public ActionResult ChangeProfile() { /*ViewBag.favDrink = CustomProfile.GetUserProfile(User.Identity.Name).FavoriteDrink; // May want to replace this viewBag with a ViewModel that handles all of our profile features. ViewBag.favBar = CustomProfile.GetUserProfile(User.Identity.Name).FavoriteBar; ViewBag.firstName = CustomProfile.GetUserProfile(User.Identity.Name).FirstName; ViewBag.lastName = CustomProfile.GetUserProfile(User.Identity.Name).LastName; ViewBag.address = CustomProfile.GetUserProfile(User.Identity.Name).Address; ViewBag.city = CustomProfile.GetUserProfile(User.Identity.Name).City; ViewBag.state = CustomProfile.GetUserProfile(User.Identity.Name).State; ViewBag.postalCode = CustomProfile.GetUserProfile(User.Identity.Name).PostalCode; ViewBag.phone = CustomProfile.GetUserProfile(User.Identity.Name).Phone;*/ CustomProfile profile = CustomProfile.GetUserProfile(User.Identity.Name); ProfileViewModel model = new ProfileViewModel { FirstName = profile.FirstName, LastName = profile.LastName, Address = profile.Address, City = profile.City, State = profile.State, PostalCode = profile.PostalCode, Phone = profile.Phone, FavoriteDrink = profile.FavoriteDrink, FavoriteBar = profile.FavoriteBar }; return View(model); }
public ActionResult ChangeProfile(ProfileViewModel model) { if (!ModelState.IsValid) { // there were validation errors => redisplay the view return View(model); } // validation succeeded => process the results CustomProfile profile = CustomProfile.GetUserProfile(); profile.FirstName = model.FirstName; profile.LastName = model.LastName; profile.Address = model.Address; profile.City = model.City; profile.State = model.State; profile.PostalCode = model.PostalCode; profile.Phone = model.Phone; profile.FavoriteDrink = model.FavoriteDrink; profile.FavoriteBar = model.FavoriteBar; profile.Save(); return RedirectToAction("Profile"); }