我们提供安全,免费的手游软件下载!
上一章节我们已经使用BootstrapBlazor UI组件完成了EasySQLite后台界面的基本搭建。本章节将重点介绍Blazor班级管理页面的编写和接口对接。
七天.NET 8 操作 SQLite 入门到实战详细教程:
不熟悉Blazor的同学可以先看这篇文章大概了解一下。
全面的ASP.NET Core Blazor简介和快速入门
主要是常见Table的数据展示、数据添加、数据删除、数据修改等操作。
@page "/SchoolClass"
@using Entity
@using WebUI.Common
@inject HttpClient _httpClient;
AutoGenerateColumns="true"
ShowToolbar="true"
IsMultipleSelect="true"
OnSaveAsync="@OnSaveAsync"
OnQueryAsync="@OnQueryAsync"
OnDeleteAsync="@OnDeleteAsync"
IsStriped="true"
IsBordered="true"
ShowSearch="true"
IsPagination="true"
ShowSearchText="true">
@code {
///
/// 数据查询
///
/// options
///
private async Task> OnQueryAsync(QueryPageOptions options)
{
var getClass = new List();
var getResults = await _httpClient.GetFromJsonAsync>>("api/SchoolClass/GetClass").ConfigureAwait(false);
if (getResults.Success)
{
// 数据模糊过滤筛选
if (!string.IsNullOrWhiteSpace(options.SearchText))
{
getClass = getResults.Data.Where(x => x.ClassName.Contains(options.SearchText)).ToList();
}
else
{
getClass = getResults.Data.ToList();
}
}
//假分页
return await Task.FromResult(new QueryData()
{
Items = getClass.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList(),
TotalCount = getClass.Count()
});
}
///
/// 模拟数据增加和修改操作
///
/// studentInfo
/// changedType
///
public async Task OnSaveAsync(SchoolClass studentInfo, ItemChangedType changedType)
{
if (changedType.ToString() == "Update")
{
var addResult = await _httpClient.PutAsJsonAsync($"api/SchoolClass/UpdateClass/{studentInfo.ClassID}", studentInfo).ConfigureAwait(false);
if (UtilityBusiness.CheckResponse(addResult))
{
return await Task.FromResult(true);
}
else
{
return await Task.FromResult(false);
}
}
else if (changedType.ToString() == "Add")
{
var addResult = await _httpClient.PostAsJsonAsync("api/SchoolClass/CreateClass", studentInfo).ConfigureAwait(false);
if (UtilityBusiness.CheckResponse(addResult))
{
return await Task.FromResult(true);
}
else
{
return await Task.FromResult(false);
}
}
return await Task.FromResult(true);
}
///
/// 数据删除
///
/// items
///
private async Task OnDeleteAsync(IEnumerable items)
{
var deleteSuccessNum = 0;
var schoolClassList = items.ToList();
foreach (var item in schoolClassList)
{
var delResult = await _httpClient.DeleteAsync($"api/SchoolClass/DeleteClass/{item.ClassID}").ConfigureAwait(false);
if (UtilityBusiness.CheckResponse(delResult))
{
deleteSuccessNum++;
}
}
if (deleteSuccessNum > 0)
{
return await Task.FromResult(true);
}
else
{
return await Task.FromResult(false);
}
}
}
热门资讯