public async Task UpdateProfileEmail(string id, UpdateProfileEmailDTO emailDto) { if (!Regex.Match(emailDto.Email, "^\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$").Success) { throw new ArgumentException("Email is invalid!"); } var dbUser = this._userRepository .All() .Single(x => x.Id == id); dbUser.Email = emailDto.Email; var activity = new UserActivity { Action = $"Update profile email", RegisteredOn = DateTime.Now, UserId = id, }; await this._userActivityRepository.AddAsync(activity); dbUser.Activity.Add(activity); await this._userRepository.SaveChangesAsync(); }
public async Task <IActionResult> UpdateEmail(string id, UpdateProfileEmailDTO emailDto) { _logger.LogInfo($"Updating profile with username {id}..."); if (emailDto.Email == "") { return(BadRequest()); } await this._profileService.UpdateProfileEmail(id, emailDto); _logger.LogInfo($"Profile with id: {id} successfully updated."); return(NoContent()); }