public void DissociateAll(CheckPointByRoleResource checkByRoleResource)
 {
     try
     {
         var parent      = (RoleCollectionViewModel)this.GetParentViewModel <CheckpointViewModel>().ParentViewModel;
         var checkPoints = new CheckpointByRole
         {
             RoleId       = checkByRoleResource.IdRole,
             CheckpointId = checkByRoleResource.Id,
             Id           = checkByRoleResource.CheckpointByRoleId
         };
         foreach (var item in parent.Entities.Where(y => y.Id == checkByRoleResource.IdRole))
         {
             var listChecks = item.CheckpointByRole.ToList();
             listChecks.RemoveAll(y => y.RoleId == checkByRoleResource.IdRole && y.CheckpointId == checkByRoleResource.Id);
             item.CheckpointByRole = listChecks;
         }
         parent.Save(parent.SelectedEntity);
         parent.SendRefreshCollectionsMessage();
     }
     catch (Exception ex)
     {
         MessageBoxService.ShowMessage(GetStringValue(Next.Enums.Enums.MessageError.SaveError) + ex.Message, ex.Message,
                                       MessageButton.OK, MessageIcon.Error);
     }
 }
        public void DissociateAll()
        {
            try
            {
                if (SelectedEntity == null)
                {
                    return;
                }
                var list = new ObservableCollection <CheckPointByRoleResource>();

                if (SelectedEntity.CheckpointByRole == null)
                {
                    SelectedEntity.CheckpointByRole = new ObservableCollection <CheckpointByRole>();
                }

                foreach (var item in Checks)
                {
                    if (SelectedEntity.CheckpointByRole == null)
                    {
                        break;
                    }
                    var existingCheckByRole = SelectedEntity.CheckpointByRole.Where(x => x.CheckpointId == item.Id).FirstOrDefault();
                    var resource            = new CheckPointByRoleResource
                    {
                        DisplayName        = item.DisplayName,
                        Group              = item.Group,
                        Type               = item.Type,
                        Id                 = item.Id,
                        ParentId           = item.ParentId,
                        IdRole             = SelectedEntity.Id,
                        Selected           = false,
                        CheckpointByRoleId = existingCheckByRole != null ? existingCheckByRole.Id : new int()
                    };
                    list.Add(resource);
                    SelectedRoleCheckpointViewModel.DissociateAll(resource);
                }
            }
            catch (Exception ex)
            {
                MessageBoxService.ShowMessage(GetStringValue(Next.Enums.Enums.MessageError.DataError) + ex.Message, ex.Message,
                                              MessageButton.OK, MessageIcon.Error);
            }
        }
 protected void LoadCheckpointsByroles()
 {
     try
     {
         if (SelectedEntity == null)
         {
             return;
         }
         else
         {
             if (SelectedEntity.CheckpointByRole != null)
             {
                 var list = new ObservableCollection <CheckPointByRoleResource>();
                 foreach (var item in Checks)
                 {
                     var existingCheckByRole = SelectedEntity.CheckpointByRole.Where(x => x.CheckpointId == item.Id).FirstOrDefault();
                     var resource            = new CheckPointByRoleResource
                     {
                         DisplayName        = item.DisplayName,
                         Group              = item.Group,
                         Type               = item.Type,
                         Id                 = item.Id,
                         ParentId           = item.ParentId,
                         IdRole             = SelectedEntity.Id,
                         Selected           = existingCheckByRole != null,
                         CheckpointByRoleId = existingCheckByRole != null ? existingCheckByRole.Id : new int()
                     };
                     list.Add(resource);
                 }
                 SelectedRoleCheckpointViewModel.CheckPointAssignedToRole = list;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBoxService.ShowMessage(GetStringValue(Next.Enums.Enums.MessageError.DataError) + ex.Message, ex.Message,
                                       MessageButton.OK, MessageIcon.Error);
     }
 }