Пример #1
0
        public void RemoveItem(long idItem, dtoEditAssignment assignment, List <dtoEditAssignment> assignments)
        {
            if (!SessionTimeout())
            {
                liteRepositoryItem item = Service.ItemGet(idItem);
                if (item != null)
                {
                    long permissions = (long)((item.AllowUpload) ? ModuleRepository.Base2Permission.DownloadOrPlay | ModuleRepository.Base2Permission.Upload : ModuleRepository.Base2Permission.DownloadOrPlay);
                    assignments.Where(a => !a.Denyed && a.Permissions == 0).ToList().ForEach(a => a.Permissions = permissions);
                    switch (assignment.Type)
                    {
                    case AssignmentType.community:
                        if (!assignments.Any(a => a.IdPerson == UserContext.CurrentUserID))
                        {
                            assignments.Add(new dtoEditAssignment()
                            {
                                Id = 0, IdPerson = UserContext.CurrentUserID, CreatedOn = DateTime.Now, Permissions = permissions, Type = AssignmentType.person
                            });
                        }
                        break;

                    case AssignmentType.person:
                        break;

                    case AssignmentType.role:
                        break;
                    }
                    View.HasPendingChanges = true;
                }
                assignments = assignments.Where(a => !a.Equals(assignment)).ToList();
                InitializeSelectors(item.Repository, assignments.Where(a => !a.IsDeleted && a.IdRole > 0).Select(a => a.IdRole).ToList(), assignments.Where(a => !a.IsDeleted && a.IdPerson > 0).Select(a => a.IdPerson).ToList());
            }
        }
Пример #2
0
        public void LoadAssignments(Boolean editMode, long idItem, Dictionary <AssignmentType, String> tTranslations, Dictionary <PermissionsTranslation, String> translations, Dictionary <ModuleRepository.Base2Permission, String> pTranslations, List <dtoEditAssignment> assignments = null)
        {
            RepositoryIdentifier identifier = Service.ItemGetRepositoryIdentifier(idItem);

            if (identifier != null)
            {
                List <dtoEditAssignment> items = Service.ItemGetAssignmentsForEditing(idItem, tTranslations, translations, pTranslations);
                if (assignments != null && items != null)
                {
                    foreach (dtoEditAssignment i in items.Where(x => !x.Inherited && assignments.Any(a => a.Id == x.Id && a.Type == x.Type && a.Denyed != x.Denyed)))
                    {
                        i.Denyed = assignments.Any(a => a.Id == i.Id && a.Denyed);
                    }

                    foreach (dtoEditAssignment nItem in items.Where(i => !i.Inherited && !assignments.Any(a => a.Id == i.Id)))
                    {
                        switch (nItem.Type)
                        {
                        case AssignmentType.community:
                            dtoEditAssignment vItem = assignments.Where(a => a.Type == nItem.Type).FirstOrDefault();
                            if (vItem != null && !vItem.Denyed && nItem.Denyed)
                            {
                                nItem.Denyed = false;
                            }
                            assignments = assignments.Where(a => a.Type != AssignmentType.community).ToList();
                            break;

                        case AssignmentType.person:
                            dtoEditAssignment pItem = assignments.Where(a => a.Type == nItem.Type && a.IdPerson == nItem.IdPerson).FirstOrDefault();
                            if (pItem != null && !pItem.Denyed && nItem.Denyed)
                            {
                                nItem.Denyed = false;
                            }
                            assignments = assignments.Where(a => a.Type != nItem.Type && a.IdPerson != nItem.IdPerson).ToList();
                            break;

                        case AssignmentType.role:
                            dtoEditAssignment rItem = assignments.Where(a => a.Type == nItem.Type && a.IdRole == nItem.IdRole).FirstOrDefault();
                            if (rItem != null && !rItem.Denyed && nItem.Denyed)
                            {
                                nItem.Denyed = false;
                            }
                            assignments = assignments.Where(a => a.Type != nItem.Type && a.IdRole != nItem.IdRole).ToList();
                            break;
                        }
                    }

                    assignments.AddRange(items.Where(i => !assignments.Any(a => a.Id == i.Id)).ToList());
                    assignments = assignments.OrderBy(a => a.OrderByInherited()).ThenBy(a => a.OrderByType()).ThenBy(a => a.DisplayName).ToList();
                    InitializeSelectors(identifier, assignments.Select(i => i.IdRole).ToList(), assignments.Where(a => a.IdPerson > 0).Select(i => i.IdPerson).ToList());
                    View.LoadAssignments(assignments);
                }
                else if (items != null)
                {
                    InitializeSelectors(identifier, items.Select(i => i.IdRole).ToList(), items.Where(a => a.IdPerson > 0).Select(i => i.IdPerson).ToList());
                    View.LoadAssignments(items.OrderBy(a => a.OrderByInherited()).ThenBy(a => a.OrderByType()).ThenBy(a => a.DisplayName).ToList());
                }
            }
        }