aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/DBViewModels/UsersViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/DBViewModels/UsersViewVM.cs')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/DBViewModels/UsersViewVM.cs75
1 files changed, 75 insertions, 0 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/DBViewModels/UsersViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/DBViewModels/UsersViewVM.cs
new file mode 100644
index 000000000..2bf34ce7a
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/DBViewModels/UsersViewVM.cs
@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.DAL.Observables;
+
+namespace Tango.MachineStudio.UI.ViewModels.DBViewModels
+{
+ public class UsersViewVM : DbTableViewModel<User>
+ {
+ private ObservableCollection<MultiComboVM<Role>> _selectedRoles;
+ public ObservableCollection<MultiComboVM<Role>> SelectedRoles
+ {
+ get { return _selectedRoles; }
+ set { _selectedRoles = value; RaisePropertyChangedAuto(); }
+ }
+
+ public UsersViewVM() : base()
+ {
+ SelectedRoles = new ObservableCollection<MultiComboVM<Role>>();
+ }
+
+ protected override void OnEdit()
+ {
+ SelectedRoles = Adapter.Roles.Select(x => new MultiComboVM<Role>(x, () => RaisePropertyChanged(nameof(SelectedRoles)))).ToObservableCollection();
+
+ foreach (var role in SelectedRoles)
+ {
+ if (SelectedEntity.UsersRoles.ToList().Exists(x => x.Role == role.Entity && !x.Deleted))
+ {
+ role.IsSelected = true;
+ }
+ }
+
+ base.OnEdit();
+ }
+
+ protected override void OnAdd()
+ {
+ SelectedRoles = Adapter.Roles.Select(x => new MultiComboVM<Role>(x, () => RaisePropertyChanged(nameof(SelectedRoles)))).ToObservableCollection();
+
+ base.OnAdd();
+ }
+
+ protected override void OnBeforeEntitySave(DialogOpenMode mode, User user)
+ {
+ base.OnBeforeEntitySave(mode, user);
+
+ foreach (var role in SelectedRoles)
+ {
+ var userRole = user.UsersRoles.SingleOrDefault(x => x.Role == role.Entity);
+
+ if (userRole != null)
+ {
+ userRole.Deleted = !role.IsSelected;
+ }
+ else
+ {
+ if (role.IsSelected)
+ {
+ user.UsersRoles.Add(new UsersRole()
+ {
+ Role = role.Entity,
+ User = user,
+ RoleGuid = role.Entity.Guid,
+ UserGuid = user.Guid
+ });
+ }
+ }
+ }
+ }
+ }
+}