|
@@ -9,11 +9,21 @@ namespace UPtur.ViewModels
|
|
|
public class ToursViewModel : ReactiveObject
|
|
|
{
|
|
|
UpPrytovContext DB = new UpPrytovContext();
|
|
|
- private List<Tour>? _tours;
|
|
|
+ private List<Tour>? _tours;
|
|
|
public List<Tour>? Tours { get => _tours; set => this.RaiseAndSetIfChanged(ref _tours, value); }
|
|
|
|
|
|
- private List<string>? _types;
|
|
|
- public List<string>? Types { get => _types; set => this.RaiseAndSetIfChanged(ref _types, 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
|
|
@@ -37,16 +47,133 @@ namespace UPtur.ViewModels
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ 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 = 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.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);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+}
|