コード例 #1
0
        public void RemoveItem(int itemId, TestingServerItemType itemType)
        {
            Debug.Assert(itemId > 0);

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

            using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString))
            {
                switch (itemType)
                {
                case TestingServerItemType.TestTree:
                {
                    Provider.TestTreeAccess(itemId);
                    int testId = dataContext.RemoveTestTreeItem(itemId);
                    if (testId != 0)
                    {
                        var test = dataContext.CoreTests.Where(c => c.TestId == testId).First();
                        test.IsDeleted = true;
                        dataContext.CoreRequirements.DeleteAllOnSubmit(
                            dataContext.CoreRequirements.Where(c => c.TestId == test.TestId ||
                                                               c.Requirement == test.TestId));
                        dataContext.TestGroups.DeleteAllOnSubmit(test.TestGroups);
                        dataContext.CoreMasterParts.DeleteAllOnSubmit(test.CoreMasterParts);
                        dataContext.CoreMasterParts.DeleteAllOnSubmit(test.CoreMasterParts1);
                        dataContext.SubmitChanges();
                    }
                } break;

                case TestingServerItemType.GroupTree:
                {
                    Provider.TestRoles(TestorUserRole.Administrator);
                    dataContext.RemoveGroupTreeItem(itemId);
                }
                break;

                default:
                    break;
                }
            }
        }