public ActionResult Save(Cars car) { if (!ModelState.IsValid) { return(View("CarsForm", car)); } if (car == null) { return(HttpNotFound()); } Cars carInDB = _context.Cars.Where(x => x.Id == car.Id).SingleOrDefault(); if (carInDB != null) { carInDB.CarBrand = car.CarBrand; carInDB.CarType = car.CarType; carInDB.LicensePlateNumber = car.LicensePlateNumber; carInDB.DateOfProduction = car.DateOfProduction; } else { _context.Cars.Add(car); } _context.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Save(Owners owner) { if (!ModelState.IsValid) { return(View("OwnersForm", owner)); } if (owner == null) { return(HttpNotFound()); } Owners ownerInDB = _context.Owners.Where(x => x.Id == owner.Id).SingleOrDefault(); if (ownerInDB != null) { ownerInDB.FirstName = owner.FirstName; ownerInDB.LastName = owner.LastName; ownerInDB.DateOfBirth = owner.DateOfBirth; } else { _context.Owners.Add(owner); } _context.SaveChanges(); return(RedirectToAction("Index")); }