public ActionResult UserProfile(UserProfileModel model) { User authentacatedUser = _userRepository.GetUserByPhone(User.Identity.Name); if (authentacatedUser != null) { string error; if (model.IsValid(out error)) { authentacatedUser.EmailAddress = model.Email; authentacatedUser.Username = model.UserName; authentacatedUser.ReceiveNewAnnouncements = model.CanReceiveEmail; _userRepository.SaveChanges(); TempData["message"] = Translation.Translation.UserDataSavedMessage; } else { ModelState.AddModelError("", error); } return(View(model)); } else { throw new Exception(Translation.Translation.AccessIsDeniedMessage); } }
public async Task <IActionResult> UpsertUserProfile([Required] UserProfileModel userProfile) { var(isValid, reason) = userProfile.IsValid(); if (!isValid) { return(BadRequest(reason)); } var userId = httpContextAccessor.GetUserId(); var entity = new UserProfile { BirthDate = userProfile.BirthDate, Height = userProfile.Height, ID = userId }; await userProfileRepository.UpsertUserProfile(entity); return(NoContent()); }