/***********************************************************************
* Project: baifenBinfa
* ProjectName: 百分兵法管理系统
* Web: http://chuanyin.com
* Author:
* Email:
* CreateTime: 202403/02
* Description: 暂无
***********************************************************************/
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using CoreCms.Net.Caching.Manual;
using CoreCms.Net.Configuration;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Model.ViewModels.UI;
using SqlSugar;
namespace CoreCms.Net.Repository
{
///
/// 地区表 接口实现
///
public class CoreCmsAreaRepository : BaseRepository, ICoreCmsAreaRepository
{
public CoreCmsAreaRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
#region 实现重写增删改查操作==========================================================
///
/// 重写异步插入方法
///
/// 实体数据
///
public async Task InsertAsync(CoreCmsArea entity)
{
var jm = new AdminUiCallBack();
var bl = await DbClient.Insertable(entity).ExecuteReturnIdentityAsync() > 0;
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;
return jm;
}
///
/// 重写异步更新方法
///
///
///
public async Task UpdateAsync(CoreCmsArea entity)
{
var jm = new AdminUiCallBack();
var oldModel = await DbClient.Queryable().In(entity.id).SingleAsync();
if (oldModel == null)
{
jm.msg = "不存在此信息";
return jm;
}
//事物处理过程开始
oldModel.name = entity.name;
oldModel.sort = entity.sort;
//事物处理过程结束
var bl = await DbClient.Updateable(oldModel).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
return jm;
}
///
/// 重写删除指定ID的数据
///
///
///
public async Task DeleteByIdAsync(object id)
{
var jm = new AdminUiCallBack();
var bl = await DbClient.Deleteable(id).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
return jm;
}
#endregion
#region 获取缓存的所有数据==========================================================
///
/// 获取缓存的所有数据
///
///
public async Task> GetCaChe()
{
var cache = await DbClient.Queryable().OrderBy(p => p.sort).With(SqlWith.NoLock).WithCache().ToListAsync();
return cache;
}
#endregion
}
}