public ActionResult GetChapterList(string semester, string department, string subject, string unit)
        {
            var semesterId = DatabaseData.GetSemesterInfo(semester)?.Id;

            var departmentId = DatabaseData.GetDepartmentInfo(department)?.Id;

            var subjectId = DatabaseData.GetCourseInfo(subject)?.Courseid;

            var unitInt = Convert.ToInt32(unit);

            var chapters = _context.Chapters
                           .Where(x => x.SemesterId == semesterId && x.DepartmentId == departmentId && x.CourseId == subjectId &&
                                  x.UnitNo == unitInt).Select(x => x.ChapterName).ToList();

            return(Json(chapters, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public ActionResult GetDetails(string selectedSemester, string selectedStaff, string selectedDepartment,
                                       string selectedSubject)
        {
            if (string.IsNullOrEmpty(selectedSemester) || string.IsNullOrEmpty(selectedStaff) ||
                string.IsNullOrEmpty(selectedDepartment) || selectedSubject.Contains("---Select---"))
            {
                TempData["AllocatedErrorMessage"] = "Please fill all of the fields";

                return(RedirectToAction("Index"));
            }

            var staffId = 0;

            // Get a selected Semester Id
            var semesterId = DatabaseData.GetSemesterInfo(selectedSemester).Id;

            // Get a selected staff Id
            var staff = _context.Staffs.FirstOrDefault(u => u.Name == selectedStaff);

            if (staff != null)
            {
                staffId = staff.Id;
            }

            // Get a selected department Id
            var departmentId = DatabaseData.GetDepartmentInfo(selectedDepartment).Id;

            // Get a selected subject id
            var subjectId = DatabaseData.GetCourseInfo(selectedSubject).Courseid;


            var newAllocatedCourse = new StaffCourse
            {
                CourseId     = subjectId,
                SemesterId   = semesterId,
                StaffId      = staffId,
                DepartmentId = departmentId
            };

            _context.StaffCourses.Add(newAllocatedCourse);
            _context.SaveChanges();

            TempData["AllocatedSuccessMessage"] = "Subject allocated to staff successfully";

            return(RedirectToAction("Index"));
        }
        public ActionResult AddQuestion(string[] selectedQuestions, int[] selectedLevel)
        {
            var semester   = (string)TempData["Para_Semester"];
            var department = (string)TempData["Para_Department"];
            var subject    = (string)TempData["Para_Subject"];
            var chapter    = (string)TempData["Para_Chapter"];
            var unit       = (string)TempData["Para_Unit"];
            var type       = (string)TempData["Para_ExamType"];


            List <int> level = selectedLevel.Where(item => item != 0).ToList();

            for (var i = 0; i < selectedQuestions.Length; i++)
            {
                var newQuestion = new Question
                {
                    UnitId          = Convert.ToInt32(unit),
                    SemesterId      = Convert.ToString(DatabaseData.GetSemesterInfo(semester).Id),
                    ChapterId       = _context.Chapters.FirstOrDefault(k => k.ChapterName == chapter)?.Id,
                    CourseId        = DatabaseData.GetCourseInfo(subject).Courseid,
                    DepartmentId    = Convert.ToString(DatabaseData.GetDepartmentInfo(department).Id),
                    DifficultyLevel = Convert.ToInt32(level[i]),
                    QuestionText    = selectedQuestions[i],
                    QuestionType    = (int)Enum.Parse(typeof(ExamType), type),
                    Answers         = null
                };

                _context.Questions.Add(newQuestion);
            }

            _context.SaveChanges();

            Alert("Success", "Question added successfully", Enums.NotificationType.success);

            return(View("Index"));
        }
        public ActionResult AddQuestion(string selectedSemester, string selectedDepartment, string selectedSubject,
                                        string selectedUnit, string chapterName, string question, string ExamType, string difficultyLevel)
        {
            // Get the semester Id
            var semesterId = DatabaseData.GetSemesterInfo(selectedSemester).Id;

            // Get the department Id
            var departmentId = DatabaseData.GetDepartmentInfo(selectedDepartment).Id;

            var subjectId = DatabaseData.GetCourseInfo(selectedSubject).Courseid;

            var unitInt = Convert.ToInt32(selectedUnit);

            var chapterId = _context.Chapters.FirstOrDefault(x =>
                                                             x.SemesterId == semesterId && x.DepartmentId == departmentId && x.CourseId == subjectId &&
                                                             x.UnitNo == unitInt && x.ChapterName == chapterName)?.Id;

            var type = (int)Enum.Parse(typeof(ExamType), ExamType);

            TempData["dept"]      = departmentId;
            TempData["sem"]       = semesterId;
            TempData["sub"]       = subjectId;
            TempData["unit"]      = unitInt;
            TempData["chapter"]   = chapterId;
            TempData["exam"]      = type;
            TempData["difflevel"] = difficultyLevel;

            var questionsList = _context.Questions.Where(x => x.SemesterId == semesterId.ToString() &&
                                                         x.DepartmentId == departmentId.ToString() &&
                                                         x.CourseId == subjectId &&
                                                         x.UnitId == unitInt &&
                                                         x.ChapterId == chapterId &&
                                                         x.QuestionType == type)
                                .Select(x => x.QuestionText)
                                .ToList();


            var url = "http://127.0.0.1:5000/semantic";

            var serverOutputDataList = new List <ServerOutputData>();


            if (questionsList.Count != 0)
            {
                foreach (var que in questionsList)
                {
                    var data = new
                    {
                        first_text  = question,
                        second_text = que
                    };

                    var cli = new WebClient
                    {
                        Headers = { [HttpRequestHeader.ContentType] = "application/json" }
                    };
                    var response = cli.UploadString(url, JsonConvert.SerializeObject(data));
                    var output   = JsonConvert.DeserializeObject <ServerOutputData>(response);
                    serverOutputDataList.Add(output);
                }

                var highestSemanticScore = serverOutputDataList.OrderByDescending(i => i.SemanticScore).First();

                if (highestSemanticScore.SemanticScore > 0.75)
                {
                    TempData["oldquestion"] = highestSemanticScore.FirstText;
                    return(RedirectToAction("Semantic", highestSemanticScore));
                }
                else
                {
                    _context.Questions.Add(new Question
                    {
                        ChapterId       = chapterId,
                        CourseId        = subjectId,
                        DepartmentId    = departmentId.ToString(),
                        DifficultyLevel = Convert.ToInt32(difficultyLevel),
                        QuestionText    = question,
                        QuestionType    = type,
                        SemesterId      = semesterId.ToString(),
                        UnitId          = unitInt
                    });

                    _context.SaveChanges();
                }
            }
            else
            {
                _context.Questions.Add(new Question
                {
                    ChapterId       = chapterId,
                    CourseId        = subjectId,
                    DepartmentId    = departmentId.ToString(),
                    DifficultyLevel = Convert.ToInt32(difficultyLevel),
                    QuestionText    = question,
                    QuestionType    = type,
                    SemesterId      = semesterId.ToString(),
                    UnitId          = unitInt
                });

                _context.SaveChangesAsync();
            }

            Alert("Success", "Question added successfully", Enums.NotificationType.success);
            return(View("Index"));
        }