Code clean up
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
@@ -14,7 +12,6 @@ using CommunityToolkit.Mvvm.Messaging;
|
||||
using GazpromApp.Enums;
|
||||
using GazpromApp.Messages;
|
||||
using GazpromApp.Models;
|
||||
using GazpromApp.Views;
|
||||
using Image = GazpromApp.Models.Image;
|
||||
|
||||
namespace GazpromApp.ViewModels;
|
||||
@@ -54,11 +51,11 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
[RelayCommand]
|
||||
private async Task AddImage(Window w)
|
||||
{
|
||||
IReadOnlyList<IStorageFile> files = await w.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions()
|
||||
var files = await w.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||
{
|
||||
AllowMultiple = true,
|
||||
Title = "Выберите одну или несколько картинок",
|
||||
FileTypeFilter = [FilePickerFileTypes.ImageAll],
|
||||
FileTypeFilter = [FilePickerFileTypes.ImageAll]
|
||||
});
|
||||
foreach (var file in files)
|
||||
{
|
||||
@@ -68,11 +65,11 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
Error error = new Error()
|
||||
var error = new Error
|
||||
{
|
||||
Title = "Ошибка обработки картинки",
|
||||
Message = $"Картинка не была добавлена: \"{HttpUtility.UrlDecode(file.Name)}\"",
|
||||
Severity = ErrorSeverity.Error,
|
||||
Severity = ErrorSeverity.Error
|
||||
};
|
||||
_ = await WeakReferenceMessenger.Default.Send(new ErrorMessage(new ErrorViewModel(error)));
|
||||
}
|
||||
@@ -96,7 +93,7 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
[RelayCommand]
|
||||
private async Task AddEquipment()
|
||||
{
|
||||
EquipmentViewModel? equipment = await WeakReferenceMessenger.Default.Send(new NewEquipmentMessage());
|
||||
var equipment = await WeakReferenceMessenger.Default.Send(new NewEquipmentMessage());
|
||||
|
||||
if (equipment != null)
|
||||
Equipment.Add(equipment);
|
||||
@@ -107,7 +104,7 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
[RelayCommand]
|
||||
private async Task EditEquipment(EquipmentViewModel equipment)
|
||||
{
|
||||
EquipmentViewModel e = await WeakReferenceMessenger.Default.Send(new EditEquipmentMessage(equipment)) ?? equipment;
|
||||
var e = await WeakReferenceMessenger.Default.Send(new EditEquipmentMessage(equipment)) ?? equipment;
|
||||
Equipment[Equipment.IndexOf(equipment)] = e;
|
||||
}
|
||||
|
||||
@@ -145,13 +142,13 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
private void CompleteEdit()
|
||||
{
|
||||
IsClosed = true;
|
||||
Point point = new Point()
|
||||
var point = new Point
|
||||
{
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Images = Images.Select(e => e.GetImage()).ToList(),
|
||||
Equipment = Equipment.Select(e => e.GetEquipment()).ToList(),
|
||||
Properties = Properties.Select(e => e.GetProperty()).ToList(),
|
||||
Properties = Properties.Select(e => e.GetProperty()).ToList()
|
||||
};
|
||||
WeakReferenceMessenger.Default.Send(new EditPointDone(new PointViewModel(point)));
|
||||
}
|
||||
@@ -234,8 +231,8 @@ public partial class EditPointDialogViewModel : ViewModelBase
|
||||
Value = "Property Value",
|
||||
Properties = [],
|
||||
Parent = null
|
||||
},
|
||||
],
|
||||
}
|
||||
],
|
||||
Parent = null
|
||||
},
|
||||
new PropertyViewModel
|
||||
|
||||
Reference in New Issue
Block a user