public ActionResult ShowMap(int?PackageId) { int packageId; if (!PackageId.HasValue) { return(RedirectToAction("Search", "Packages")); } else { packageId = PackageId.GetValueOrDefault(); } ShowMapViewModel model = new ShowMapViewModel(); string errorMessage = "Sorry, we are unable to display the locations for this package."; string noLocationsError = "Sorry, we do not have any map locations saved for this package."; try { Result <Package> packageResult = new Result <Package>(); packageResult = packageService.GetPackageById(packageId); if (packageResult.Status == ResultEnum.Success && packageResult.Data.Status == PackageStatusEnum.Available) { IEnumerable <Activity> activities = packageResult.Data.Activities; model = activities.ToShowMapViewModel(); if (model.Locations.Count() < 1 || model.Locations.Count() > 3) { ModelState.AddModelError("ErrorMessage", noLocationsError); } return(View(model)); } else { ModelState.AddModelError("ErrorMessage", errorMessage); return(View(model)); } } catch { ModelState.AddModelError("ErrorMessage", errorMessage); return(View(model)); } #endregion }
public static ShowMapViewModel ToShowMapViewModel(this IEnumerable <Activity> activities) { ShowMapViewModel model = new ShowMapViewModel(); model.Locations = new List <LocationModel>(); foreach (Activity activity in activities) { if (activity.Latitude != 0 && activity.Longitude != 0) { model.Locations.Add(new LocationModel { ActivityName = activity.Name, ActivityAddress = activity.Address, Latitude = activity.Latitude, Longitude = activity.Longitude }); } } return(model); }
//private static WndShowMap mapWnd = new WndShowMap(); public static void ShowWndMap(OrderCustomerAddress address) { try { logger.Debug("ShowWndMap"); System.Windows.Application.Current.Dispatcher.Invoke(() => { var model = new ShowMapViewModel(address); WndShowMap mapWnd = new WndShowMap { DataContext = model }; ShowDialogWnd(mapWnd); }); } catch (Exception e) { logger.Error($"ShowWndChangeOrderStatus {e.Message}"); } }