public ActionResult Edit(int Id) { User users = UserRepository.GetById(Id); UserInput viewModel = new UserInput() { Username = users.Username }; return View(viewModel); }
public ActionResult Edit(UserInput input) { if (ModelState.IsValid) { UpdateUserFromInput(input); TempData["message"] = "The user was updated"; return RedirectToAction("index"); } return View(input); }
public ActionResult Edit(UserInput input) { if (ModelState.IsValid) { //do some work to update a User from the UserInput and persist the User to the database. return RedirectToAction("index"); //Successful Flow //Post Redirect Get } return new ViewResult(){ ViewData = this.ViewData, TempData = this.TempData, ViewName = ""};// Failure Flow} }
public ActionResult Edit(int Id) { User users = UserRepository.GetById(Id); var viewModel = new UserInput { Username = users.Username, FirstName = users.FirstName, LastName = users.LastName, }; return View(viewModel); }
private void UpdateUserFromInput(UserInput input) { User user = UserRepository.GetByUsername(input.Username); user.FirstName = input.FirstName; user.LastName = input.LastName; UserRepository.Save(user); }