1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using QM.AuthServer.Models.Roles;
- using QM.AuthServer.IRepository;
- using QM.OrmSqlSugar;
- using System;
- using System.Linq;
- using System.Threading.Tasks;
- using WS;
- using WS.AutoMapper;
- namespace QM.AuthServer.Repository
- {
- public class SysDepartmentRepository : SqlSugarRepository<SysDepartment>, ISysDepartmentRepository
- {
- /// <summary>
- /// 检查
- /// </summary>
- /// <param name="bid"></param>
- /// <returns></returns>
- public SysDepartment CheckId(string bid)
- {
- var model = Get(t => t.bid == bid);
- if (model == null)
- throw new UseArgumentException("部门不存在,请检查数据是否正确");
- return model;
- }
- /// <summary>
- /// 创建
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public async Task<bool> Create(DepartmentInputDto input, string user)
- {
- var model = Get(t => t.name == input.name);
- if (model != null)
- throw new UseArgumentException("部门已存在,请重新输入");
- SysDepartment role = input.MapTo<SysDepartment>();
- role.bid = Guid.NewGuid().ToStringN();
- role.cuser = user;
- await InsertAsync(role);
- return true;
- }
- /// <summary>
- /// 修改
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public async Task<bool> Update(DepartmentUpdateDto input, string user)
- {
- var person = CheckId(input.bid);
- var model = input.Map(person);
- await UpdateAsync(model);
- return true;
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="bid"></param>
- /// <returns></returns>
- public async Task<bool> Delete(string bid)
- {
- var person = CheckId(bid);
- try
- {
- BeginTran();
- var gids = Db.Queryable<SysPost>().Where(t => t.bid == bid).Select(t => t.gid).ToList();
- await Db.Deleteable<SysPostMenu>(t => gids.Contains(t.gid)).ExecuteCommandAsync();
- await Db.Deleteable<SysPost>(t => t.bid == bid).ExecuteCommandAsync();
- await Db.Deleteable<SysDepartment>(t => t.bid == bid).ExecuteCommandAsync();
- CommitTran();
- return true;
- }
- catch (Exception ex)
- {
- RollbackTran();
- }
- return false;
- }
- }
- }
|