Inspections added
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Avalonia.Media.Imaging;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using GazpromApp.Models;
|
||||
using GazpromApp.Utils;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
@@ -33,7 +33,7 @@ public partial class EquipmentViewModel : ViewModelBase
|
||||
Image = null;
|
||||
Properties = [];
|
||||
Inspections = [];
|
||||
NearestInspection = DateTime.Now.ToLongDateString();
|
||||
NearestInspection = "Нету инспекций";
|
||||
}
|
||||
|
||||
public EquipmentViewModel(Equipment equipment)
|
||||
@@ -42,8 +42,22 @@ public partial class EquipmentViewModel : ViewModelBase
|
||||
Description = equipment.Description;
|
||||
Image = new ImageViewModel(equipment.Image ?? new Image());
|
||||
Properties = new ObservableCollection<PropertyViewModel>(equipment.Properties.Select(e => new PropertyViewModel(e)));
|
||||
Inspections = new ObservableCollection<InspectionViewModel>(equipment.Inspections.Select(e => new InspectionViewModel(e)));
|
||||
NearestInspection = DateTime.Now.ToLongDateString();
|
||||
|
||||
List<DateTime[]> times = (equipment.Inspections.Select(e => new InspectionViewModel(e)))
|
||||
.Select(e => e.GetNearestDates())
|
||||
.ToList();
|
||||
|
||||
Inspections = new ObservableCollection<InspectionViewModel>(equipment.Inspections
|
||||
.Select((e, i) => new InspectionViewModel(e) { InspectionDate = times[i][0] }));
|
||||
|
||||
NearestInspection = times
|
||||
.Where(e => e[1] > DateTime.Now)
|
||||
.Select(e => e[1])
|
||||
.OrderBy(e => e)
|
||||
.FirstOrDefault()
|
||||
.ToLongDateString();
|
||||
|
||||
if (Inspections.Count == 0) NearestInspection = "Нету инспекций";
|
||||
}
|
||||
|
||||
public Equipment GetEquipment()
|
||||
@@ -53,6 +67,7 @@ public partial class EquipmentViewModel : ViewModelBase
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Image = Image?.GetImage(),
|
||||
Inspections = Inspections.Select(e => e.GetInspection()).ToList(),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user