Removed dialogs for editing equipment and points, and their related resources
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
@@ -14,39 +21,64 @@ public partial class PointViewModel : ViewModelBase
|
||||
[ObservableProperty]
|
||||
private string? _description;
|
||||
|
||||
[ObservableProperty]
|
||||
private DateTime _creationDate;
|
||||
|
||||
[ObservableProperty]
|
||||
private double? _latitude;
|
||||
|
||||
[ObservableProperty]
|
||||
private double? _longitude;
|
||||
|
||||
[RelayCommand]
|
||||
private void AddEquipment()
|
||||
{
|
||||
Equipment.Add(new EquipmentViewModel(new Equipment()) {Name = "Новое оборудование", Description = "Описание оборудования", Parent = this});
|
||||
WeakReferenceMessenger.Default.Send(new EditPointMessage(this));
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void RemovePoint()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Send(new RemovePointMessage(this));
|
||||
}
|
||||
|
||||
private void RemoveEquipment(object sender, RemoveEquipmentMessage msg)
|
||||
{
|
||||
if (msg.Equipment.GetEquipment().Point == GetPoint())
|
||||
Equipment.Remove(msg.Equipment);
|
||||
}
|
||||
|
||||
// EF stuff
|
||||
[ObservableProperty]
|
||||
private List<Image> _images;
|
||||
private ObservableCollection<ImageViewModel> _images;
|
||||
[ObservableProperty]
|
||||
private List<Equipment> _equipment;
|
||||
private ObservableCollection<EquipmentViewModel> _equipment;
|
||||
[ObservableProperty]
|
||||
private List<Property> _properties;
|
||||
private ObservableCollection<PropertyViewModel> _properties;
|
||||
|
||||
public PointViewModel(Point point)
|
||||
{
|
||||
Point = point;
|
||||
Name = point.Name;
|
||||
CreationDate = point.CreationDate;
|
||||
Description = point.Description;
|
||||
Latitude = point.Latitude;
|
||||
Longitude = point.Longitude;
|
||||
Images = point.Images;
|
||||
Equipment = point.Equipment;
|
||||
Properties = point.Properties;
|
||||
Images = new ObservableCollection<ImageViewModel>(point.Images.Select(i => new ImageViewModel(i)));
|
||||
Equipment = new ObservableCollection<EquipmentViewModel>(point.Equipment.Select(i => new EquipmentViewModel(i){Parent = this}));
|
||||
Properties = new ObservableCollection<PropertyViewModel>(point.Properties.Select(i => new PropertyViewModel(i)));
|
||||
|
||||
WeakReferenceMessenger.Default.Register<RemoveEquipmentMessage>(this, RemoveEquipment);
|
||||
}
|
||||
|
||||
public Point GetPoint()
|
||||
{
|
||||
Point.Name = Name;
|
||||
Point.Description = Description;
|
||||
Point.Equipment = Equipment;
|
||||
Point.Images = Images;
|
||||
Point.Properties = Properties;
|
||||
Point.CreationDate = CreationDate;
|
||||
Point.Equipment = Equipment.Select(e => e.GetEquipment()).ToList();
|
||||
Point.Images = Images.Select(i => i.GetImage()).ToList();
|
||||
Point.Properties = Properties.Select(p => p.GetProperty()).ToList();
|
||||
return Point;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user