public async Task <ActionResult> UserProfile(ApplicationUser applicationUser, HttpPostedFileBase file) { var message = ManageMessageId.Error; var userprofile = await UserManager.FindByIdAsync(applicationUser.Id); userprofile.Name = applicationUser.Name; userprofile.Gender = applicationUser.Gender; userprofile.DatOfBirth = applicationUser.DatOfBirth; userprofile.Address = applicationUser.Address; if (string.IsNullOrEmpty(userprofile.Email)) { userprofile.Email = userprofile.UserName; } if (file != null && file.ContentLength > 0) { //delete existing one if (!string.IsNullOrEmpty(userprofile.ProfilePicture)) { var filePath = Server.MapPath(userprofile.ProfilePicture); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); userprofile.ProfilePicture = ""; } } // code for saving the image file to a physical location. var fileName = Path.GetFileName(file.FileName); if (fileName != null) { var path = Path.Combine(Server.MapPath("~/Uploads/ProfileImages"), fileName); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } file.SaveAs(path); // prepare a relative path to be stored in the database and used to display later on. userprofile.ProfilePicture = Url.Content(Path.Combine("~/Uploads/ProfileImages", fileName)); } } var result = await UserManager.UpdateAsync(userprofile); if (result.Succeeded) { // create a new identity var identity = new ClaimsIdentity(User.Identity); await ClaimManagement.ManageClaimsAfterDbUpdate(userprofile, identity, UserManager); // the claim has been updates, We need to change the cookie value for getting the updated claim AuthenticationManager.SignOut(identity.AuthenticationType); await SignInManager.SignInAsync(userprofile, isPersistent : false, rememberBrowser : false); return(RedirectToAction("Index", new { Message = ManageMessageId.ProfileUpdated })); } return(RedirectToAction("Index", new { Message = message })); }
public async Task <ActionResult> Confirm(int packageId) { var package = _packageService.GetById(packageId); if (package != null) { var userId = User.Identity.GetUserId(); var userprofile = await UserManager.FindByIdAsync(userId); userprofile.PackageId = package.Id; userprofile.StartDate = DateTime.Now; var result = await UserManager.UpdateAsync(userprofile); if (result.Succeeded) { // create a new identity var identity = new ClaimsIdentity(User.Identity); await ClaimManagement.ManageClaimsAfterDbUpdate(userprofile, identity, UserManager); // the claim has been updated, We need to change the cookie value for getting the updated claim AuthenticationManager.SignOut(identity.AuthenticationType); await SignInManager.SignInAsync(userprofile, isPersistent : false, rememberBrowser : false); return(RedirectToAction("Index")); } } return(RedirectToAction("Upgrade", new { id = packageId })); }