コード例 #1
0
        public void SetTestGroups(int testId, int[] addGroups, int[] remGroups)
        {
            Debug.Assert(testId > 0);

            Provider.TestRoles(TestorUserRole.Administrator, TestorUserRole.Teacher, TestorUserRole.Laboratorian);

            using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString))
            {
                Provider.TestCoreTestsAccess(testId);

                var test = dataContext.CoreTests.Where(c => c.TestId == testId).FirstOrDefault();
                if (test == null)
                {
                    return;
                }
                var ids = (from c in dataContext.GetUserGroupTree(Provider.CurrentUser.UserRole == TestorUserRole.Administrator ||
                                                                  Provider.CurrentUser.UserRole == TestorUserRole.Anonymous ? 0 : Provider.CurrentUser.UserId,
                                                                  null, true, null)
                           select c.GroupId).ToArray();
                var aGroups = addGroups.Where(c => ids.Contains(c));
                var rGroups = remGroups.Where(c => ids.Contains(c));
                dataContext.TestGroups.DeleteAllOnSubmit(test.TestGroups.Where(
                                                             c => rGroups.Contains(c.GroupId) || aGroups.Contains(c.GroupId)));
                foreach (int groupId in aGroups)
                {
                    TestGroup group = new TestGroup();
                    group.CoreTest = test;
                    group.GroupId  = groupId;
                    dataContext.TestGroups.InsertOnSubmit(group);
                }
                dataContext.SubmitChanges();
            }
        }
コード例 #2
0
        public TestorTreeItem[] GetServerTree(int parentId, int levelsNumber, TestingServerItemType itemType)
        {
            Debug.Assert(parentId >= 0);

            Provider.TestRoles(TestorUserRole.Anonymous, TestorUserRole.Administrator, TestorUserRole.Teacher, TestorUserRole.Laboratorian,
                               TestorUserRole.Student);

            using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString))
            {
                int i = -1;
                if (itemType == TestingServerItemType.TestTree || itemType == TestingServerItemType.ActiveTestTree || itemType == TestingServerItemType.FolderTree)
                {
                    if (Provider.CurrentUser.UserRole == TestorUserRole.Anonymous && parentId == 0)
                    {
                        if (!CoreConfiguration.GetAnonymousPolicy(ref parentId))
                        {
                            return new TestorTreeItem[] { }
                        }
                    }
                    ;
                }
                switch (itemType)
                {
                case TestingServerItemType.TestTree:
                {
                    var results = dataContext.GetTestTreeByLevel(GetId(parentId), GetId(levelsNumber), false, false).ToArray();
                    return(GetTestTreeItems(ref i, results, false));
                };

                case TestingServerItemType.ActiveTestTree:
                {
                    var results = dataContext.GetTestTreeByLevel(GetId(parentId), GetId(levelsNumber), false, true).ToArray();
                    return(GetTestTreeItems(ref i, results, true));
                };

                case TestingServerItemType.FolderTree:
                {
                    var results = dataContext.GetTestTreeByLevel(GetId(parentId), GetId(levelsNumber), false, false).Where(c => c.NodeType == (byte)TestorItemType.Folder).ToArray();
                    return(GetTestTreeItems(ref i, results, false));
                };

                case TestingServerItemType.GroupTree:
                {
                    var results = dataContext.GetUserGroupTree(Provider.CurrentUser.UserRole == TestorUserRole.Administrator ||
                                                               Provider.CurrentUser.UserRole == TestorUserRole.Anonymous ? 0 : Provider.CurrentUser.UserId,
                                                               GetId(parentId), true, GetId(levelsNumber)).ToArray();
                    return(GetGroupTreeItems(ref i, results));
                };

                default:
                    return(null);
                }
            }
        }
コード例 #3
0
        public int[] GetTestGroups(int testId)
        {
            Debug.Assert(testId > 0);

            Provider.TestRoles(TestorUserRole.Administrator, TestorUserRole.Teacher, TestorUserRole.Laboratorian);

            using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString))
            {
                List <int> retValue = new List <int>();
                var        ids      = from c in dataContext.GetUserGroupTree(Provider.CurrentUser.UserRole == TestorUserRole.Administrator ||
                                                                             Provider.CurrentUser.UserRole == TestorUserRole.Anonymous ? 0 : Provider.CurrentUser.UserId,
                                                                             null, true, null)
                                      select c.GroupId;
                var groups = from c in dataContext.TestGroups.Where(c => c.TestId == testId && ids.Contains(c.GroupId))
                             select new { Group = c.GroupId };
                foreach (var group in groups)
                {
                    retValue.Add(group.Group);
                }
                return(retValue.ToArray());
            }
        }