Beispiel #1
0
        public MainWindow()
        {
            InitializeComponent();

            shView     = new ScheduleView();
            toursView  = new ToursView();
            salesView  = new SalesView();
            guidesView = new GuidesView();

            DataContext = shView;
            //Height = SystemParameters.PrimaryScreenHeight * 0.75;
            //Width = SystemParameters.PrimaryScreenWidth * 0.75;
        }
Beispiel #2
0
        /// <summary>
        /// Возвращает модель-представление списка туров
        /// </summary>
        private ToursView GetToursViewModel()
        {
            var viewModel = new ToursView();

            var citiesList = _dbContext.cities
                             .ToList();

            var hotels = _dbContext.hotels
                         .Include("city")
                         .Include("tour")
                         .ToList();

            var tours = _dbContext.tours
                        .Include("country");

            var rooms = _dbContext.rooms
                        .ToList();

            foreach (var tour in tours)
            {
                var citiesId = new List <int>();
                var min      = 0;

                foreach (var hotel in hotels)
                {
                    if (hotel.tour_id == tour.id)
                    {
                        var id = hotel.city.id;

                        if (!citiesId.Any(x => x == id))
                        {
                            citiesId.Add(id);
                        }

                        foreach (var room in rooms)
                        {
                            if (room.hotel_id == hotel.id)
                            {
                                if (min == 0)
                                {
                                    min = room.cost_per_day;
                                }
                                else
                                if (min > room.cost_per_day)
                                {
                                    min = room.cost_per_day;
                                }
                            }
                        }
                    }
                }

                var cities = "";
                var first  = true;

                foreach (var id in citiesId)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        cities += ", ";
                    }

                    cities += citiesList.First(x => x.id == id).name;
                }

                viewModel.TourViewItems.Add(
                    new ToursView.TourViewItem
                {
                    TourId      = tour.id,
                    TourName    = tour.name,
                    CountryName = tour.country?.name,
                    Cities      = cities,
                    Description = "летний",
                    MinCost     = 5 * min
                });
            }

            return(viewModel);
        }