Ejemplo n.º 1
0
 public static void CreateQuestionForTest(testitprojectEntities ctx, Question question, Test test, int nikud)
 {
     ctx.QuestionforTests.Add(new QuestionforTest()
     {
         Question = question,
         nikod    = nikud,
         Test     = test
     });
 }
Ejemplo n.º 2
0
 public static void CreateAnswer(testitprojectEntities ctx, Question q, AnswerVM ans)
 {
     ctx.Answers.Add(new Answer()
     {
         answerDescription = ans.answerDescription,
         isCorrect         = ans.isCorrect,
         Question          = q
     });
     ctx.SaveChanges();
 }
Ejemplo n.º 3
0
 public static object publicQuestion(int id)
 {
     using (var ctx = new testitprojectEntities())
     {
         if (ctx.Questions.FirstOrDefault(q => q.questionId == id) != null)
         {
             ctx.Questions.FirstOrDefault(q => q.questionId == id).isPrivate = false;
             ctx.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// יצירת שאלה
 /// </summary>
 /// <param name="question"></param>
 /// <returns></returns>
 public static bool CreateQuestion(QuestionVM question, int userId)
 {
     using (var ctx = new testitprojectEntities())
     {
         var q = QuestionCRUD.CreateQuestion(ctx, question, userId);
         foreach (var ans in question.Answers)
         {
             AnswerCRUD.CreateAnswer(ctx, q, ans);
         }
         ctx.SaveChanges();
         return(true);
     }
 }
Ejemplo n.º 5
0
 public static UserVM GetUserDetailById(string id)
 {
     using (testitprojectEntities ctx = new testitprojectEntities())
     {
         var user = ctx.Teachers.FirstOrDefault(p => p.teacherId.ToString() == id);
         return(new UserVM()
         {
             Id = user.teacherId,
             email = user.email,
             isManager = user.isManager != null? (bool)user.isManager:false,
             Name = user.teacherName
         });
     }
 }
Ejemplo n.º 6
0
        public static Question CreateQuestion(testitprojectEntities ctx, QuestionVM question, int userId)
        {
            var newQ = new Question()
            {
                categoriId          = question.categoryId,
                createById          = userId,
                questionDescription = question.questionDescription,
                isPrivate           = question.isPrivate//TODO create permission and then change
            };

            ctx.Questions.Add(newQ);
            ctx.SaveChanges();
            return(newQ);
        }
Ejemplo n.º 7
0
        public static Test CreateTest(testitprojectEntities ctx, TestVM test_vm, int userId)
        {
            Test test = new Test()
            {
                categoriId = test_vm.categoriId,
                link       = @"http://localhost:4200/test/",
                teacherId  = userId,
                name       = test_vm.name
            };//active route

            ctx.Tests.Add(test);
            ctx.SaveChanges();//in order to get the id
            test.link += test.testId;

            ctx.SaveChanges();
            return(test);
        }
Ejemplo n.º 8
0
 public static List <ModelStatisticA> StatisticA()
 {
     using (var ctx = new testitprojectEntities())
     {
         var ls             = new List <ModelStatisticA>();
         var categoriesList = ctx.Categories.ToList();
         foreach (var category in categoriesList)
         {
             var questionsNumber = ctx.Questions.Where(i => i.categoriId == category.categoryId).Count();
             ls.Add(new ModelStatisticA()
             {
                 name = category.categoryName,
                 y    = questionsNumber
             });
         }
         return(ls);
     }
 }
Ejemplo n.º 9
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var identity = new ClaimsIdentity(context.Options.AuthenticationType);

            using (testitprojectEntities ctx = new testitprojectEntities())
            {
                var user = ctx.Teachers.FirstOrDefault(p => p.teacherName == context.UserName && p.teacherPassword == context.Password);
                if (user != null)
                {
                    identity.AddClaim(new Claim("UserId", user.teacherId.ToString()));
                    context.Validated(identity);
                }
                else
                {
                    context.SetError("invalid_grant", "Provided username and password is incorrect");
                    context.Rejected();
                }
            }
        }
Ejemplo n.º 10
0
        public static int getStudents()
        {
            try
            {
                using (testitprojectEntities db = new testitprojectEntities())
                {
                    int numStudent = 0;
                    numStudent = db.students.Count();
                    if (numStudent != 0)
                    {
                        return(numStudent);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(0);
        }
Ejemplo n.º 11
0
        /// <summary>
        ///פונקציה המחזירה עץ המורכב מכל הקטגוריות
        /// </summary>
        /// <returns></returns>
        public static List <CategoryTreeItem> GetCategoryTree()
        {
            using (var ctx = new testitprojectEntities())
            {
                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]);
                if (categoryTreeList[0].children.Count > 0)
                {
                    return(categoryTreeList[0].children);
                }
                return(new List <CategoryTreeItem>());
            }
        }
Ejemplo n.º 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 (testitprojectEntities db = new testitprojectEntities())
                {
                    int numTeachers = 0;
                    numTeachers = db.Teachers.Count();

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

            return(0);
        }
Ejemplo n.º 13
0
        public static Test GetByTestIdForStudent(testitprojectEntities ctx, int testId)
        {
            Test tests = ctx.Tests.FirstOrDefault(t => t.testId == testId);

            return(tests);
        }
Ejemplo n.º 14
0
        public static Test ReadTestById(testitprojectEntities ctx, int testId)
        {
            Test tests = ctx.Tests.FirstOrDefault(t => t.testId == testId);

            return(tests);
        }
Ejemplo n.º 15
0
        public static Test ReadOneTestByCat(testitprojectEntities ctx, int categoryId)
        {
            Test tests = ctx.Tests.FirstOrDefault(t => t.categoriId == categoryId);

            return(tests);
        }
Ejemplo n.º 16
0
        public static List <Test> ReadTestByCat(testitprojectEntities ctx, int categoryId)
        {
            List <Test> tests = ctx.Tests.Where(t => t.categoriId == categoryId).ToList();

            return(tests);
        }
Ejemplo n.º 17
0
 public static List <Category> GetAllCategories(testitprojectEntities ctx)
 {
     return(ctx.Categories.ToList());
 }