HotelPageViewModel.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using Microsoft.EntityFrameworkCore;
  2. using ReactiveUI;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using travel.Models;
  9. namespace travel.ViewModels
  10. {
  11. public class HotelPageViewModel : ReactiveObject
  12. {
  13. List<Hotel> listHotels = MainWindowViewModel.myConnection.Hotels.Skip(0).Take(10).ToList();
  14. string countElem = "10";
  15. int schet = 0;
  16. string t1 = "0";
  17. string t2 = "0";
  18. public List<Hotel> ListHotels { get => listHotels; set => this.RaiseAndSetIfChanged(ref listHotels, value); }
  19. public string T1 { get => t1; set => this.RaiseAndSetIfChanged(ref t1, value); }
  20. public string T2 { get => t2; set => this.RaiseAndSetIfChanged(ref t2, value); }
  21. public string CountElem
  22. {
  23. get
  24. {
  25. number();
  26. return countElem;
  27. }
  28. set
  29. {
  30. if (value != string.Empty)
  31. countElem = value;
  32. else countElem = "1";
  33. CE();
  34. }
  35. }
  36. public void number()
  37. {
  38. if (MainWindowViewModel.myConnection.Hotels.ToList().Count % Convert.ToInt32(countElem) == 0)
  39. T2 = (MainWindowViewModel.myConnection.Hotels.ToList().Count / Convert.ToInt32(countElem)).ToString();
  40. else
  41. T2 = (MainWindowViewModel.myConnection.Hotels.ToList().Count / Convert.ToInt32(countElem) + 1).ToString();
  42. T1 = (schet + 1).ToString();
  43. }
  44. public void CE()
  45. {
  46. if(countElem != string.Empty || countElem != "0" || countElem != "")
  47. ListHotels = MainWindowViewModel.myConnection.Hotels.Skip(0).Take(Convert.ToInt32(countElem)).ToList();
  48. else
  49. ListHotels = MainWindowViewModel.myConnection.Hotels.ToList();
  50. }
  51. public void Start()
  52. {
  53. ListHotels = MainWindowViewModel.myConnection.Hotels.Skip(0).Take(Convert.ToInt32(countElem)).ToList();
  54. schet = 0;
  55. number();
  56. }
  57. public void End()
  58. {
  59. int c = Convert.ToInt32(countElem) * (MainWindowViewModel.myConnection.Hotels.ToList().Count / Convert.ToInt32(countElem));
  60. ListHotels = MainWindowViewModel.myConnection.Hotels.Skip(c).Take(Convert.ToInt32(countElem)).ToList();
  61. if (MainWindowViewModel.myConnection.Hotels.ToList().Count % Convert.ToInt32(countElem) == 0)
  62. schet = MainWindowViewModel.myConnection.Hotels.ToList().Count / Convert.ToInt32(countElem)-1;
  63. else
  64. schet = MainWindowViewModel.myConnection.Hotels.ToList().Count / Convert.ToInt32(countElem);
  65. number();
  66. }
  67. public void Back()
  68. {
  69. if (schet != 0)
  70. schet--;
  71. ListHotels = MainWindowViewModel.myConnection.Hotels.Skip(schet * Convert.ToInt32(countElem)).Take(Convert.ToInt32(countElem)).ToList();
  72. number();
  73. }
  74. public void Next()
  75. {
  76. if (schet < Convert.ToInt32(T2)-1)
  77. schet++;
  78. ListHotels = MainWindowViewModel.myConnection.Hotels.Skip(schet * Convert.ToInt32(countElem)).Take(Convert.ToInt32(countElem)).ToList();
  79. number();
  80. }
  81. }
  82. }