public async Task <IActionResult> Edit(UserEditBindingModel model) { var user = await this.userManager.GetUserAsync(this.User); if (user == null) { return(this.NotFound()); } if (!this.ModelState.IsValid) { model.Email = user.Email; return(this.View(model)); } user.FirstName = model.FirstName; user.LastName = model.LastName; await this.userManager.UpdateAsync(user); this.Success(NotificationMessages.ProfileDetailsUpdated); return(this.LocalRedirect("/")); }
public async Task <IActionResult> SendVerificationEmail(UserEditBindingModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = await userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID {userManager.GetUserId(User)}"); } var code = await userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); var email = user.Email; await emailSender.SendEmailAsync(model.Email, "Please verify your email", $"Please confirm your new email by clicking this link: <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>link</a>"); this.Success(NotificationMessages.VerificationEmailSent); return(RedirectToAction(nameof(EditProfile))); }
public async Task <IActionResult> EditProfile(UserEditBindingModel model) { var user = await this.userManager.GetUserAsync(this.User); if (!ModelState.IsValid) { return(View(model)); } if (user == null) { return(this.NotFound()); } var email = user.Email; if (model.Email != email) { var setEmailResult = await userManager.SetEmailAsync(user, model.Email); if (!setEmailResult.Succeeded) { return(NotFound()); } } var phoneNumber = user.PhoneNumber; if (model.PhoneNumber != phoneNumber) { var setPhoneResult = await userManager.SetPhoneNumberAsync(user, model.PhoneNumber); if (!setPhoneResult.Succeeded) { return(NotFound()); } } if (model.NewPicture != null) { try { await photoService.AddPhotoToUser(model.NewPicture, user.UserName); } catch { this.Error(NotificationMessages.ImageUploadError); return(View(model)); } } user.AboutMe = model.AboutMe; user.Address = model.Address; await this.userManager.UpdateAsync(user); this.Success(NotificationMessages.AccountUpdated); return(RedirectToAction(nameof(EditProfile))); }
public void EditUser(UserEditBindingModel bind, string userName) { ApplicationUser user = this.Context.Users.FirstOrDefault(u => u.Name == userName); user.Name = bind.Name; user.Email = bind.Email; this.Context.SaveChanges(); }
public ActionResult Edit(UserEditBindingModel bind) { string userName = this.User.Identity.Name; if (ModelState.IsValid) { this.usersService.EditUser(bind, userName); this.RedirectToAction("Profile"); } UserEditViewModel uevm = this.usersService.GetEditUser(userName); return(this.View(uevm)); }
public async Task <IActionResult> Edit() { var user = await this.userManager.GetUserAsync(this.User); if (user == null) { return(this.NotFound()); } var model = new UserEditBindingModel { Email = user.Email, FirstName = user.FirstName, LastName = user.LastName }; return(this.View(model)); }
public async Task <IActionResult> EditProfile() { var user = await userManager.GetUserAsync(User); if (user == null) { throw new ArgumentException(); } var model = new UserEditBindingModel { UserPhotoUrl = user.PictureUrl, Username = user.UserName, Email = user.Email, IsEmailConfirmed = user.EmailConfirmed, PhoneNumber = user.PhoneNumber, Address = user.Address, AboutMe = user.AboutMe }; return(View(model)); }
public ActionResult EditDetails(string id, UserEditBindingModel model) { if (this.ModelState.IsValid) { var user = this.UserManager.FindById(id); if (user == null) { this.AddToastMessage("Error", "Non-existing user.", ToastType.Error); return this.RedirectToAction("Index"); } user.FullName = model.FullName; user.Email = model.Email; user.PhoneNumber = model.PhoneNumber; var result = this.UserManager.Update(user); if (result.Succeeded) { this.AddToastMessage("Success", "User edited.", ToastType.Success); return this.RedirectToAction("Index"); } this.AddErrors(result); } return View(model); }
public async Task<ActionResult> Edit(string id, UserEditBindingModel model) { if (this.ModelState.IsValid) { //var user = this.UserProfile; var currentUserId = this.User.Identity.GetUserId(); var userToEdit = this.UserManager.FindById(currentUserId); //var userToEdit = this.ContestsData.Users.Find(currentUserId); userToEdit.FullName = model.FullName; userToEdit.Email = model.Email; userToEdit.PhoneNumber = model.PhoneNumber; var oldProfilePhotoPath = userToEdit.ProfilePhotoPath; var oldProfilePhotoThumbPath = userToEdit.ThumbnailPath; if (model.Upload != null && model.Upload.ContentLength > 0) { var photoPaths = Helpers.UploadImages.UploadImage(model.Upload, true); var profilePhotoUrl = Dropbox.Download(photoPaths[0]); var profileThumbnailUrl = Dropbox.Download(photoPaths[1], "Thumbnails"); userToEdit.ProfilePhotoPath = photoPaths[0]; userToEdit.ThumbnailPath = photoPaths[1]; userToEdit.ProfilePhotoUrl = profilePhotoUrl; userToEdit.ThumbnailUrl = profileThumbnailUrl; } var result = this.UserManager.Update(userToEdit); //this.ContestsData.SaveChanges(); if (result.Succeeded) { Dropbox.DeleteImages(oldProfilePhotoPath, oldProfilePhotoThumbPath); this.AddToastMessage("Success", "Profile edited.", ToastType.Success); return this.RedirectToAction("Index", "Home", new {area = ""}); } this.AddErrors(result); } return View(model); }