using System; using System.Collections.ObjectModel; using System.IO; using System.Linq; using Avalonia.Media.Imaging; using CommunityToolkit.Mvvm.ComponentModel; using GazpromApp.Models; namespace GazpromApp.ViewModels; public partial class EquipmentViewModel : ViewModelBase { [ObservableProperty] private string? _name; [ObservableProperty] private string? _description; [ObservableProperty] private ImageViewModel? _image; public ObservableCollection Properties { get; set; } public ObservableCollection Inspections { get; set; } [ObservableProperty] private string _nearestInspection; public EquipmentViewModel() { Name = string.Empty; Description = string.Empty; Image = null; Properties = []; Inspections = []; NearestInspection = DateTime.Now.ToLongDateString(); } public EquipmentViewModel(Equipment equipment) { Name = equipment.Name; Description = equipment.Description; Image = new ImageViewModel(equipment.Image ?? new Image()); Properties = new ObservableCollection(equipment.Properties.Select(e => new PropertyViewModel(e))); Inspections = new ObservableCollection(equipment.Inspections.Select(e => new InspectionViewModel(e))); NearestInspection = DateTime.Now.ToLongDateString(); } public Equipment GetEquipment() { return new Equipment() { Name = Name, Description = Description, Image = Image?.GetImage(), }; } }