public ActionResult Makes() { var model = new AddMakeViewModel(); model.MakeList = _carDealer.GetAllCarMakes(); return(View(model)); }
public ActionResult Makes() { AddMakeViewModel model = new AddMakeViewModel(); model.Makes = _makeRepo.GetAll(); return(View(model)); }
public ActionResult Makes(AddMakeViewModel model) { if (ModelState.IsValid) { // attempt to add new make bool success = DataManager.Instance.AddMake(model.Make); if (success) { return(RedirectToAction("Vehicles", new { Message = $"Successfully created the new make: '{model.Make}'" })); } // if we got here then the make already exists! ModelState.AddModelError("Make", $"The make '{model.Make}' already exists."); } // if we got there then the submission was invalid return(View(model)); }
public ActionResult Makes() { if (Request.IsAuthenticated) { var userMgr = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); var user = userMgr.FindByName(User.Identity.Name); ViewBag.UserName = user.UserName; } AddMakeViewModel model = new AddMakeViewModel(); var repo = MakeModelRepositoryFactory.GetRepository(); model.Makes = repo.GetMakes(); return(View(model)); }
public ActionResult Makes(AddMakeViewModel model) { var repo = MakeModelRepositoryFactory.GetRepository(); if (string.IsNullOrEmpty(model.CarMakeName)) { ModelState.AddModelError("CarMakeName", "Please enter a car make name"); } if (ModelState.IsValid) { try { model.NewMake = new CarMake(); model.NewMake.CarMakeId = model.CarMakeId; model.NewMake.CarMakeName = model.CarMakeName; model.NewMake.DateCreated = model.DateCreated; var userMgr = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); var user = userMgr.FindByName(User.Identity.Name); ViewBag.UserName = user.UserName; repo.AddMake(model.NewMake); return(RedirectToAction("Makes", "Admin")); } catch (Exception ex) { throw ex; } } else { model.Makes = repo.GetMakes(); return(View(model)); } }
public ActionResult Makes(AddMakeViewModel model) { if (ModelState.IsValid) { Make newMake = new Make() { AddedBy = User.Identity.Name, DateAdded = DateTime.Today, MakeName = model.Make }; _makeRepo.Insert(newMake); model.Makes = _makeRepo.GetAll(); TempData["Success"] = "Make Successfully Added!"; return(View(model)); } model.Makes = _makeRepo.GetAll(); return(View(model)); }