Пример #1
0
        public static TestForStudentVM GetByTestIdForStudent(int testId)
        {
            using (checkTestEntities1 ctx = new checkTestEntities1())
            {
                TestForStudentVM test = new TestForStudentVM();
                Test             t    = TestCRUD.ReadTestById(ctx, testId);
                test.title       = t.name;
                test.testId      = t.testId;
                test.questionArr = new List <QuestionForTestVM>();
                foreach (var quenstion in t.QuestionforTests)//מעבר על כל שאלות המבחן
                {
                    List <Answer> answers        = Entity.db.Answers.Where(ans => ans.questionId == quenstion.questionId).ToList();
                    List <string> answersDes     = new List <string>();
                    Answer        selectedAnswer = answers.FirstOrDefault(ans => ans.isCorrect == true);
                    foreach (var item in answers)//תשובות של שאלה נוכחית
                    {
                        answersDes.Add(item.answerDescription);
                    }
                    test.questionArr.Add(new QuestionForTestVM()//המרת שאלה נוכחית
                    {
                        questionDescription = quenstion.Question.questionDescription,
                        Answers             = answersDes,
                        nikud = quenstion.nikod,

                        selectedAnswer = selectedAnswer.answerDescription
                    });
                }
                return(test);
            }
        }
Пример #2
0
 public static void CreateAnswer(checkTestEntities1 ctx, Question q, AnswerVM ans)
 {
     ctx.Answers.Add(new Answer()
     {
         answerDescription = ans.answerDescription,
         isCorrect         = ans.isCorrect,
         Question          = q
     });
 }
Пример #3
0
 public static void CreateQuestionForTest(checkTestEntities1 ctx, Question question, Test test, int nikud)
 {
     ctx.QuestionforTests.Add(new QuestionforTest()
     {
         Question = question,
         nikod    = nikud,
         Test     = test
     });
 }
Пример #4
0
        public static TestVM GetByCategory(int categoryId)
        {
            using (checkTestEntities1 ctx = new checkTestEntities1())
            {
                TestVM test = new TestVM();
                Test   t    = TestCRUD.ReadOneTestByCat(ctx, categoryId);
                test.name   = test.name;
                test.testId = t.testId;

                return(test);
            }
        }
Пример #5
0
        public static Question CreateQuestion(checkTestEntities1 ctx, QuestionVM question)
        {
            var newQ = new Question()
            {
                categoriId          = question.categoryId,
                questionDescription = question.questionDescription,
                isPrivate           = true//TODO create permission and then change
            };

            ctx.Questions.Add(newQ);
            return(newQ);
        }
Пример #6
0
 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);
     }
 }
Пример #7
0
 public static List <TestVM> FilterByCategory(int catId)
 {
     using (checkTestEntities1 ctx = new checkTestEntities1())
     {
         List <TestVM> testsList = new List <TestVM>();
         foreach (var test in TestCRUD.ReadTestByCat(ctx, catId))
         {
             testsList.Add(new TestVM()
             {
                 name   = test.name,
                 testId = test.testId
             });
         }
         return(testsList);
     }
 }
Пример #8
0
        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);
        }
Пример #9
0
        public static List <CategoryTreeItem> GetCategoryTree()
        {
            using (var ctx = new checkTestEntities1())
            {
                var categoriesList = CategoryCRUD.GetAllCategories(ctx);
                List <CategoryTreeItem> categoryTreeList = new List <CategoryTreeItem>();
                categoryTreeList.Add(new CategoryTreeItem()
                {
                    id       = 0,
                    name     = "all",
                    children = new List <CategoryTreeItem>()
                });

                GetAllCategortTree(categoriesList, null, categoryTreeList[0]);
                return(categoryTreeList);
            }
        }
Пример #10
0
        public static int getStudents()
        {
            try
            {
                using (checkTestEntities1 db = new checkTestEntities1())
                {
                    int numStudent = 0;
                    numStudent = db.students.Count();
                    if (numStudent != 0)
                    {
                        return(numStudent);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(0);
        }
Пример #11
0
 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);
     }
 }
Пример #12
0
        public static int getTeachers()
        {
            //The context cannot be used while the model is being created. This exception may be thrown if the context is used inside the OnModelCreating method or if the same context instance is accessed by multiple threads concurrently.Note that instance members of DbContext and related classes are not guaranteed to be thread safe."
            try
            {
                using (checkTestEntities1 db = new checkTestEntities1())
                {
                    int numTeachers = 0;
                    numTeachers = db.Teachers.Count();

                    if (numTeachers != 0)
                    {
                        return(numTeachers);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(0);
        }
Пример #13
0
        public static TestVM GetByTestId(int testId)
        {
            using (checkTestEntities1 ctx = new checkTestEntities1())
            {
                TestVM test = new TestVM();
                Test   t    = TestCRUD.ReadTestById(ctx, testId);
                test.name        = t.name;
                test.testId      = t.testId;
                test.categoriId  = t.categoriId;
                test.questionArr = new List <QuestionVM>();
                foreach (var quenstion in t.QuestionforTests)
                {
                    List <Answer>   answers   = Entity.db.Answers.Where(ans => ans.questionId == quenstion.questionId).ToList();
                    List <AnswerVM> answersvm = new List <AnswerVM>();
                    foreach (var item in answers)
                    {
                        answersvm.Add(new AnswerVM()
                        {
                            answerDescription = item.answerDescription,
                            answerId          = item.answerId,
                            isCorrect         = item.isCorrect
                        });
                    }
                    test.questionArr.Add(new QuestionVM()
                    {
                        isPrivate           = false,
                        questionDescription = quenstion.Question.questionDescription,
                        Answers             = answersvm,
                        nikud      = quenstion.nikod,
                        categoryId = quenstion.Question.categoriId,
                        questionId = quenstion.questionId
                    });
                }

                return(test);
            }
        }
Пример #14
0
        public static Test GetByTestIdForStudent(checkTestEntities1 ctx, int testId)
        {
            Test tests = ctx.Tests.FirstOrDefault(t => t.testId == testId);

            return(tests);
        }
Пример #15
0
        public static Test ReadTestById(checkTestEntities1 ctx, int testId)
        {
            Test tests = ctx.Tests.FirstOrDefault(t => t.testId == testId);

            return(tests);
        }
Пример #16
0
        public static Test ReadOneTestByCat(checkTestEntities1 ctx, int categoryId)
        {
            Test tests = ctx.Tests.FirstOrDefault(t => t.categoriId == categoryId);

            return(tests);
        }
Пример #17
0
        public static List <Test> ReadTestByCat(checkTestEntities1 ctx, int categoryId)
        {
            List <Test> tests = ctx.Tests.Where(t => t.categoriId == categoryId).ToList();

            return(tests);
        }
Пример #18
0
 public static List <Category> GetAllCategories(checkTestEntities1 ctx)
 {
     return(ctx.Categories.ToList());
 }