public ActionResult Add(EditableCar modelCar) { if (ModelState.IsValid) { if (modelCar != null) { Car car = new Car(); car.Mark = modelCar.Mark; car.Model = modelCar.Model; car.Color = modelCar.Color; car.NrOfSeats = modelCar.NrOfSeats; car.CarNumber = modelCar.CarNumber; car.DriverName = modelCar.DriverName; car.CompanyId = modelCar.CompanyId; Manager.Add(car); return RedirectToAction("Index"); } } var company = Manager.RepoGeneric.FindOne<Company>(c => c.CompanyId == modelCar.CompanyId); if (company == null) throw new Exception("Company doesn't found"); modelCar.CompanyName = company.Name; modelCar.CompanyId = company.CompanyId; return View(modelCar); }
public IUnitOfWorkResult Add(Car model) { var repo = RepoGeneric; repo.Add<Car>(model); return repo.UnitOfWork.SaveChanges(); }
public IUnitOfWorkResult Edit(Car model) { var repo = RepoGeneric; var record = repo.FindOne<Car>(c => c.CarId == model.CarId); if (record == null) throw new Exception("Car doesn't exist"); record.CarNumber = model.CarNumber; record.Color = model.Color; record.DriverName = model.DriverName; record.Mark = model.Mark; record.Model = model.Model; record.NrOfSeats = model.NrOfSeats; return repo.UnitOfWork.SaveChanges(); }
public ActionResult Edit(EditableCar modelCar) { if (ModelState.IsValid) { Car car = new Car(); car.CarId = modelCar.CarId.GetValueOrDefault(); car.Mark = modelCar.Mark; car.Model = modelCar.Model; car.Color = modelCar.Color; car.NrOfSeats = modelCar.NrOfSeats; car.CarNumber = modelCar.CarNumber; car.DriverName = modelCar.DriverName; car.CompanyId = modelCar.CompanyId; Manager.Edit(car); return RedirectToAction("Index"); } else { return View(modelCar); } }