refactor: 代码重构

This commit is contained in:
Argo-Tianyi 2021-12-11 14:27:47 +08:00
parent 27e25c9907
commit 8ed5a6981f
3 changed files with 10 additions and 10 deletions

View File

@ -8,11 +8,11 @@ using Microsoft.EntityFrameworkCore;
namespace BootstrapAdmin.DataAccess.EFCore.Services
{
/// <summary>
/// PetaPoco ORM 的 IDataService 接口实现
/// EFCore ORM 的 IDataService 接口实现
/// </summary>
class DefaultDataService<TModel> : DataServiceBase<TModel> where TModel : class, new()
{
private IDbContextFactory<BootstrapAdminContext> DbFactory { get; set; }
private IDbContextFactory<BootstrapAdminContext> DbFactory { get; }
/// <summary>
/// 构造函数

View File

@ -14,12 +14,12 @@ namespace BootstrapBlazor.DataAcces.PetaPoco.Services
/// </summary>
class DefaultDataService<TModel> : DataServiceBase<TModel> where TModel : class, new()
{
private readonly IDatabase _db;
private IDatabase Database { get; }
/// <summary>
/// 构造函数
/// </summary>
public DefaultDataService(IDatabase db) => _db = db;
public DefaultDataService(IDatabase db) => Database = db;
/// <summary>
/// 删除方法
@ -30,7 +30,7 @@ namespace BootstrapBlazor.DataAcces.PetaPoco.Services
{
// 通过模型获取主键列数据
// 支持批量删除
_db.DeleteBatch(models);
Database.DeleteBatch(models);
return Task.FromResult(true);
}
@ -44,11 +44,11 @@ namespace BootstrapBlazor.DataAcces.PetaPoco.Services
{
if (changedType == ItemChangedType.Add)
{
await _db.InsertAsync(model);
await Database.InsertAsync(model);
}
else
{
await _db.UpdateAsync(model);
await Database.UpdateAsync(model);
}
return true;
}
@ -70,14 +70,14 @@ namespace BootstrapBlazor.DataAcces.PetaPoco.Services
var filters = option.Filters.Concat(option.Searchs).Concat(option.CustomerSearchs);
if (option.IsPage)
{
var items = await _db.PageAsync<TModel>(option.PageIndex, option.PageItems, filters, option.SortName, option.SortOrder);
var items = await Database.PageAsync<TModel>(option.PageIndex, option.PageItems, filters, option.SortName, option.SortOrder);
ret.TotalCount = Convert.ToInt32(items.TotalItems);
ret.Items = items.Items;
}
else
{
var items = await _db.FetchAsync<TModel>(filters, option.SortName, option.SortOrder);
var items = await Database.FetchAsync<TModel>(filters, option.SortName, option.SortOrder);
ret.TotalCount = items.Count;
ret.Items = items;
}

View File

@ -9,7 +9,7 @@ namespace BootstrapAdmin.DataAccess.PetaPoco.Services
/// </summary>
class NavigationsService : INavigations
{
private IDatabase Database { get; set; }
private IDatabase Database { get; }
/// <summary>
///