// GET: Service/Create public ActionResult Create() { var viewModel = new ServiceCarViewModel { cars = _context.carModels.ToList() }; return(View(viewModel)); }
public ActionResult Update(ServiceCarViewModel viewModel) { if (!ModelState.IsValid) { return(View("Create", viewModel)); } var car = _context.carModels.Single(c => c.Id == viewModel.Car); var service = _context.carServices.Single(e => e.Id == viewModel.Id); service.serviceName = viewModel.serviceName; service.Description = viewModel.Description; service.ToDateTime = viewModel.ToDateTime; service.FromDateTime = viewModel.FromDateTime; service.Price = viewModel.Price; service.CarModel.Id = viewModel.Car; //_context.carServices.Add(service); _context.SaveChanges(); return(RedirectToAction("Index", "Service")); }
public ActionResult Create(ServiceCarViewModel viewModel) { if (!ModelState.IsValid) { viewModel.cars = _context.carModels.ToList(); return(View("Create", viewModel)); } var car = _context.carModels.Single(c => c.Id == viewModel.Car); var service = new CarService { serviceName = viewModel.serviceName, Description = viewModel.Description, FromDateTime = viewModel.FromDateTime, ToDateTime = viewModel.ToDateTime, Price = viewModel.Price, CarModel = car }; _context.carServices.Add(service); _context.SaveChanges(); return(RedirectToAction("Index", "Service")); }
// GET: Service/Edit/5 public ActionResult Edit(int id) { var service = _context.carServices .Single(g => g.Id == id); var viewModel = new ServiceCarViewModel { cars = _context.carModels.ToList(), Id = service.Id, serviceName = service.serviceName, Description = service.Description, FromDateTime = service.FromDateTime, ToDateTime = service.FromDateTime, Price = service.Price }; if (service == null) { return(HttpNotFound()); } return(View(viewModel)); }