public static Test CreateTest(checkTestEntities1 ctx, TestVM test_vm) { Test test = new Test() { categoriId = test_vm.categoriId, link = @"http://localhost:4200/test/", teacherId = 25, name = test_vm.name };//active route ctx.Tests.Add(test); ctx.SaveChanges();//inorder to get the id test.link += test.testId; ctx.SaveChanges(); return(test); }
public static bool CreateQuestion(QuestionVM question) { using (var ctx = new checkTestEntities1()) { var q = QuestionCRUD.CreateQuestion(ctx, question); foreach (var ans in question.Answers) { AnswerCRUD.CreateAnswer(ctx, q, ans); } ctx.SaveChanges(); return(true); } }
public static bool CreateTest(TestVM testvm) { using (checkTestEntities1 ctx = new checkTestEntities1()) { Test test = TestCRUD.CreateTest(ctx, testvm); foreach (var quest in testvm.questionArr) { quest.categoryId = testvm.categoriId; var question = QuestionCRUD.CreateQuestion(ctx, quest); foreach (var ans in quest.Answers) { if (ans.answerDescription != null) { AnswerCRUD.CreateAnswer(ctx, question, ans); } } QuestionForTestCRUD.CreateQuestionForTest(ctx, question, test, quest.nikud); } ctx.SaveChanges(); return(true); } }