public ActionResult SaveEditingUserProfile(EditUserProfileBindingModel userProfile, string id) { var loginUserId = User.Identity.GetUserId(); if (!(loginUserId == id || User.IsInRole("Admin"))) { return RedirectToAction("Index", "Contest"); } if (!ModelState.IsValid) { return this.RedirectToAction("Profile", new { id = id }); } var currentUser = this.Data.Users.GetById(id); if (userProfile.FirstName != null) { currentUser.FirstName = userProfile.FirstName; } if (userProfile.LastName != null) { currentUser.LastName = userProfile.LastName; } if (userProfile.AvatarPath != null) { currentUser.AboutMe = userProfile.AboutMe; } if (userProfile.PhoneNumber != null) { currentUser.PhoneNumber = userProfile.PhoneNumber; } if (userProfile.AvatarPath != null) { currentUser.ProfilePic = userProfile.AvatarPath; } this.Data.SaveChanges(); return this.RedirectToAction("Profile", new { id = id }); }
public PartialViewResult EditProfile(string id) { var userId = User.Identity.GetUserId(); if (!(userId == id || User.IsInRole("Admin"))) { return PartialView("_EditProfile", new EditUserProfileBindingModel()); } var user = this.Data.Users.GetById(id); var userBinding = new EditUserProfileBindingModel() { Id = user.Id, FirstName = user.FirstName, LastName = user.LastName, AboutMe = user.AboutMe, PhoneNumber = user.PhoneNumber, AvatarPath = user.ProfilePic }; return PartialView("_EditProfile", userBinding); }