diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2021-01-20 12:10:43 +0000 |
|---|---|---|
| committer | Roy Ben Shabat <Roy@twine-s.com> | 2021-01-20 12:10:43 +0000 |
| commit | 9aa45ed8258c7b5200cba90d94cc049cf59dc78d (patch) | |
| tree | 6bce77cac6078b6e60f6609319e43f06808ee492 | |
| parent | 4029a2148e82dd34c20057d33ab70f09cb6dce16 (diff) | |
| parent | c536bc430907a15bb5bd4d8c0c1fec0934d5a9c8 (diff) | |
| download | Tango-9aa45ed8258c7b5200cba90d94cc049cf59dc78d.tar.gz Tango-9aa45ed8258c7b5200cba90d94cc049cf59dc78d.zip | |
Merged PR 13: MS. Display the proper error message when trying to delete Organization. Item...
MS. Display the proper error message when trying to delete Organization. Item 4510.
Related work items: #4510
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs | 29 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.BL/Builders/OrganizationBuilder.cs | 1 |
2 files changed, 30 insertions, 0 deletions
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..9143f50a8 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,35 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels { if (_notification.ShowQuestion("Are you sure you want to remove " + SelectedOrganization.Name + " organization?")) { + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + var usersCount = db.Users.Count(x => x.OrganizationGuid == SelectedOrganization.Guid); + + if (usersCount > 0) + { + _notification.ShowError($"The organization cannot be removed as it contains {usersCount} users."); + return; + } + + var machinesCount = db.Machines.Count(x => x.OrganizationGuid == SelectedOrganization.Guid); + + if (machinesCount > 0) + { + _notification.ShowError($"The organization cannot be removed as it contains {machinesCount} machines."); + return; + } + + var sitesCount = db.Sites.Count(x => x.OrganizationGuid == SelectedOrganization.Guid); + + if (sitesCount > 0) + { + _notification.ShowError($"The organization cannot be removed as it contains {sitesCount} sites."); + return; + } + } + + using (_notification.PushTaskItem("Removing organization...")) { await SelectedOrganization.DeleteCascadeAsync(_organizationsContext); diff --git a/Software/Visual_Studio/Tango.BL/Builders/OrganizationBuilder.cs b/Software/Visual_Studio/Tango.BL/Builders/OrganizationBuilder.cs index 3b4dbb28a..81712542f 100644 --- a/Software/Visual_Studio/Tango.BL/Builders/OrganizationBuilder.cs +++ b/Software/Visual_Studio/Tango.BL/Builders/OrganizationBuilder.cs @@ -34,5 +34,6 @@ namespace Tango.BL.Builders .Include(x => x.UsersRoles).ToSynchronizedObservableCollection(); }); } + } } |
