public async Task <IActionResult> UpdateUserProfile(PutUserDTO user) { ServiceResponse <GetUserDTO> response = await _userService.UpdateUserProfile( this.User.FindFirst(ClaimTypes.NameIdentifier).Value, user); return(response.ReturnResult()); }
public async Task UpdateAsync(string userId, PutUserDTO arg) { try { var user = await userManager.FindByIdAsync(userId); if (user == null) { throw new EntityNotFoundException(); } var IsEnteredDataAvailable = true; if (arg.Username != null) { IsEnteredDataAvailable = !(await db.Users.AnyAsync(a => a.NormalizedUserName == arg.Username.ToUpper() && a.Id != userId)); } if (arg.Email != null && IsEnteredDataAvailable) { IsEnteredDataAvailable = !(await db.Users.AnyAsync(a => a.NormalizedEmail == arg.Email.ToUpper() && a.Id != userId)); } if (IsEnteredDataAvailable) { if (arg.Username != null) { await userManager.SetUserNameAsync(user, arg.Username); } if (arg.Email != null) { await userManager.SetEmailAsync(user, arg.Email); } } else { throw new UserNameOrEmailIsNotAvailableException(); } mapper.Map(arg, user); db.Update(user); await db.SaveChangesAsync(); } catch (Exception ex) { throw; } }
public async Task <ActionResult <PutUserDTO> > PutUser(string email, PutUser putUser) { var userToPut = await _context.Users.Where(user => user.Email == email).FirstAsync(); PutUser putUserModel = putUser; if (userToPut == null) { return(BadRequest(this.GetError(Error.INVALID_TOKEN))); } if (putUser.AccessToken == null || !putUserModel.AccessToken.Equals(userToPut.AccessToken)) { return(BadRequest(this.GetError(Error.INVALID_TOKEN))); } if (userToPut.tokenExpired()) { return(BadRequest(this.GetError(Error.EXPIRED_TOKEN))); } if (putUserModel.Name != null && putUserModel.Name.Length > 0) { userToPut.Name = putUser.Name; } if (putUserModel.Email != null && putUserModel.Email.Length > 0) { var emailExistUser = await _context.Users.Where(user => user.Email == putUserModel.Email).FirstAsync(); if (emailExistUser != null) { return(BadRequest(this.GetError(Error.DUPLICATED_EMAIL))); } userToPut.Email = putUser.Email; } if (putUserModel.Password != null && putUserModel.Password.Length > 0) { userToPut.Password = new AES().EncryptToBase64String(putUser.Password); } _context.Entry(userToPut).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } PutUserDTO putUserDTO = new PutUserDTO(userToPut); return(putUserDTO); }
public async Task <ApiResponse> Put(string id, [FromBody] PutUserDTO arg) { try { await userService.UpdateAsync(id, arg); return(new ApiResponse(InfoMessages.UserUpdated, null, HttpStatusCode.OK.ToInt())); } catch (ValidationException ex) { throw new ApiException(ex.Errors, ex.StatusCode); } catch (CustomException ex) { throw new ApiException(ex, ex.StatusCode); } catch (Exception ex) { throw new ApiException(ex); } }
public Task UpdateAsync(PutUserDTO user) { return(_repository.UpdateAsync(user.AsEntity())); }
public async Task <IActionResult> Update(PutUserDTO user) { await _userService.UpdateAsync(user); return(Ok()); }
public async Task <ServiceResponse <GetUserDTO> > UpdateUserProfile(string identifier, PutUserDTO user) { ServiceResponse <GetUserDTO> resposne = new ServiceResponse <GetUserDTO>(); try{ User userInfo = await _context.Users.FirstOrDefaultAsync(u => u.Auth == identifier); _mapper.Map(user, userInfo); await _context.SaveChangesAsync(); } catch (Exception ex) { resposne.Message = ex.Message; resposne.Success = false; } return(resposne); }