using System; using System.Collections.Generic; using System.Linq; using Avalonia.Controls; using Microsoft.EntityFrameworkCore; using MsBox.Avalonia; using MsBox.Avalonia.Enums; using ReactiveUI; using TourAgent.Models; using TourAgent.Views; namespace MPrakt.ViewModels { public class OtelsViewModel : ReactiveObject { UP_SmirnovContext DB = new UP_SmirnovContext(); UserControl us = new TourAgent.Views.Menu(); public UserControl US { get => us; set => this.RaiseAndSetIfChanged(ref us, value); } private List? _hotels; public List? Hotels { get => _hotels; set => this.RaiseAndSetIfChanged(ref _hotels, value); } private int countElements = 10; public int CountElements { get => countElements; set => this.RaiseAndSetIfChanged(ref countElements, 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; public void ChangePageToHotels() { US = new Hotels(); } public void ChangePageToTours() { US = new TourAgent.Views.Hotels(); } public void ToMenu() { US = new TourAgent.Views.Menu(); } public OtelsViewModel() { Hotels = DB.Hotels.ToList(); 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() { 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 + 1; Hotels = Hotels.Skip(Page * CountElements).ToList(); Hotels = Hotels.Take(CountElements).ToList(); EnableOrNotRight = false; EnableOrNotLeft = true; } public override bool Equals(object? obj) { return base.Equals(obj); } public override int GetHashCode() { return base.GetHashCode(); } public override string? ToString() { return base.ToString(); } } }