public virtual ActionResult EditFlightLog(Guid id, FlightLogViewModel flightLogViewModel) { var flightLog = Repository.Get<FlightLog>(id); this.Validate(flightLogViewModel, string.Empty); if (!ModelState.IsValid) { var viewModel = CreateFlightLogViewModel(flightLog); return View(viewModel); } Mapper.Map<FlightLogViewModel, FlightLog>(flightLogViewModel, flightLog); flightLog.Location = Repository.Get<ProgramLocation>(flightLogViewModel.LocationId); flightLog.MarkedUpdated(); TempData["SavedFlightLog"] = true; return RedirectToAction(MVC.FlightLogs.EditFlightLog(id)); }
private FlightLogViewModel CreateFlightLogViewModel(FlightLog flightLog) { var viewModel = new FlightLogViewModel(); var activeLocations = flightProgramsRepository.GetAllActiveProgramLocations(); var activeAircraft = flightProgramsRepository.GetAllActiveAircraftMds(); if (flightLog != null) { Mapper.Map<FlightLog, FlightLogViewModel>(flightLog, viewModel); activeLocations = activeLocations.Union(new ProgramLocation[] { flightLog.Location }); } viewModel.SetActiveLocations(activeLocations); viewModel.SetActiveAircraft(activeAircraft); viewModel.IsFlightLogManager = CurrentUser.Roles.FlightLogManager; return viewModel; }
public virtual ActionResult CreateFlightLog(FlightLogViewModel flightLogViewModel) { this.Validate(flightLogViewModel, string.Empty); if (!ModelState.IsValid) return View(CreateFlightLogViewModel(null)); var flightLog = Mapper.Map<FlightLogViewModel, FlightLog>(flightLogViewModel); flightLog.Location = Repository.Get<ProgramLocation>(flightLogViewModel.LocationId); flightLog = flightLogRepository.AddFlightLog(flightLog); return RedirectToAction(MVC.FlightLogs.EditFlightLog(flightLog.Id.Value)); }