|
@@ -1,10 +1,123 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using MsBox.Avalonia;
|
|
|
+using MsBox.Avalonia.Enums;
|
|
|
using ReactiveUI;
|
|
|
+using UPtur.Models;
|
|
|
|
|
|
namespace UPtur.ViewModels
|
|
|
{
|
|
|
- public class HotelsViewModel : ReactiveObject
|
|
|
- {
|
|
|
- }
|
|
|
-}
|
|
|
+ public class HotelsViewModel : ReactiveObject
|
|
|
+ {
|
|
|
+ UpPrytovContext DB = new UpPrytovContext();
|
|
|
+ private List<Hotel>? _hotels; //ëèñòû îòåëåé
|
|
|
+ public List<Hotel>? Hotels { get => _hotels; set => this.RaiseAndSetIfChanged(ref _hotels, value); }
|
|
|
+ private int countElements;
|
|
|
+ public int CountElements
|
|
|
+ {
|
|
|
+ get => countElements;//äëÿ âûâîäà îïðåäåëåííûé ñòðàíèö íà ýêðàíå
|
|
|
+ set
|
|
|
+ {
|
|
|
+ this.RaiseAndSetIfChanged(ref countElements, value);
|
|
|
+ Hotels = DB.Hotels.ToList();
|
|
|
+ AmountOfPages = Hotels.Count / countElements + 1;
|
|
|
+ ToFirstPage();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private int _amountOfPages;
|
|
|
+ public int AmountOfPages
|
|
|
+ {
|
|
|
+ get => _amountOfPages;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ this.RaiseAndSetIfChanged(ref _amountOfPages, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private int _page = 1;
|
|
|
+ public int Page { get => _page; set => this.RaiseAndSetIfChanged(ref _page, value); }
|
|
|
+ private bool _enableOrNotRight = true;
|
|
|
+ public bool EnableOrNotRight { get => _enableOrNotRight; set => this.RaiseAndSetIfChanged(ref _enableOrNotRight, value); }
|
|
|
+ private bool _enableOrNotLeft = false;
|
|
|
+ public bool EnableOrNotLeft { get => _enableOrNotLeft; set => this.RaiseAndSetIfChanged(ref _enableOrNotLeft, value); }
|
|
|
+ int flagElementCount = 0;
|
|
|
+
|
|
|
+ private List<int> _selectCountOfElements = new List<int>() { 10, 15, 20 };//âûáîð êîë-âî ñòðàíèö íà ýêðàíå
|
|
|
+ public List<int> SelectedCountOfElements { get => _selectCountOfElements; set => this.RaiseAndSetIfChanged(ref _selectCountOfElements, value); }
|
|
|
+
|
|
|
+ private List<Hotel> _selectedHotels;
|
|
|
+ public List<Hotel> SelectedHotels
|
|
|
+ {
|
|
|
+ get => _selectedHotels;
|
|
|
+ set => this.RaiseAndSetIfChanged(ref _selectedHotels, value);
|
|
|
+ }
|
|
|
+ public HotelsViewModel()//âûâîä ïåðâûõ 10 çàïèñåé
|
|
|
+ {
|
|
|
+ Hotels = DB.Hotels.ToList();
|
|
|
+ CountElements = SelectedCountOfElements[0];
|
|
|
+ Hotels = Hotels.Take(CountElements).ToList();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void NextPage()//ïåðåõîä íà ñëåäóþùóþ ñòðàíèöó
|
|
|
+ {
|
|
|
+ Page++;
|
|
|
+ Hotels = DB.Hotels.ToList();
|
|
|
+ Hotels = Hotels.Skip((Page - 1) * CountElements).ToList();
|
|
|
+ flagElementCount = Hotels.Count();
|
|
|
+ Hotels = Hotels.Take(CountElements).ToList();
|
|
|
+ EnableOrNotLeft = true;
|
|
|
+ if (flagElementCount <= CountElements)
|
|
|
+ {
|
|
|
+ EnableOrNotRight = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ EnableOrNotRight = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void PrevPage()//ïåðåõîä íà ïðåäûäóùóþ ñòðàíèöó
|
|
|
+ {
|
|
|
+ Page--;
|
|
|
+ Hotels = DB.Hotels.ToList();
|
|
|
+ Hotels = Hotels.Skip((Page - 1) * CountElements).ToList();
|
|
|
+ Hotels = Hotels.Take(CountElements).ToList();
|
|
|
+ EnableOrNotRight = true;
|
|
|
+ if (Page == 1)
|
|
|
+ {
|
|
|
+ EnableOrNotLeft = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ EnableOrNotLeft = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void ToFirstPage()//ïåðåõîä íà ñàìóþ 1 ñòðàíèöó
|
|
|
+ {
|
|
|
+ Page = 1;
|
|
|
+ Hotels = DB.Hotels.ToList();
|
|
|
+ Hotels = Hotels.Take(CountElements).ToList();
|
|
|
+ EnableOrNotLeft = false;
|
|
|
+ EnableOrNotRight = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void ToLastPage()//ïåðåõîä íà ïîñëåäíþþ ñòðàíèöó
|
|
|
+ {
|
|
|
+ Hotels = DB.Hotels.ToList();
|
|
|
+ Page = Hotels.Count / CountElements;
|
|
|
+ Hotels = Hotels.Skip(Page * CountElements).ToList();
|
|
|
+ Hotels = Hotels.Take(CountElements).ToList();
|
|
|
+ Page++;
|
|
|
+ EnableOrNotRight = false;
|
|
|
+ EnableOrNotLeft = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|