// // GET: /Reminder/Add/1 public ActionResult Add(int vehicleId) { var vehicles = Using<GetVehicleListForUser>() .Execute(CurrentUserId); var vehicle = vehicles.First(v => v.VehicleId == vehicleId); var reminders = Using<GetUnfulfilledRemindersForVehicle>() .Execute(CurrentUserId, vehicleId, vehicle.Odometer ?? 0) .Select(r => new ReminderSummaryModel(r, r.IsOverdue ?? false)); var viewModel = new ReminderAddViewModel { VehicleList = new VehicleListViewModel(vehicles, vehicleId) { IsCollapsed = true }, Reminder = new ReminderFormModel(), Reminders = new SelectedItemList<ReminderSummaryModel>(reminders), }; return View(viewModel); }
public ActionResult Add(int vehicleId, ReminderFormModel reminder) { if ((reminder != null) && ModelState.IsValid) { var errors = Using<CanAddReminder>().Execute(CurrentUserId, reminder); ModelState.AddModelErrors(errors, "Add"); if (ModelState.IsValid) { Using<AddReminderToVehicle>().Execute(CurrentUserId, vehicleId, reminder); return RedirectToAction("Details", "Reminder", new { id = reminder.ReminderId }); } } var vehicles = Using<GetVehicleListForUser>() .Execute(CurrentUserId); var vehicle = vehicles.First(v => v.VehicleId == vehicleId); var reminders = Using<GetUnfulfilledRemindersForVehicle>() .Execute(CurrentUserId, vehicleId, vehicle.Odometer ?? 0) .Select(r => new ReminderSummaryModel(r, r.IsOverdue ?? false)); var viewModel = new ReminderAddViewModel { VehicleList = new VehicleListViewModel(vehicles, vehicleId) { IsCollapsed = true }, Reminder = reminder, Reminders = new SelectedItemList<ReminderSummaryModel>(reminders), }; return View(viewModel); }