private static void DrawCategory(Listing_Standard standard, PerformanceCategory category, string stringifiedCat)
        {
            var stateChange = false;
            var enableAll   = allEnabled[(int)category];

            if (category == PerformanceCategory.Removes)
            {
                var r = standard.GetRect(Text.LineHeight);
                r.x     += 30;
                r.width -= 30;
                Widgets.Label(r, stringifiedCat);
            }
            else
            {
                var rect = standard.GetRect(Text.LineHeight);
                if (DubGUI.Checkbox(rect, stringifiedCat, ref enableAll))
                {
                    stateChange = true;
                    allEnabled[(int)category] = enableAll;
                }
            }

            standard.Gap();

            foreach (var p in Patches.Where(p => p.Category == category))
            {
                if (stateChange)
                {
                    p.EnabledRefAccess() = enableAll;
                    p.CheckState();
                }

                p.Draw(standard);
            }
        }
        private static float DrawCategory(ref Listing_Standard standard, PerformanceCategory category)
        {
            var stateChange    = false;
            var enableAll      = allEnabled[(int)category];
            var stringifiedCat = category.ToString();

            if (category == PerformanceCategory.Removes)
            {
                DubGUI.Heading(standard, stringifiedCat);
            }
            else
            {
                if (DubGUI.HeadingCheckBox(standard, stringifiedCat, ref enableAll))
                {
                    stateChange = true;
                    allEnabled[(int)category] = enableAll;
                }
            }

            standard.curY += 6; // emulate the gapline we draw

            foreach (var p in Patches.Where(p => p.Category == category))
            {
                if (stateChange)
                {
                    p.EnabledRefAccess() = enableAll;
                    p.CheckState();
                }

                p.Draw(standard);
            }

            float height = standard.curY;

            standard.NewColumn();

            return(height);
        }
        public ActionResult TakeTheExam(FormCollection form)
        {
            int trueCounter  = 0;
            int falseCounter = 0;

            Exam exam = new Exam {
                StudentId = Convert.ToInt32(Session["StudentId"]), Date = DateTime.Now
            };

            List <ExamCategory> examCategories = new List <ExamCategory>();

            foreach (var item in _questionsIdList)
            {
                if (form[item.Key.ToString()] == null)
                {
                    continue;
                }

                string result   = form[item.Key.ToString()];
                string dbAnswer = GetRightAnswer(item.Key);

                bool isNewCategory = true;
                foreach (ExamCategory examCategory in examCategories.Where(examCategory => examCategory.CategoryId == item.Value))
                {
                    isNewCategory = false;
                    if (result == dbAnswer)
                    {
                        examCategory.TrueCounter += 1;
                        trueCounter += 1;
                    }
                    else
                    {
                        examCategory.FalseCounter += 1;
                        falseCounter += 1;
                    }
                }

                if (!isNewCategory)
                {
                    continue;
                }

                ExamCategory newExamCategory = new ExamCategory {
                    CategoryId = item.Value, TrueCounter = 0, FalseCounter = 0
                };

                examCategories.Add(newExamCategory);

                if (result == dbAnswer)
                {
                    newExamCategory.TrueCounter += 1;
                    trueCounter += 1;
                }
                else
                {
                    newExamCategory.FalseCounter += 1;
                    falseCounter += 1;
                }
            }

            exam.TrueCounter  = trueCounter;
            exam.FalseCounter = falseCounter;
            exam.Point        = trueCounter * 2;

            _context.Exams.Add(exam);
            _context.SaveChanges();

            foreach (var examCategory in examCategories)
            {
                int examId = exam.Id;
                examCategory.ExamId = examId;
                _context.ExamCategories.Add(examCategory);
            }

            List <PerformanceCategory> performanceCategories = new List <PerformanceCategory>();

            foreach (var examCategory in examCategories)
            {
                bool isExist = IsCategoryInList(performanceCategories, examCategory);

                if (isExist)
                {
                    continue;
                }

                PerformanceCategory newPerformanceCategory = new PerformanceCategory
                {
                    CategoryId   = examCategory.CategoryId,
                    TrueCounter  = examCategory.TrueCounter,
                    FalseCounter = examCategory.FalseCounter,
                    StudentID    = GetStundetId()
                };

                performanceCategories.Add(newPerformanceCategory);
            }

            foreach (PerformanceCategory performanceCategory in performanceCategories)
            {
                PerformanceCategory performCategory =
                    GetPerformanceWithCategoryId(GetStundetId(), performanceCategory.CategoryId);

                if (performCategory != null)
                {
                    performCategory.TrueCounter  += performanceCategory.TrueCounter;
                    performCategory.FalseCounter += performanceCategory.FalseCounter;
                }
                else
                {
                    AddPerformanceCategory(performanceCategory);
                }
            }

            _context.SaveChanges();

            List <Category> categories = GetTeacherCategories(GetTeacherIDForStudent());

            List <PerformanceCategory> existPerformanceCategories = GetPerformanceCategoriesForStudent(GetStundetId());

            foreach (var category in categories)
            {
                bool isExist = false;
                foreach (var performanceCategory in existPerformanceCategories)
                {
                    if (category.Id == performanceCategory.CategoryId)
                    {
                        isExist = true;
                        break;
                    }
                }

                if (isExist)
                {
                    continue;
                }

                var newPerformanceCategory = new PerformanceCategory
                {
                    CategoryId   = category.Id,
                    TrueCounter  = 0,
                    FalseCounter = 0,
                    StudentID    = GetStundetId()
                };

                AddPerformanceCategory(newPerformanceCategory);
            }

            _context.SaveChanges();
            ToastrService.AddToUserQueue("", "Sınavınız tamamlandı!", ToastrType.Info);
            return(RedirectToAction("Index", "Student"));
        }
 private void AddPerformanceCategory(PerformanceCategory performCategory)
 {
     _context.PerformanceCategories.Add(performCategory);
 }