2025-06-12 18:41:46 +08:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
|
|
using PMSWPF.Data.Entities;
|
|
|
|
|
|
using PMSWPF.Data.Repositories;
|
|
|
|
|
|
using PMSWPF.Excptions;
|
|
|
|
|
|
using PMSWPF.Extensions;
|
|
|
|
|
|
using PMSWPF.Helper;
|
2025-06-12 13:15:55 +08:00
|
|
|
|
using PMSWPF.Models;
|
|
|
|
|
|
using PMSWPF.Services;
|
|
|
|
|
|
using PMSWPF.ViewModels.Dialogs;
|
|
|
|
|
|
using PMSWPF.Views.Dialogs;
|
2025-06-10 20:55:39 +08:00
|
|
|
|
|
2025-06-12 13:15:55 +08:00
|
|
|
|
namespace PMSWPF.ViewModels;
|
|
|
|
|
|
|
|
|
|
|
|
public partial class DevicesViewModel : ViewModelBase
|
2025-06-10 20:55:39 +08:00
|
|
|
|
{
|
2025-06-12 13:15:55 +08:00
|
|
|
|
private readonly IDeviceDialogService _deviceDialogService;
|
2025-06-12 18:41:46 +08:00
|
|
|
|
private readonly DevicesRepositories _devicesRepositories;
|
2025-06-12 13:15:55 +08:00
|
|
|
|
|
2025-06-12 18:41:46 +08:00
|
|
|
|
public DevicesViewModel(IDeviceDialogService deviceDialogService,DevicesRepositories devicesRepositories)
|
2025-06-12 13:15:55 +08:00
|
|
|
|
{
|
|
|
|
|
|
_deviceDialogService = deviceDialogService;
|
2025-06-12 18:41:46 +08:00
|
|
|
|
_devicesRepositories = devicesRepositories;
|
2025-06-12 13:15:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[RelayCommand]
|
|
|
|
|
|
public async void AddDevice()
|
2025-06-10 22:13:06 +08:00
|
|
|
|
{
|
2025-06-12 18:41:46 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2025-06-12 18:56:25 +08:00
|
|
|
|
|
|
|
|
|
|
Device device= await _deviceDialogService.ShowAddDeviceDialog();
|
|
|
|
|
|
if (device != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
DbDevice dbDevice = new DbDevice();
|
|
|
|
|
|
device.CopyTo<DbDevice>(dbDevice);
|
|
|
|
|
|
await _devicesRepositories.Add(dbDevice);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-12 18:41:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (DbExistException e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(e);
|
|
|
|
|
|
MessageBox.Show(e.Message);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(e);
|
|
|
|
|
|
MessageBox.Show(e.Message);
|
|
|
|
|
|
}
|
2025-06-10 22:13:06 +08:00
|
|
|
|
}
|
2025-06-10 20:55:39 +08:00
|
|
|
|
}
|