public ActionResult EditTrip(int tripId) { BlViewTrip trip = null; var _blError = TripManager.GetTripById(tripId, out trip); // error handling if (_blError.ErrorCode != 0) { throw new ApplicationException(_blError.ErrorMessage); } if (trip == null || trip.DlTripView == null) { throw new ApplicationException(String.Format("Invalid trip id requested: {0}", tripId)); } if (trip.DlTripView.AspNetUserId != User.Identity.GetUserId()) { throw new ApplicationException(String.Format("Unauthorized trip id requested: {0} by {1}", tripId, User.Identity.GetUserId())); } // looks like all ok List <BlTripTemplate> _allTemplates = null; List <BlTripTemplate> _relatedTemplates = new List <BlTripTemplate>(); _blError = TripManager.SearchTripTemplatesByAlias(trip.DlTripView.TemplateSearchAlias, out _allTemplates); if (_allTemplates != null) { foreach (var template in _allTemplates) { if (!trip.DlTripView.Templates.Contains(template.DlTemplate.Id.ToString())) { _relatedTemplates.Add(template); } } } var startLocationOptions = trip.DlTripView.StartLocation.Split('/').ToList(); var _tripStartLocationOptions = new List <SelectListItem>(); foreach (var startLocation in startLocationOptions) { _tripStartLocationOptions.Add(new SelectListItem() { Text = startLocation, Value = startLocation }); } var _model = new EditTripViewModel() { ActiveTrip = trip, RelatedTemplates = _relatedTemplates, TripStartLocationOptions = _tripStartLocationOptions }; return(View("EditTrip", _model)); }
public ActionResult ListAllTripTemplates(string templateAlias) { var _availableTemplates = new List <BlTripTemplate>(); var _allTemplates = new List <BlTripTemplate>(); var _blError = TripManager.SearchTripTemplatesByAlias(templateAlias, out _availableTemplates); var _trip = TripManager.GetImmediateTripForUser(User.Identity.GetUserId()); if (_availableTemplates != null) { foreach (var template in _availableTemplates) { // if there is already a trip that includes this template - then if (_trip != null && _trip.DlTripView != null && !String.IsNullOrEmpty(_trip.DlTripView.Templates) && _trip.DlTripView.Templates.Contains(template.DlTemplate.Id.ToString())) { // do nothing } else // add it to the available list { _allTemplates.Add(template); } } } var _model = new TripViewModel() { AliasName = templateAlias, AllTemplates = _allTemplates }; if (_trip != null) { _model.ImmediateTripId = _trip.DlTripView.Id; _model.ActiveTrip = _trip; } if (_availableTemplates.Count > 0) { _model.Country = _availableTemplates[0].Country; } return(View("TripTemplates", _model)); }