Adding equipment works
This commit is contained in:
@@ -12,6 +12,7 @@ using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
using GazpromApp.Views;
|
||||
using Image = GazpromApp.Models.Image;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
@@ -75,6 +76,34 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
{
|
||||
_ = await WeakReferenceMessenger.Default.Send(new ViewImageMessage(image));
|
||||
}
|
||||
|
||||
public ObservableCollection<EquipmentViewModel> Equipment { get; set; }
|
||||
|
||||
[RelayCommand]
|
||||
private async Task AddEquipment()
|
||||
{
|
||||
EquipmentViewModel? equipment = await WeakReferenceMessenger.Default.Send(new NewEquipmentMessage());
|
||||
|
||||
if (equipment != null)
|
||||
Equipment.Add(equipment);
|
||||
|
||||
IsEquipmentEmpty = Equipment.Count == 0;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task EditEquipment(EquipmentViewModel equipment)
|
||||
{
|
||||
EquipmentViewModel e = await WeakReferenceMessenger.Default.Send(new EditEquipmentMessage(equipment)) ?? equipment;
|
||||
Equipment[Equipment.IndexOf(equipment)] = e;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void DeleteEquipment(EquipmentViewModel equipment)
|
||||
{
|
||||
Equipment.Remove(equipment);
|
||||
|
||||
IsEquipmentEmpty = Equipment.Count == 0;
|
||||
}
|
||||
|
||||
private bool CanCompleteEdit() => !string.IsNullOrWhiteSpace(Name);
|
||||
|
||||
@@ -86,7 +115,8 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
{
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Images = Images.Select(e => e.GetImage()).ToList()
|
||||
Images = Images.Select(e => e.GetImage()).ToList(),
|
||||
Equipment = Equipment.Select(e => e.GetEquipment()).ToList()
|
||||
};
|
||||
WeakReferenceMessenger.Default.Send(new EditPointDone(new PointViewModel(point)));
|
||||
}
|
||||
@@ -104,7 +134,7 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
private bool _isImagesEmpty;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isEquipmentEmpty = true;
|
||||
private bool _isEquipmentEmpty;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isClosed;
|
||||
@@ -116,7 +146,21 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
Name = "";
|
||||
Description = "";
|
||||
Images = [];
|
||||
Equipment = [
|
||||
new EquipmentViewModel
|
||||
{
|
||||
Name = "Equipment Name Very Long",
|
||||
Description = "Really big description for the equipment to show the long textReally big description for the equipment to show the long textReally big description for the equipment to show the long textReally big description for the equipment to show the long text", Image = null
|
||||
},
|
||||
new EquipmentViewModel
|
||||
{
|
||||
Name = "Equipment Name Very Long",
|
||||
Description = "Really big description for the equipment to show the long textReally big description for the equipment to show the long textReally big description for the equipment to show the long textReally big description for the equipment to show the long text", Image = null
|
||||
}
|
||||
];
|
||||
|
||||
IsImagesEmpty = true;
|
||||
IsEquipmentEmpty = true;
|
||||
|
||||
_point = new PointViewModel(new Point());
|
||||
}
|
||||
@@ -126,11 +170,10 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
Name = point.Name;
|
||||
Description = point.Description;
|
||||
Images = new ObservableCollection<ImageViewModel>((point.Images ?? []).Select(e => new ImageViewModel(e)));
|
||||
foreach (ImageViewModel imageViewModel in Images)
|
||||
{
|
||||
Debug.WriteLine(imageViewModel.FileName);
|
||||
}
|
||||
Equipment = new ObservableCollection<EquipmentViewModel>((point.Equipment ?? []).Select(e => new EquipmentViewModel(e)));
|
||||
|
||||
IsImagesEmpty = Images.Count == 0;
|
||||
IsEquipmentEmpty = Equipment.Count == 0;
|
||||
|
||||
_point = point;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user