// GET: Vehicle/Create public ActionResult Create(long id) { var userId = User.Identity.GetUserId(); var aiaUserId = db.AIAUsers.Where(u => u.ApplicationUserId == userId).First().Id; var check = db.Quotes.Where(q => q.AIAUserId == aiaUserId && q.Id == id && !q.Submitted).SingleOrDefault(); if (check == null) { return View("Error"); } var vehicles = db.Vehicles.Where(v => v.QuoteId == id).ToList(); ViewBag.Vehicles = vehicles; var drivers = db.Drivers.Where(d => d.QuoteId == id).ToList(); ViewBag.Drivers = new SelectList(drivers, "Id", "FirstName"); ViewBag.DriversToTable = drivers; Vehicle vehicle = new Vehicle(); vehicle.QuoteId = id; return View(vehicle); }
public ActionResult Create(Vehicle model, long id) { if (ModelState.IsValid) { //TODO: Make sure cant submit to submitted quote, Validate now //TODO: Make sure only CURRENT User and modify HIS OWN quote, Validate now var userId = User.Identity.GetUserId(); var aiaUserId = db.AIAUsers.Where(u => u.ApplicationUserId == userId).First().Id; Quote check = db.Quotes.Where(d => d.Id == id && d.AIAUserId == aiaUserId && !d.Submitted).SingleOrDefault(); if (check == null) { return View("Error"); } if (check.Submitted) { return View("Error"); } model.QuoteId = id; db.Vehicles.Add(model); db.SaveChanges(); return RedirectToAction("Create", "Vehicle", new { id = id }); } return View(model); }