public ActionResult Edit(Car car) { if (ModelState.IsValid) { db.Entry(car).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.CarTypeId = new SelectList(db.CarType, "CarTypeId", "description", car.CarTypeId); return View(car); }
public ActionResult Create(Car car) { if (ModelState.IsValid) { var caridentico = db.Car.FirstOrDefault(c => c.Patente == car.Patente); if (caridentico == null) { db.Car.Add(car); db.SaveChanges(); return RedirectToAction("TicketEntrada", "Tickets", new { carId = car.CarId }); } else { ModelState.AddModelError("", String.Concat("Ya hay un auto con la patente: ", caridentico.Patente)); } } ViewBag.CarTypeId = new SelectList(db.CarType, "CarTypeId", "description", car.CarTypeId); return View(car); }