public ActionResult Delete(int ID) { SubDbContext context = new SubDbContext(); User user = context.Users.Find(ID); if (null != user) { context.Users.Remove(user); context.SaveChanges(); } return(RedirectToAction("ShowUsersList")); }
public ActionResult Create(CarViewModel newCar) { if (!ModelState.IsValid) { return(View()); } Car car = MapToCar(newCar); SubDbContext context = new SubDbContext(); context.Cars.Add(car); context.SaveChanges(); return(RedirectToAction("ShowCarsList", new { userID = newCar.UserID })); }
public ActionResult Create(UserViewModel newUser) { if (!ModelState.IsValid) { return(View()); } User user = MapToUser(newUser); SubDbContext context = new SubDbContext(); context.Users.Add(user); context.SaveChanges(); return(RedirectToAction("ShowUsersList")); }
public ActionResult Edit(UserViewModel userModel) { if (!ModelState.IsValid) { return(View()); } SubDbContext context = new SubDbContext(); User user = context.Users.Find(userModel.ID); if (null != user) { user.FirstName = userModel.FirstName; user.MiddleName = userModel.MiddleName; user.LastName = userModel.LastName; user.GPA = userModel.GPA; user.YearsInSchool = userModel.YearsInSchool; user.EmailAddress = userModel.EmailAddress; context.SaveChanges(); } return(RedirectToAction("ShowUsersList")); }