public ActionResult EditChapterDetails(Chapter chap, string selectedSemester, string selectedDepartment,
                                               string selectedUnit)
        {
            var dbChapter = _context.Chapters.FirstOrDefault(u => u.Id == chap.Id);

            var semesterId = DatabaseData.GetSemesterInfo(selectedSemester).Id;

            var departmentId = DatabaseData.GetDepartmentInfo(selectedDepartment).Id;

            chap.DepartmentId = departmentId;
            chap.SemesterId   = semesterId;
            chap.UnitNo       = Convert.ToInt32(selectedUnit);

            dbChapter.ChapterName  = chap.ChapterName;
            dbChapter.DepartmentId = chap.DepartmentId;
            dbChapter.SemesterId   = chap.SemesterId;
            dbChapter.UnitNo       = chap.UnitNo;
            dbChapter.ChapterNo    = chap.ChapterNo;
            _context.SaveChangesAsync();


            TempData["ChapterDetailsEditedSuccessfully"] = "Chapter details edited successfully";

            return(RedirectToAction("ViewChapters"));
        }
Esempio n. 2
0
        public ActionResult QuestionFileUpload(string selectedFileType, HttpPostedFileBase fileControl,
                                               string selectedSemester, string selectedDepartment, string selectedSubject, string selectedUnit,
                                               string ExamType, string chapterName)
        {
            var extension = Path.GetExtension(fileControl.FileName);

            var subjectId = _context.Courses.FirstOrDefault(u => u.CourseName == selectedSubject)?.Courseid;

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

            var semesterId = DatabaseData.GetSemesterInfo(selectedSemester)?.Id;

            var unit = Convert.ToInt32(selectedUnit);

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

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

            // Word file
            if (extension == ".docx" || extension == ".doc")
            {
                ProcessFile.WordFile(fileControl);
            }

            // CSV file
            else if (extension == ".csv" || extension == ".CSV")
            {
                var data = ProcessFile.CsvFile(fileControl);
                if (data.questions == null)
                {
                    TempData["UploadError"] = data.error;
                    return(View("Index"));
                }

                foreach (var q in data.questions)
                {
                    _context.Questions.Add(new Question
                    {
                        ChapterId       = chapterId,
                        CourseId        = subjectId,
                        DepartmentId    = Convert.ToString(departmentId),
                        DifficultyLevel = q.Level,
                        QuestionText    = q.Question,
                        QuestionType    = type,
                        SemesterId      = Convert.ToString(semesterId),
                        UnitId          = unit
                    });
                }
                _context.SaveChangesAsync();

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

                return(RedirectToAction("Index", "Question"));
            }
            return(null);
        }
        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));
        }
Esempio n. 4
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"));
        }