MainWindowViewModel.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Avalonia.Controls;
  2. using AvaloniaApplicationTest.Models;
  3. using AvaloniaApplicationTest.Views;
  4. using ReactiveUI;
  5. using System.Linq;
  6. using System.Net;
  7. namespace AvaloniaApplicationTest.ViewModels
  8. {
  9. public class MainWindowViewModel : ViewModelBase
  10. {
  11. public static UpKrupinaContext myConnection = new UpKrupinaContext();
  12. UserControl us = new TourPage();
  13. public UserControl US
  14. {
  15. get => us;
  16. set => this.RaiseAndSetIfChanged(ref us, value);
  17. }
  18. public ShowTourPageViewModel PageTours { get => pageTours; set => pageTours = value; }
  19. ShowTourPageViewModel pageTours = new ShowTourPageViewModel();
  20. public ShowHotelsPageViewModel PageHotels { get => pageHotels; set => pageHotels = value; }
  21. ShowHotelsPageViewModel pageHotels = new ShowHotelsPageViewModel();
  22. public AddPageViewModel PageAdd { get => pageAdd; set => pageAdd = value; }
  23. AddPageViewModel pageAdd = new AddPageViewModel();
  24. public void ToHotels()
  25. {
  26. US = new ShowHotelsPage();
  27. }
  28. public void ToTours()
  29. {
  30. US = new TourPage();
  31. }
  32. public void ToAdd()
  33. {
  34. PageAdd = new AddPageViewModel();
  35. US = new AddPage();
  36. }
  37. public void ToChange(int ID)
  38. {
  39. PageAdd = new AddPageViewModel(ID);
  40. US = new AddPage();
  41. }
  42. public void DeleteHotel(int ID)
  43. {
  44. Hotel hotel = myConnection.Hotels.FirstOrDefault(x=> x.Id == ID);
  45. if (hotel != null)
  46. {
  47. myConnection.Hotels.Remove(hotel);
  48. myConnection.SaveChanges();
  49. }
  50. US = new ShowHotelsPage();
  51. }
  52. }
  53. }