public async Task <UserDto> PromoteManagerAsync(PromoteUserDto dto) { var entity = await Repository.SingleAsync(s => s.UserName == dto.UserName); if (entity == null) { throw new BadRequestException("User is not existed."); } var roles = entity.Roles?.ToList() ?? new List <string>(); if (roles.Contains(RoleSetting.ROLE_MANAGER)) { throw new BadRequestException(string.Format("User is ready {0}.", RoleSetting.ROLE_MANAGER)); } await _proxyService.AddAccountToRoletAsync(dto.UserName, RoleSetting.ROLE_MANAGER); roles.Add(RoleSetting.ROLE_MANAGER); entity.Roles = roles; await UpdateAsync(entity); return(entity.ToDto()); }
public async Task <IActionResult> PromoteAsycn([FromBody] PromoteUserDto dto) { var validation = CheckValidation(dto); if (!validation.IsValid) { throw new BadRequestException(validation.Errors); } var result = await _userService.PromoteManagerAsync(dto); return(ResultOk(result)); }