Removed dialogs for editing equipment and points, and their related resources
This commit is contained in:
@@ -1,31 +1,49 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Media.Imaging;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
|
||||
public partial class ImageViewModel : ViewModelBase
|
||||
{
|
||||
public ViewModelBase? Parent;
|
||||
private Image Image { get; }
|
||||
|
||||
[ObservableProperty]
|
||||
private byte[]? _bytes;
|
||||
|
||||
|
||||
[ObservableProperty] private byte[]? _bytes;
|
||||
|
||||
[ObservableProperty] private DateTime _creationDate;
|
||||
|
||||
// EF stuff
|
||||
|
||||
[ObservableProperty]
|
||||
private Point? _point;
|
||||
|
||||
[ObservableProperty]
|
||||
private Equipment? _equipment;
|
||||
|
||||
[ObservableProperty]
|
||||
private Bitmap? _fileName;
|
||||
|
||||
[ObservableProperty] private Point? _point;
|
||||
|
||||
[ObservableProperty] private Equipment? _equipment;
|
||||
|
||||
[ObservableProperty] private Bitmap? _fileName;
|
||||
|
||||
[RelayCommand]
|
||||
private async Task ViewImage() => _ = await WeakReferenceMessenger.Default.Send(new ViewImageMessage(this));
|
||||
|
||||
[RelayCommand]
|
||||
private void DeleteImage() => _ = Parent switch
|
||||
{
|
||||
PointViewModel pmv => pmv.Images.Remove(this),
|
||||
EquipmentViewModel emv => emv.Images.Remove(this),
|
||||
EditPointViewModel editPointViewModel => editPointViewModel.Images.Remove(this),
|
||||
EditEquipmentViewModel editEquipmentViewModel => editEquipmentViewModel.Images.Remove(this),
|
||||
_ => false
|
||||
};
|
||||
|
||||
public ImageViewModel(Image image)
|
||||
{
|
||||
Bytes = image.Bytes;
|
||||
CreationDate = image.CreationDate;
|
||||
Equipment = image.Equipment;
|
||||
Point = image.Point;
|
||||
FileName = image.Bytes is { Length: > 0 } ? new Bitmap(new MemoryStream(image.Bytes)) : null;
|
||||
@@ -35,6 +53,7 @@ public partial class ImageViewModel : ViewModelBase
|
||||
public ImageViewModel()
|
||||
{
|
||||
Bytes = null;
|
||||
CreationDate = DateTime.Now;
|
||||
Equipment = null;
|
||||
Point = null;
|
||||
Image = new Image();
|
||||
@@ -45,6 +64,7 @@ public partial class ImageViewModel : ViewModelBase
|
||||
var ms = new MemoryStream();
|
||||
FileName?.Save(ms);
|
||||
Image.Bytes = ms.ToArray();
|
||||
Image.CreationDate = CreationDate;
|
||||
Image.Equipment = Equipment;
|
||||
Image.Point = Point;
|
||||
return Image;
|
||||
|
||||
Reference in New Issue
Block a user