using System; using System.Linq; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; using GazpromApp.Enums; using GazpromApp.Messages; using GazpromApp.Models; namespace GazpromApp.ViewModels; public partial class InspectionViewModel : ViewModelBase { private Inspection Inspection { get; } [ObservableProperty] private string _name; [ObservableProperty] private DateTime _creationDate; [ObservableProperty] private DateTimeOffset _inspectionDate; [ObservableProperty] private PeriodType _periodType; [ObservableProperty] private float _periodValue; // Visual properties [ObservableProperty] private bool _isEditing; [RelayCommand] private void EditInspection() { IsEditing = !IsEditing; } [RelayCommand] private void RemoveInspection() => WeakReferenceMessenger.Default.Send(new RemoveInspectionMessage(this)); // ReSharper disable once MemberCanBeMadeStatic.Global public PeriodType[] AllPeriods => Enum.GetValues() .Where(p => p != PeriodType.Unknown) .ToArray(); public InspectionViewModel() { Name = string.Empty; CreationDate = DateTime.Now; InspectionDate = DateTimeOffset.Now; PeriodType = 0; PeriodValue = 1; Inspection = new Inspection(); } public InspectionViewModel(Inspection inspection) { Name = inspection.Name; CreationDate = inspection.CreationDate; InspectionDate = inspection.InspectionDate; PeriodType = inspection.PeriodType.ToPeriodType(); PeriodValue = inspection.PeriodValue; Inspection = inspection; } public Inspection GetInspection() { Inspection.Name = Name; Inspection.CreationDate = CreationDate; Inspection.InspectionDate = InspectionDate; Inspection.PeriodType = PeriodType.ToDescription(); Inspection.PeriodValue = PeriodValue; return Inspection; } }