123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using Avalonia.Controls;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Logging;
- using ReactiveUI;
- using TourAgent.Models;
- using TourAgent.Views;
- namespace TourAgent.ViewModels
- {
- public class HWindowViewModel : ViewModelBase
- {
- public static UP_SmirnovContext DB = new UP_SmirnovContext();
- UserControl us = new Views.Menu();
- public UserControl US
- {
- get => us;
- set => this.RaiseAndSetIfChanged(ref us, value);
- }
- MenuViewModel menuVM = new MenuViewModel();
- public MenuViewModel MenuVM
- {
- get => menuVM;
- set => menuVM = value;
- }
- ToursViewModel _toursVM = new ToursViewModel();
- public ToursViewModel ToursVM
- {
- get => _toursVM;
- set => _toursVM = value;
- }
- HotelsViewModel _hotelsVM = new HotelsViewModel();
- public HotelsViewModel HotelsVM
- {
- get => _hotelsVM;
- set => _hotelsVM = value;
- }
- public void ChangePageToHotels()
- {
- US = new Hotels();
- }
- public void ChangePageToTours()
- {
- US = new Tours();
- }
- public void ToMenu()
- {
- US = new Views.Menu();
- }
- }
- public class ToursViewModel : ReactiveObject
- {
- UP_SmirnovContext DB = new UP_SmirnovContext();
- private List<Tour>? _tours;
- public List<Tour>? Tours { get => _tours; set => this.RaiseAndSetIfChanged(ref _tours, value); }
- private static List<string>? _types;
- public static List<string>? Types { get => _types; set => _types = value; }
- private static List<string>? _sort;
- public static List<string>? Sort { get => _sort; set => _sort = value; }
- private decimal _priceOfAll;
- public decimal PriceOfAll
- {
- get => _priceOfAll;
- set => this.RaiseAndSetIfChanged(ref _priceOfAll, value);
- }
- private bool _checkOrNot = false;
- public bool CheckOrNot
- {
- get => _checkOrNot;
- set
- {
- _checkOrNot = value;
- Filter();
- }
- }
- private string? _findTour;
- public string? FindTour
- {
- get => _findTour;
- set
- {
- _findTour = value;
- Filter();
- }
- }
- private string? _selectedItem;
- public string? SelectedItem
- {
- get
- {
- return _selectedItem;
- }
- set
- {
- _selectedItem = value;
- Filter();
- }
- }
- private string? _selectedSort;
- public string? SelectedSort
- {
- get
- {
- return _selectedSort;
- }
- set
- {
- _selectedSort = value;
- Filter();
- }
- }
- public ToursViewModel()
- {
- Tours = DB.Tours.ToList();
- Types = DB.Types.Select(x=>x.Name).ToList();
- Types.Insert(0, "Âñå");
- SelectedItem = Types[0];
- Sort = new List<string> { "Áåç ñîðòèðîâêè", "Ïî âîçðàñòàíèþ öåíû", "Ïî óáûâàíèþ öåíû" };
- SelectedSort = Sort[0];
- }
- public void Filter()
- {
- Tours = DB.Tours.ToList();
- PriceOfAll = 0;
- if (SelectedItem != "Âñå")
- {
- List <TypeOfTour> TypesForFilter = DB.TypeOfTours.ToList();
- List <int> IdForFilter = new List<int>();
- switch (SelectedItem)
- {
- case "Ìåæäóíàðîäíûé òóðèçì":
- TypesForFilter = TypesForFilter.Where(x=>x.TypeId==1).ToList();
- IdForFilter = TypesForFilter.Select(x=>x.TourId).ToList();
- Tours = Tours.Where(x=> IdForFilter.Contains(x.Id)).ToList();
- break;
- case "Âíóòðåííèé òóðèçì":
- TypesForFilter = TypesForFilter.Where(x => x.TypeId == 2).ToList();
- IdForFilter = TypesForFilter.Select(x => x.TourId).ToList();
- Tours = Tours.Where(x => IdForFilter.Contains(x.Id)).ToList();
- break;
- case "Ëå÷åáíî-îçäîðîâèòåëüíûå òóðû":
- TypesForFilter = TypesForFilter.Where(x => x.TypeId == 3).ToList();
- IdForFilter = TypesForFilter.Select(x => x.TourId).ToList();
- Tours = Tours.Where(x => IdForFilter.Contains(x.Id)).ToList();
- break;
- case "Ïëÿæíûå òóðû":
- TypesForFilter = TypesForFilter.Where(x => x.TypeId == 4).ToList();
- IdForFilter = TypesForFilter.Select(x => x.TourId).ToList();
- Tours = Tours.Where(x => IdForFilter.Contains(x.Id)).ToList();
- break;
- case "Ýêñêóðñèîííûå òóðû":
- TypesForFilter = TypesForFilter.Where(x => x.TypeId == 5).ToList();
- IdForFilter = TypesForFilter.Select(x => x.TourId).ToList();
- Tours = Tours.Where(x => IdForFilter.Contains(x.Id)).ToList();
- break;
- case "Ñïåöèàëèçèðîâàííûå äåòñêèå òóðû":
- TypesForFilter = TypesForFilter.Where(x => x.TypeId == 6).ToList();
- IdForFilter = TypesForFilter.Select(x => x.TourId).ToList();
- Tours = Tours.Where(x => IdForFilter.Contains(x.Id)).ToList();
- break;
- case "Îáñëóæèâàíèå êîðïîðàòèâíûõ êëèåíòîâ ïî çàêàçó":
- TypesForFilter = TypesForFilter.Where(x => x.TypeId == 7).ToList();
- IdForFilter = TypesForFilter.Select(x => x.TourId).ToList();
- Tours = Tours.Where(x => IdForFilter.Contains(x.Id)).ToList();
- break;
- case "Ãîðíîëûæíûå êóðîðòû":
- TypesForFilter = TypesForFilter.Where(x => x.TypeId == 8).ToList();
- IdForFilter = TypesForFilter.Select(x => x.TourId).ToList();
- Tours = Tours.Where(x => IdForFilter.Contains(x.Id)).ToList();
- break;
- case "Êóëüòóðíî-èñòîðè÷åñêèå òóðû":
- TypesForFilter = TypesForFilter.Where(x => x.TypeId == 9).ToList();
- IdForFilter = TypesForFilter.Select(x => x.TourId).ToList();
- Tours = Tours.Where(x => IdForFilter.Contains(x.Id)).ToList();
- break;
- default:
- break;
- }
- }
- if(CheckOrNot)
- {
- Tours = Tours.Where(x => x.IsActual[0]==true).ToList();
- }
- if(FindTour!=null && FindTour != "")
- {
- Tours = Tours.Where(x=>x.Name.ToUpper().Contains(FindTour.ToString().ToUpper()) || x.DescriptionWithoutNull.ToUpper().Contains(FindTour.ToString().ToUpper())).ToList();
- }
- if(SelectedSort != "Áåç ñîðòèðîâêè")
- {
- switch(SelectedSort)
- {
- case "Ïî âîçðàñòàíèþ öåíû":
- Tours = Tours.OrderBy(x=>x.Price).ToList();
- break;
- case "Ïî óáûâàíèþ öåíû":
- Tours = Tours.OrderByDescending(x => x.Price).ToList();
- break;
- }
- }
- foreach(Tour t in Tours)
- {
- PriceOfAll += (t.Price * t.TicketCount);
- }
- }
- }
- }
|