public async Task <IActionResult> Post(UpdateRolePermissionModel model) { var per = await PerSvc.GetByNameAsync(model.Name); if (per != null) { if (per.Id != model.Id) { return(new JsonResult(new APIResult <int> { ErrorMsg = "该权限已存在" }) { StatusCode = 400 }); } } UpdateRolePermissionDTO dto = new UpdateRolePermissionDTO(); dto.Description = model.Description; dto.Id = model.Id; dto.Name = model.Name; await PerSvc.UpdateAsync(dto); return(Ok()); }
public async Task UpdateAsync(UpdateRolePermissionDTO dto) { using (AdminUserContext ctx = new AdminUserContext()) { BaseService <RoleEntity> roleBs = new BaseService <RoleEntity>(ctx); var namePer = await roleBs.GetAll().SingleOrDefaultAsync(e => e.Name == dto.Name); if (namePer != null) { if (dto.Id != namePer.Id) { throw new Exception("权限名已存在"); } } var entity = await roleBs.GetAll().SingleAsync(e => e.Id == dto.Id); entity.Description = dto.Description; entity.Name = dto.Name; await ctx.SaveChangesAsync(); } }