From 1fbf8b8fa6bdfca2ce83dc90cc82fb155170c586 Mon Sep 17 00:00:00 2001 From: "David P.G" Date: Fri, 13 Jun 2025 19:15:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=B7=BB=E5=8A=A0=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=AE=8C=E6=88=90=E5=90=8E=EF=BC=8C=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E7=9A=84=E5=88=B7=E6=96=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ViewModels/DevicesViewModel.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ViewModels/DevicesViewModel.cs b/ViewModels/DevicesViewModel.cs index 4c92518..8a95d02 100644 --- a/ViewModels/DevicesViewModel.cs +++ b/ViewModels/DevicesViewModel.cs @@ -24,19 +24,25 @@ public partial class DevicesViewModel : ViewModelBase { _deviceDialogService = deviceDialogService; _devicesRepositories = devicesRepositories; + _devices = new ObservableCollection(); } public async Task OnLoadedAsync() { var ds = await _devicesRepositories.GetAll(); - _devices = new ObservableCollection(); - + foreach (var dbDevice in ds) { - Device device = new Device(); - dbDevice.CopyTo(device); - _devices.Add(device); + var deviceExist= _devices.FirstOrDefault(d => d.Id == dbDevice.Id); + if (deviceExist == null) + { + Device device = new Device(); + dbDevice.CopyTo(device); + _devices.Add(device); + } + } + } @@ -54,7 +60,8 @@ public partial class DevicesViewModel : ViewModelBase var rowCount= await _devicesRepositories.Add(dbDevice); if (rowCount>0) { - MessageBox.Show("Device added successfully"); + // MessageBox.Show("Device added successfully"); + await OnLoadedAsync(); } }