// // GET: /Fillups/Add/1 public ActionResult Add(int vehicleId) { var vehicles = Using<GetVehicleListForUser>() .Execute(CurrentUserId); var vehicle = vehicles.First(v => v.VehicleId == vehicleId); var newFillupEntry = new FillupEntryFormModel { Odometer = vehicle.Odometer.HasValue ? vehicle.Odometer.Value : 0 }; var fillups = Using<GetFillupsForVehicle>() .Execute(vehicleId) .OrderByDescending(f => f.Date); var viewModel = new FillupAddViewModel { VehicleList = new VehicleListViewModel(vehicles, vehicleId) {IsCollapsed = true}, FillupEntry = newFillupEntry, Fillups = new SelectedItemList<Model.FillupEntry>(fillups), }; ViewBag.IsFirstFillup = (!fillups.Any()); return View(viewModel); }
public ActionResult Add(int vehicleId, FillupEntryFormModel model) { var vehicles = Using<GetVehicleListForUser>() .Execute(CurrentUserId ); if (ModelState.IsValid) { var errors = Using<CanAddFillup>() .Execute(CurrentUserId, vehicleId, model); ModelState.AddModelErrors(errors, "AddFillup"); if (ModelState.IsValid) { Using<AddFillupToVehicle>().Execute(CurrentUserId, vehicleId, model); TempData["LastActionMessage"] = Resources.VehicleController_AddFillupSuccessMessage; return RedirectToAction("List", "Fillup", new { vehicleId = vehicleId }); } } var fillups = Using<GetFillupsForVehicle>() .Execute(vehicleId) .OrderByDescending(f => f.Date); var viewModel = new FillupAddViewModel { VehicleList = new VehicleListViewModel(vehicles, vehicleId) { IsCollapsed = true }, FillupEntry = model, Fillups = new SelectedItemList<Model.FillupEntry>(fillups), }; ViewBag.IsFirstFillup = (!fillups.Any()); return View(viewModel); }