12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using Microsoft.EntityFrameworkCore;
- using ReactiveUI;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using travel.Models;
- namespace travel.ViewModels
- {
- public class HotelPageViewModel : ReactiveObject
- {
- List<Hotel> listHotels = MainWindowViewModel.myConnection.Hotels.Skip(0).Take(10).ToList();
- string countElem = "10";
- int schet = 0;
- string t1 = "0";
- string t2 = "0";
- public List<Hotel> ListHotels { get => listHotels; set => this.RaiseAndSetIfChanged(ref listHotels, value); }
- public string T1 { get => t1; set => this.RaiseAndSetIfChanged(ref t1, value); }
- public string T2 { get => t2; set => this.RaiseAndSetIfChanged(ref t2, value); }
- public string CountElem
- {
- get
- {
- number();
- return countElem;
- }
- set
- {
- if (value != string.Empty)
- countElem = value;
- else countElem = "1";
- CE();
- }
- }
- public void number()
- {
- if (MainWindowViewModel.myConnection.Hotels.ToList().Count % Convert.ToInt32(countElem) == 0)
- T2 = (MainWindowViewModel.myConnection.Hotels.ToList().Count / Convert.ToInt32(countElem)).ToString();
- else
- T2 = (MainWindowViewModel.myConnection.Hotels.ToList().Count / Convert.ToInt32(countElem) + 1).ToString();
- T1 = (schet + 1).ToString();
- }
- public void CE()
- {
- if(countElem != string.Empty || countElem != "0" || countElem != "")
- ListHotels = MainWindowViewModel.myConnection.Hotels.Skip(0).Take(Convert.ToInt32(countElem)).ToList();
- else
- ListHotels = MainWindowViewModel.myConnection.Hotels.ToList();
- }
- public void Start()
- {
- ListHotels = MainWindowViewModel.myConnection.Hotels.Skip(0).Take(Convert.ToInt32(countElem)).ToList();
- schet = 0;
- number();
- }
- public void End()
- {
- int c = Convert.ToInt32(countElem) * (MainWindowViewModel.myConnection.Hotels.ToList().Count / Convert.ToInt32(countElem));
- ListHotels = MainWindowViewModel.myConnection.Hotels.Skip(c).Take(Convert.ToInt32(countElem)).ToList();
- if (MainWindowViewModel.myConnection.Hotels.ToList().Count % Convert.ToInt32(countElem) == 0)
- schet = MainWindowViewModel.myConnection.Hotels.ToList().Count / Convert.ToInt32(countElem)-1;
- else
- schet = MainWindowViewModel.myConnection.Hotels.ToList().Count / Convert.ToInt32(countElem);
- number();
- }
- public void Back()
- {
- if (schet != 0)
- schet--;
- ListHotels = MainWindowViewModel.myConnection.Hotels.Skip(schet * Convert.ToInt32(countElem)).Take(Convert.ToInt32(countElem)).ToList();
- number();
- }
- public void Next()
- {
- if (schet < Convert.ToInt32(T2)-1)
- schet++;
- ListHotels = MainWindowViewModel.myConnection.Hotels.Skip(schet * Convert.ToInt32(countElem)).Take(Convert.ToInt32(countElem)).ToList();
- number();
- }
- }
- }
|