// GET: Driver/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"); } Driver model = new Driver(); model.QuoteId = id; var drivers = db.Drivers.Where(d => d.QuoteId == id).ToList(); ViewBag.Drivers = drivers; return View(model); }
public ActionResult Create(Driver model, long id) { //TODO: Make sure cant submit to submitted quote, Validate //TODO: Make sure only CURRENT User and modify HIS OWN quote, Validate if (ModelState.IsValid) { 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.Drivers.Add(model); db.SaveChanges(); return RedirectToAction("Create", "Driver", new { id = model.QuoteId }); } return View(model); }