private bool EditRoute(RouteModel route)
        {
            var editWindow = new EditRouteWindow();
            var ctx        = (EditRouteViewModel)editWindow.DataContext;
            var routeCopy  = new RouteModel();

            CopyFields(route, routeCopy);
            ctx.Route               = routeCopy;
            ctx.Airports            = _airportService.GetAllAirports();
            ctx.Carriers            = _carrierService.GetAllCarriers();
            routeCopy.AirportDepart = ctx.Airports.Single(a => a.Id == routeCopy.AirportDepart.Id);
            routeCopy.AirportArrive = ctx.Airports.Single(a => a.Id == routeCopy.AirportArrive.Id);
            if (editWindow.ShowDialog() != true)
            {
                return(false);
            }
            var errs = GetModelErrors(routeCopy);

            if (errs != string.Empty)
            {
                ShowError(errs, "Error! Saving cancelled. ");
                return(false);
            }

            CopyFields(routeCopy, route);
            _routeService.EditRoute(route);
            return(true);
        }
        private void InitializeCommands()
        {
            EditRouteCommand = new RelayCommand(p =>
            {
                if (selectedroute != null)
                {
                    EditRouteWindow window = new EditRouteWindow(selectedroute);
                    if (window.ShowDialog() == true)
                    {
                        // Allroutes = this.GetAll();
                    }
                    else
                    {
                        Allroutes = this.GetAll();
                    }
                }
            });

            AddRouteCommand = new RelayCommand(p =>
            {
                AddNewRouteWindow window = new AddNewRouteWindow();
                if (window.ShowDialog() == true)
                {
                    Allroutes = this.GetAll();
                }
            });

            DeleteRouteCommand = new RelayCommand(p =>
            {
                if (selectedroute != null)
                {
                    if (SelectedRoute.Trips.Count > 0)
                    {
                        foreach (var trip in SelectedRoute.Trips)
                        {
                            if (trip.Departure.Day >= DateTime.Now.Day && trip.Departure.Month >= DateTime.Now.Month && trip.Departure.Year >= DateTime.Now.Year)
                            {
                                MessageBox.Show("У маршрута есть действующие рейсы! Не подлежит изменению");
                                return;
                            }
                        }
                        var result = MessageBox.Show("Вы уверены?", "Удалить запись", MessageBoxButton.YesNo);
                        if (result == MessageBoxResult.Yes)
                        {
                            DeleteRoute(selectedroute);
                            Allroutes = this.GetAll();
                        }
                    }
                }
            });
        }
        private bool AddRoute(RouteModel routeModel)
        {
            var editWindow = new EditRouteWindow();
            var ctx        = (EditRouteViewModel)editWindow.DataContext;

            ctx.Route    = routeModel;
            ctx.Airports = _airportService.GetAllAirports();
            ctx.Carriers = _carrierService.GetAllCarriers();
            if (editWindow.ShowDialog() != true)
            {
                return(false);
            }
            var errs = GetModelErrors(ctx.Route);

            if (errs != string.Empty)
            {
                ShowError(errs, "Error! Saving cancelled. ");
                return(false);
            }

            _routeService.AddRoute(routeModel);
            return(true);
        }