public async Task <RoleProfile> AddAsync([Required] EditRoleInput input) { // 判断角色是否存在 var isExist = await _roleRepository.AnyAsync(u => u.Name.Trim().Equals(input.Name.Trim())); if (isExist) { throw Oops.Oh(SystemErrorCodes.u1006); } var addRole = input.Adapt <Role>(); var entryEntity = await _roleRepository.InsertNowAsync(addRole); return(entryEntity.Entity.Adapt <RoleProfile>()); }
public async Task ModifyAsync([Required, Range(1, int.MaxValue, ErrorMessage = "请输入有效的角色 Id"), ApiSeat(ApiSeats.ActionStart)] int roleId, [Required] EditRoleInput input) { // 查询角色是否存在 var role = await _roleRepository.FirstOrDefaultAsync(u => u.Id == roleId, false); _ = role ?? throw Oops.Oh(SystemErrorCodes.u1002); var modifyRole = input.Adapt <Role>(); // 配置主键和更新时间 modifyRole.Id = roleId; modifyRole.UpdatedTime = DateTimeOffset.Now; await _roleRepository.UpdateExcludeAsync(modifyRole, new[] { nameof(Role.IsDeleted), nameof(Role.CreatedTime) }, ignoreNullValues : true); }