public TestorTreeItem CreateFolder(int parentId, string folderName) { Debug.Assert(parentId >= 0); Debug.Assert(!String.IsNullOrEmpty(folderName)); Provider.TestRoles(TestorUserRole.Administrator, TestorUserRole.Teacher, TestorUserRole.Laboratorian); using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString)) { TestorData td = new TestorData(); TestorData.CoreTestsRow testRow = HtmlStore.CreateCoreTest(td, folderName); CoreTest coreTest = new CoreTest(); CreateCoreTest(testRow, coreTest); dataContext.CoreTests.InsertOnSubmit(coreTest); dataContext.SubmitChanges(); int result = dataContext.AddTestTreeItem(GetId(parentId), (int)TestorItemType.Folder, coreTest.TestId, Provider.CurrentUser.UserId); TestorTreeItem retValue = new TestorTreeItem( result, coreTest.TestId, folderName, TestorItemType.Folder, new TestorTreeItem[] { }); retValue.ItemOwner = Provider.CurrentUser.UserId; return(retValue); } }
public TestorTreeItem[] SendTests(byte[] testorData, int folderId, int[] groupIds) { Debug.Assert(testorData != null); Debug.Assert(folderId >= 0); Provider.TestRoles(TestorUserRole.Administrator, TestorUserRole.Teacher, TestorUserRole.Laboratorian); using (DataClassesTestorCoreDataContext dataContext = new DataClassesTestorCoreDataContext(TestorSecurityProvider.ConnectionString)) { TestorData data = DataCompressor.DecompressData <TestorData>(testorData); //data.WriteXml("C:/locator.xml", System.Data.XmlWriteMode.IgnoreSchema); Dictionary <int, CoreTest> xTests = new Dictionary <int, CoreTest>(); foreach (TestorData.CoreTestsRow coreTest in data.CoreTests) { CoreTest test = new CoreTest(); test.TestKey = coreTest.TestKey; test.IsMasterTest = coreTest.IsMasterTest; CreateCoreTest(coreTest, test); xTests.Add(coreTest.TestId, test); dataContext.CoreTests.InsertOnSubmit(test); foreach (int groupId in groupIds) { TestGroup group = new TestGroup(); group.CoreTest = test; group.GroupId = groupId; dataContext.TestGroups.InsertOnSubmit(group); } foreach (var coreQuest in coreTest.GetCoreQuestionsRows()) { CoreQuestion quest = new CoreQuestion(); quest.CoreTest = test; quest.QuestionType = coreQuest.QuestionType; quest.Question = coreQuest.Question; quest.QuestionMark = coreQuest.QuestionMark; try { if (!Convert.IsDBNull(coreQuest.QuestionMetadata)) { quest.QuestionMetadata = coreQuest.QuestionMetadata; } } catch { quest.QuestionMetadata = null; } dataContext.CoreQuestions.InsertOnSubmit(quest); foreach (var coreAnswer in coreQuest.GetCoreAnswersRows()) { CoreAnswer answer = new CoreAnswer(); answer.CoreQuestion = quest; answer.Answer = coreAnswer.Answer; answer.IsTrue = coreAnswer.IsTrue; try { if (!Convert.IsDBNull(coreAnswer.AnswerMetadata)) { answer.AnswerMetadata = coreAnswer.AnswerMetadata; } } catch { answer.AnswerMetadata = null; } dataContext.CoreAnswers.InsertOnSubmit(answer); } foreach (var coreBlob in coreQuest.GetCoreBLOBsRows()) { CoreBLOB blob = new CoreBLOB(); blob.CoreQuestion = quest; blob.BLOBId = coreBlob.BLOBId; blob.BLOBContent = coreBlob.BLOBContent; dataContext.CoreBLOBs.InsertOnSubmit(blob); } } } foreach (var masterTest in data.CoreTests.Where(c => c.IsMasterTest == true)) { var parts = data.CoreMasterParts.Where(c => c.MasterTestId == masterTest.TestId); var test = xTests.Where(c => c.Value.TestKey == masterTest.TestKey).FirstOrDefault(); foreach (var part in parts) { CoreMasterPart masterPart = new CoreMasterPart(); masterPart.CoreTest1 = test.Value; masterPart.CoreTest = xTests.Where( c => c.Key == part.PartTestId).FirstOrDefault().Value; masterPart.QuestionsNumber = part.QuestionsNumber; dataContext.CoreMasterParts.InsertOnSubmit(masterPart); } } foreach (var coreReq in data.CoreRequirements) { CoreRequirement req = new CoreRequirement(); Guid testKey = data.CoreTests.Where(c => c.TestId == coreReq.TestId).FirstOrDefault().TestKey; Guid reqKey = data.CoreTests.Where(c => c.TestId == coreReq.Requirement).FirstOrDefault().TestKey; req.CoreTest = xTests.Where(c => c.Value.TestKey == testKey).FirstOrDefault().Value; req.CoreTest1 = xTests.Where(c => c.Value.TestKey == reqKey).FirstOrDefault().Value; dataContext.CoreRequirements.InsertOnSubmit(req); } try { dataContext.SubmitChanges(); } catch (Exception ex) { throw ex; } List <TestorTreeItem> retValue = new List <TestorTreeItem>(); foreach (var test in xTests) { CoreTest coreTest = test.Value; TestorItemType type = TestorItemType.Test; if (coreTest.IsMasterTest) { type = TestorItemType.MasterTest; } int result = dataContext.AddTestTreeItem(GetId(folderId), (byte)type, coreTest.TestId, Provider.CurrentUser.UserId); TestorTreeItem item = new TestorTreeItem(result, coreTest.TestId, coreTest.TestName, type, null); retValue.Add(item); } return(retValue.ToArray()); } }