|
@@ -0,0 +1,173 @@
|
|
|
+using ReactiveUI;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using Tmds.DBus.Protocol;
|
|
|
+using travel.Models;
|
|
|
+using travel.Views;
|
|
|
+
|
|
|
+namespace travel.ViewModels
|
|
|
+{
|
|
|
+ public class HotelCardViewModel : ReactiveObject
|
|
|
+ {
|
|
|
+ Hotel hotelEdit = new Hotel();
|
|
|
+ bool state = false;
|
|
|
+ string title = "";
|
|
|
+ string description = "";
|
|
|
+ string star1 = "☆";
|
|
|
+ string star2 = "☆";
|
|
|
+ string star3 = "☆";
|
|
|
+ string star4 = "☆";
|
|
|
+ string star5 = "☆";
|
|
|
+ List<String> countries = MainWindowViewModel.myConnection.Countries.Select(x => x.Name).ToList();
|
|
|
+ string select = "Russia";
|
|
|
+ string message = "";
|
|
|
+ int starCount = 0;
|
|
|
+
|
|
|
+ public List<String> ListCountry { get => countries; }
|
|
|
+ public string SelectCountry { get => select; set { this.RaiseAndSetIfChanged(ref select, value); } }
|
|
|
+ public string TitleHotel { get => title; set { this.RaiseAndSetIfChanged(ref title, value); } }
|
|
|
+ public string Message { get => message; set { this.RaiseAndSetIfChanged(ref message, value); } }
|
|
|
+ public string DescriptionHotel { get => description; set { this.RaiseAndSetIfChanged(ref description, value); } }
|
|
|
+ public string Star1 { get => star1; set { this.RaiseAndSetIfChanged(ref star1, value); } }
|
|
|
+ public string Star2 { get => star2; set { this.RaiseAndSetIfChanged(ref star2, value); } }
|
|
|
+ public string Star3 { get => star3; set { this.RaiseAndSetIfChanged(ref star3, value); } }
|
|
|
+ public string Star4 { get => star4; set { this.RaiseAndSetIfChanged(ref star4, value); } }
|
|
|
+ public string Star5 { get => star5; set { this.RaiseAndSetIfChanged(ref star5, value); } }
|
|
|
+
|
|
|
+
|
|
|
+ public HotelCardViewModel(int IDhotel)
|
|
|
+ {
|
|
|
+ state = true;
|
|
|
+ hotelEdit = MainWindowViewModel.myConnection.Hotels.FirstOrDefault(x => x.Id == IDhotel);
|
|
|
+ TitleHotel = hotelEdit.Name;
|
|
|
+ DescriptionHotel = hotelEdit.Description;
|
|
|
+ Country c = MainWindowViewModel.myConnection.Countries.FirstOrDefault(x => x.Code == hotelEdit.CountryCode);
|
|
|
+ SelectCountry = c.Name;
|
|
|
+ switch(hotelEdit.CountOfStars)
|
|
|
+ {
|
|
|
+ case 1:
|
|
|
+ SelectStar1();
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ SelectStar2();
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ SelectStar3();
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ SelectStar4();
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ SelectStar5();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ SelectStar0();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public HotelCardViewModel()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ public async Task SelectStar1()
|
|
|
+ {
|
|
|
+ Star1 = "★";
|
|
|
+ Star2 = "☆";
|
|
|
+ Star3 = "☆";
|
|
|
+ Star4 = "☆";
|
|
|
+ Star5 = "☆";
|
|
|
+ starCount = 1;
|
|
|
+ }
|
|
|
+ public async Task SelectStar2()
|
|
|
+ {
|
|
|
+ Star1 = "★";
|
|
|
+ Star2 = "★";
|
|
|
+ Star3 = "☆";
|
|
|
+ Star4 = "☆";
|
|
|
+ Star5 = "☆";
|
|
|
+ starCount = 2;
|
|
|
+ }
|
|
|
+ public async Task SelectStar3()
|
|
|
+ {
|
|
|
+ Star1 = "★";
|
|
|
+ Star2 = "★";
|
|
|
+ Star3 = "★";
|
|
|
+ Star4 = "☆";
|
|
|
+ Star5 = "☆";
|
|
|
+ starCount = 3;
|
|
|
+ }
|
|
|
+ public async Task SelectStar4()
|
|
|
+ {
|
|
|
+ Star1 = "★";
|
|
|
+ Star2 = "★";
|
|
|
+ Star3 = "★";
|
|
|
+ Star4 = "★";
|
|
|
+ Star5 = "☆";
|
|
|
+ starCount = 4;
|
|
|
+ }
|
|
|
+ public async Task SelectStar5()
|
|
|
+ {
|
|
|
+ Star1 = "★";
|
|
|
+ Star2 = "★";
|
|
|
+ Star3 = "★";
|
|
|
+ Star4 = "★";
|
|
|
+ Star5 = "★";
|
|
|
+ starCount = 5;
|
|
|
+ }
|
|
|
+ public async Task SelectStar0()
|
|
|
+ {
|
|
|
+ Star1 = "☆";
|
|
|
+ Star2 = "☆";
|
|
|
+ Star3 = "☆";
|
|
|
+ Star4 = "☆";
|
|
|
+ Star5 = "☆";
|
|
|
+ starCount = 0;
|
|
|
+ }
|
|
|
+ public async Task SaveCard()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Country c = MainWindowViewModel.myConnection.Countries.FirstOrDefault(x => x.Name == select);
|
|
|
+ if (!state)
|
|
|
+ {
|
|
|
+ int h = MainWindowViewModel.myConnection.Hotels.OrderBy(x => x.Id).Last().Id + 1;
|
|
|
+ if (TitleHotel.Length > 0)
|
|
|
+ {
|
|
|
+ Hotel newHotel = new Hotel()
|
|
|
+ {
|
|
|
+ Id = MainWindowViewModel.myConnection.Hotels.OrderBy(x => x.Id).Last().Id + 1,
|
|
|
+ Name = TitleHotel,
|
|
|
+ Description = DescriptionHotel,
|
|
|
+ CountOfStars = starCount,
|
|
|
+ CountryCode = c.Code
|
|
|
+ };
|
|
|
+ MainWindowViewModel.myConnection.Hotels.Add(newHotel);
|
|
|
+ MainWindowViewModel.myConnection.SaveChanges();
|
|
|
+ Message = "Отель добавлен";
|
|
|
+ }
|
|
|
+ else Message = "Отель не добавлен. Укажите название";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (TitleHotel.Length > 0)
|
|
|
+ {
|
|
|
+ hotelEdit.Name = TitleHotel;
|
|
|
+ hotelEdit.Description = DescriptionHotel;
|
|
|
+ hotelEdit.CountOfStars = starCount;
|
|
|
+ hotelEdit.CountryCode = c.Code;
|
|
|
+ MainWindowViewModel.myConnection.SaveChanges();
|
|
|
+ Message = "Данные изменены";
|
|
|
+ }
|
|
|
+ else Message = "Отель не изменен. Укажите название";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ Message = "Не удалось добавить отель";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|