public ActionResult CreateModel(Car model) { if (ModelState.IsValid) { using (ApplicationDbContext db = new ApplicationDbContext()) { model.DateCreated = DateTime.Now; model.DateDeleted = null; db.Cars.Add(model); db.SaveChanges(); } return RedirectToAction("Index"); } return View(model); }
public ActionResult EditModel(Car model) { if (ModelState.IsValid) { using (ApplicationDbContext db = new ApplicationDbContext()) { Car tempModel = db.Cars.FirstOrDefault(x => x.ModelId == model.ModelId); tempModel.ModelName = model.ModelName; tempModel.FirstYear = model.FirstYear; tempModel.LastYear = model.LastYear; tempModel.UnitsProduced = model.UnitsProduced; tempModel.Description = model.Description; tempModel.Synopsis = model.Synopsis; tempModel.ImgUrl = model.ImgUrl; db.SaveChanges(); } return RedirectToAction("CarDetails", new { id = model.ModelId }); } return View("EditModel", model); }