public UpdateDisplayNameViewModel GetCurrentUserById(string id) { var currentUser = UserManager.FindById(id); if (currentUser == null) { throw new UserNotFoundException(); } var viewModel = new UpdateDisplayNameViewModel { DisplayName = currentUser.DisplayName.Trim() }; return(viewModel); }
public ActionResult EditDisplayName() { try { var model = new UpdateDisplayNameViewModel(); model = UserPresenter.GetCurrentUserById(User.Identity.GetUserId()); return(View(model)); } catch (UserNotFoundException e) { return(View("UserNotFoundError")); } catch (Exception e) { throw e; } }
public async Task <JsonResult> UpdateDisplayName([FromBody] UpdateDisplayNameViewModel displayNameVM) { if (displayNameVM.DisplayName.Length > 30) { return(Json(new { Error = "The max-length allowed for display names is 30 characters." })); } var user = await _userManager.GetUserAsync(User); user.DisplayName = displayNameVM.DisplayName; var updateResult = await _userManager.UpdateAsync(user); if (updateResult.Succeeded) { return(Json(new { Error = "" })); } else { return(Json(new { Error = updateResult.Errors })); } }
public ActionResult EditDisplayName(UpdateDisplayNameViewModel model) { if (ModelState.IsValid) { try { UserPresenter.UpdateDisplayNameInDB(User.Identity.GetUserId(), model.DisplayName); } catch (UserNotFoundException e) { return(View("UserNotFoundError")); } catch (Exception ex) { throw ex; } return(RedirectToAction("Index")); } return(View()); }