コード例 #1
0
        private async void ButtonAddDevice_OnClick(object sender, RoutedEventArgs e)
        {
            var group = GroupsDataGrid.SelectedItem as Group;

            if (group == null)
            {
                return;
            }

            var deviceWindow = new DeviceMultiselectWindow(new ZvsEntityContextConnection(), group.Devices.Select(o => o.Id).ToList())
            {
                Owner = Window.GetWindow(this)
            };
            var result = deviceWindow.ShowDialog();

            if (!result.HasValue || !result.Value)
            {
                return;
            }

            var selectDeviceIds = deviceWindow.SelectedDevices.Select(o => o.Id);
            var devicesToAdd    = await Context.Devices.Where(o => selectDeviceIds.Contains(o.Id) && o.Groups.All(p => p.Id != group.Id)).ToListAsync();

            foreach (var device in devicesToAdd)
            {
                group.Devices.Add(device);
            }
            await SaveChangesAsync();
        }
コード例 #2
0
        private async void ButtonAddDevice_OnClick(object sender, RoutedEventArgs e)
        {
            var group = GroupsDataGrid.SelectedItem as Group;
            if (group == null) return;

            var deviceWindow = new DeviceMultiselectWindow(new ZvsEntityContextConnection(), group.Devices.Select(o => o.Id).ToList())
            {
                Owner = Window.GetWindow(this)
            };
            var result = deviceWindow.ShowDialog();
            if (!result.HasValue || !result.Value) return;

            var selectDeviceIds = deviceWindow.SelectedDevices.Select(o => o.Id);
            var devicesToAdd = await Context.Devices.Where(o => selectDeviceIds.Contains(o.Id) && o.Groups.All(p => p.Id != group.Id)).ToListAsync();

            foreach (var device in devicesToAdd)
            {
                group.Devices.Add(device);
            }
            await SaveChangesAsync();
        }