/// <summary> /// 添加 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <StatusResult> AddAsync(UserRoleInputDto input) { var entity = input.Adapt <UserRole>(); entity.Id = Snowflake.GenId(); var result = await _userRoleRepository.InsertAsync(entity); return(new StatusResult(result == null, "添加失败")); }
/// <summary> /// 修改用户 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <StatusResult> UpdateAsync(UserRoleInputDto input) { var data = await _userRoleRepository.Select.Where(o => o.Id == input.Id).FirstAsync(); if (data == null) { return(new StatusResult("数据不存在!")); } data.RoleId = input.RoleId; data.UserId = input.UserId; int res = await _userRoleRepository.UpdateAsync(data); return(new StatusResult(res == 0, "修改失败")); }
/// <summary> /// 用户分配角色 /// </summary> /// <param name="dto"></param> /// <returns></returns> public async Task <OperationResponse> AllocationRoleAsync(UserRoleInputDto dto) { dto.NotNull(nameof(dto)); return(await _userRoleRepository.UnitOfWork.UseTranAsync(async() => { await _userRoleRepository.DeleteBatchAsync(x => x.UserId == dto.Id); if (dto.RoleIds?.Any() == true) { await _userRoleRepository.InsertAsync(dto.RoleIds.Select(x => new UserRoleEntity { RoleId = x, UserId = dto.Id }).ToArray()); } return new OperationResponse(ResultMessage.AllocationSucces, OperationEnumType.Success); })); }
public BaseResponse <bool> Create(UserRoleInputDto userRole) { var entity = Mapper.Map <UserRole>(userRole); if (Contains(x => x.EntityStatus == EntityStatus.Activated && x.UserId == entity.UserId && x.RoleId == entity.RoleId)) { throw new BadRequestException($"User Id {entity.UserId} already has role {entity.RoleId}"); } Create(entity, out var isSaved); if (!isSaved) { throw new InternalServerErrorException($"Could not create role for user {userRole.UserId}"); } return(new SuccessResponse <bool>(true)); }
/// <summary> /// 修改 /// </summary> /// <param name="input"></param> /// <returns></returns> [HttpPost] public async Task <StatusResult> UpdateAsync(UserRoleInputDto input) => await _iUserRoleContract.UpdateAsync(input);
public async Task <AjaxResult> AllocationUserRoleAsync([FromBody] UserRoleInputDto dto) { return((await _userRoleContract.AllocationRoleAsync(dto)).ToAjaxResult()); }
public BaseResponse <bool> Create([FromBody] UserRoleInputDto userRole) { return(_userRoleService.Create(userRole)); }