From 18e79aebd6cb8269b31520ddbc93aaf0aa4b4591 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Sun, 17 Jan 2021 12:36:39 +0200 Subject: MS. Display the proper error message when trying to delete Organization. Item 4510. --- .../ViewModels/MainViewVM.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs index 16395d6bc..75e4af225 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs @@ -205,6 +205,28 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels { if (_notification.ShowQuestion("Are you sure you want to remove " + SelectedOrganization.Name + " organization?")) { + Organization selectedToRemoveOrganization = null; + await Task.Factory.StartNew(() => + { + _manageContext = ObservablesContext.CreateDefault(); + selectedToRemoveOrganization = new OrganizationBuilder(_manageContext).Set(SelectedOrganization.Guid).WithUsers(true).WithMachines().WithSites().Build(); + }); + if (selectedToRemoveOrganization != null && selectedToRemoveOrganization.Machines.Count > 0) + { + _notification.ShowError("The organization cannot be removed as it contains Machines."); + return; + } + if (selectedToRemoveOrganization != null && selectedToRemoveOrganization.Sites.Count > 0) + { + _notification.ShowError("The organization cannot be removed as it contains Sites."); + return; + } + if (selectedToRemoveOrganization != null && selectedToRemoveOrganization.Users.Count(x => x.OrganizationGuid == SelectedOrganization.Guid && x.Deleted == false) > 0) + { + _notification.ShowError("The organization cannot be removed as it contains active users."); + return; + } + using (_notification.PushTaskItem("Removing organization...")) { await SelectedOrganization.DeleteCascadeAsync(_organizationsContext); -- cgit v1.3.1