|
@@ -0,0 +1,71 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using AvaloniaApplicationBase.Models;
|
|
|
+using AvaloniaApplicationBase.Views;
|
|
|
+using ReactiveUI;
|
|
|
+
|
|
|
+namespace AvaloniaApplicationBase.ViewModels
|
|
|
+{
|
|
|
+ public class AddCatPageViewModel : ReactiveObject
|
|
|
+ {
|
|
|
+ string name = "";
|
|
|
+ DateTime date = DateTime.Now;
|
|
|
+ int gender = -1;
|
|
|
+ List<string> selectedTraits = new List<string>();
|
|
|
+
|
|
|
+ public string Name { get => name; set => name = value; }
|
|
|
+ public string Date { get => date.ToString(); set => date = DateTime.Parse(value); }
|
|
|
+ public int Gender { get => gender; set => gender = value; }
|
|
|
+
|
|
|
+ public List<string> NewTraits
|
|
|
+ {
|
|
|
+ get => MainWindowViewModel.myConnection.TraitTables.Select(x => x.Trait).ToList();
|
|
|
+ }
|
|
|
+ public List<string> SelectedTraits
|
|
|
+ {
|
|
|
+ get => selectedTraits;
|
|
|
+ set => this.RaiseAndSetIfChanged(ref selectedTraits, value);
|
|
|
+ }
|
|
|
+ public string SelectedTraitCat
|
|
|
+ {
|
|
|
+ get => null;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ selectedTraits.Add(value);
|
|
|
+ SelectedTraits = new List<string>(selectedTraits);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addNewCat()
|
|
|
+ {
|
|
|
+ CatTable newCat = new CatTable()
|
|
|
+ {
|
|
|
+ Name = name,
|
|
|
+ Date = date,
|
|
|
+ Gender = gender + 1,
|
|
|
+ };
|
|
|
+ MainWindowViewModel.myConnection.CatTables.Add(newCat);
|
|
|
+ MainWindowViewModel.myConnection.SaveChanges();
|
|
|
+
|
|
|
+ foreach (string item in selectedTraits)
|
|
|
+ {
|
|
|
+ TraitTable tc = MainWindowViewModel.myConnection.TraitTables.FirstOrDefault(x => x.Trait == item);
|
|
|
+ if (tc != null)
|
|
|
+ {
|
|
|
+ TraitCatTable traitCatTable = new TraitCatTable();
|
|
|
+ traitCatTable.IdCat = newCat.Id;
|
|
|
+ traitCatTable.IdTrait = tc.Id;
|
|
|
+ MainWindowViewModel.myConnection.TraitCatTables.Add(traitCatTable);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ MainWindowViewModel.myConnection.SaveChanges();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|