|
@@ -23,23 +23,34 @@ namespace AvaloniaApplication1.ViewModels
|
|
|
Smeshariki smesh;
|
|
|
List<Gender> genders;
|
|
|
Bitmap imageSmesh;
|
|
|
+ List<Property> property;
|
|
|
+ List<Property> property2;
|
|
|
+ Property selectedProperty;
|
|
|
public ICommand DeleteItemCommand { get; }
|
|
|
- public ObservableCollection<Property> Properties { get; } = new ObservableCollection<Property>();
|
|
|
+ public ObservableCollection<Property> Properties { get; }
|
|
|
public Smeshariki Smesh { get => smesh; set => this.RaiseAndSetIfChanged(ref smesh, value); }
|
|
|
public List<Gender> Genders { get => genders; set => this.RaiseAndSetIfChanged(ref genders, value); }
|
|
|
public Gender selectedGender;
|
|
|
public Gender SelectedGender { get => selectedGender; set => this.RaiseAndSetIfChanged(ref selectedGender, value); }
|
|
|
public Bitmap ImageSmesh { get => imageSmesh; set => this.RaiseAndSetIfChanged(ref imageSmesh, value); }
|
|
|
+ public List<Property> Property { get => property; set => this.RaiseAndSetIfChanged(ref property, value); }
|
|
|
+ public List<Property> Property2 { get => property2; set => this.RaiseAndSetIfChanged(ref property2, value); }
|
|
|
+ public Property SelectedProperty { get => selectedProperty; set { selectedProperty = value; AddNewItem(); } }
|
|
|
public UpdateSmesharikViewModel(int id)
|
|
|
{
|
|
|
Genders = myConnection.Genders.ToList();
|
|
|
smesh = myConnection.Smesharikis.Include(x => x.GenderNavigation).Include(x=> x.IdProperties).FirstOrDefault(x=> x.Id ==id);
|
|
|
imageSmesh = Smesh.Image != null ? new Bitmap(new MemoryStream(smesh.Image)) : new Bitmap("çàãëóøêà.png");
|
|
|
-
|
|
|
+ Properties = new ObservableCollection<Property>(smesh.IdProperties);
|
|
|
+ property2 = myConnection.Properties.ToList();
|
|
|
+ property = property2.Except(Properties).ToList();
|
|
|
}
|
|
|
|
|
|
public void Save()
|
|
|
{
|
|
|
+
|
|
|
+ smesh.IdProperties = Properties.ToList();
|
|
|
+
|
|
|
myConnection.SaveChanges();
|
|
|
MainWindowViewModel.Self.Uc = new AdminPage();
|
|
|
}
|
|
@@ -67,6 +78,20 @@ namespace AvaloniaApplication1.ViewModels
|
|
|
|
|
|
public void Back() => MainWindowViewModel.Self.Uc = new AdminPage();
|
|
|
|
|
|
+ public async void AddNewItem()
|
|
|
+ {
|
|
|
+ var newItem = SelectedProperty;
|
|
|
+ await Dispatcher.UIThread.InvokeAsync(() =>
|
|
|
+ {
|
|
|
+ if (newItem != null)
|
|
|
+ {
|
|
|
+ Properties.Add(newItem);
|
|
|
+ Property = Property.Except(Properties).ToList();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public async void DeleteProperty(int id)
|
|
|
{
|
|
|
var newItem = await myConnection.Properties.FirstOrDefaultAsync(x=> x.Id == id);
|
|
@@ -74,7 +99,9 @@ namespace AvaloniaApplication1.ViewModels
|
|
|
{
|
|
|
if (newItem != null)
|
|
|
{
|
|
|
- Smesh.IdProperties.Remove(newItem);
|
|
|
+ Properties.Remove(newItem);
|
|
|
+ Property = Property2;
|
|
|
+ Property = Property.Except(Properties).ToList();
|
|
|
}
|
|
|
});
|
|
|
}
|