public ActionResult Edit(int ID) { SubDbContext context = new SubDbContext(); User user = context.Users.Find(ID); if (null == user) { return(RedirectToAction("ShowUsersList")); } return(View(MapToUserViewModel(user))); }
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 ShowUsersList() { SubDbContext db = new SubDbContext(); List <UserViewModel> models = new List <UserViewModel>(); foreach (User user in db.Users) { UserViewModel model = MapToUserViewModel(user); models.Add(model); } return(View(models)); }
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 ShowCarsList(int userID) { SubDbContext db = new SubDbContext(); List <CarViewModel> models = new List <CarViewModel>(); ViewBag.userID = userID; foreach (Car car in db.Cars) { if (car.UserID == userID) { CarViewModel model = MapToCarViewModel(car); models.Add(model); } } return(View(models)); }
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")); }
public UserRepository(SubDbContext context) { this.context = context; }