1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using ReactiveUI;
- using TourAgent.Models;
- namespace TourAgent.ViewModels
- {
- public class HotelsViewModel : ReactiveObject
- {
- UP_SmirnovContext DB = new UP_SmirnovContext();
- private List<Hotel>? _hotels;
- public List<Hotel>? 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 HotelsViewModel()
- {
- 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;
- }
- }
- }
|