public ActionResult Models(MakeModelVM vm) { var manager = ManagerFactory.Create(); var userManager = HttpContext.GetOwinContext().GetUserManager <UserManager <AppUser> >(); vm.SetMakesAndModels(manager); if (vm.AllModels.Any(m => m.Name == vm.SubmittedModel)) { ModelState.AddModelError("", "Error: This model already exists for the given make."); } if (vm.SubmittedModel == null) { ModelState.AddModelError("", "Error: the model field may not be blank."); } if (!ModelState.IsValid) { return(View(vm)); } else { manager.AddModel(new Model { Name = vm.SubmittedModel, Maker = manager.GetMake(vm.SubmittedMakeId) }, vm.UserId); return(RedirectToAction("Models")); } }
public ActionResult Makes(MakeModelVM vm) { var manager = ManagerFactory.Create(); var userManager = HttpContext.GetOwinContext().GetUserManager <UserManager <AppUser> >(); vm.SetMakesAndModels(manager); if (vm.AllMakes.Any(m => m.Name == vm.SubmittedMake)) { ModelState.AddModelError("", "Error: That make is already in the database."); } if (vm.SubmittedMake == null) { ModelState.AddModelError("", "Error: the Make field is required."); } if (!ModelState.IsValid) { return(View(vm)); } else { manager.AddMake(new Make { Name = vm.SubmittedMake, DateAdded = DateTime.Now, UserAddedBy = userManager.FindById(vm.UserId) }, vm.UserId); return(RedirectToAction("Makes")); } }
public ActionResult Models() { var vm = new MakeModelVM(); var manager = ManagerFactory.Create(); var userManager = HttpContext.GetOwinContext().GetUserManager <UserManager <AppUser> >(); vm.UserId = userManager.FindByName(User.Identity.Name).Id; vm.SetMakesAndModels(manager); return(View(vm)); }