Exemple #1
0
        public void TimetableCountTest()
        {
            TimetableGeneratorService timetableGeneratorService = new TimetableGeneratorService();

            Assert.Empty(timetableGeneratorService.GenerateTimetableList(new TimetableData {
                CourseList = new List <CourseData>(), CourseLecturerSettings = GetCourseLecturerSettings()
            }, ""));
            Assert.Single(timetableGeneratorService.GenerateTimetableList(new TimetableData {
                CourseList = GetCourseDataMock(), CourseLecturerSettings = GetCourseLecturerSettings()
            }, ""));
            Assert.Single(timetableGeneratorService.GenerateTimetableList(new TimetableData {
                CourseList = GetCourseDataMock().Concat(GetCourseDataMock()), CourseLecturerSettings = GetCourseLecturerSettings()
            }, ""));
            Assert.Equal(2, timetableGeneratorService.GenerateTimetableList(new TimetableData {
                CourseList = GetCourseWithTwoGroupsDataMock(), CourseLecturerSettings = GetCourseLecturerSettings()
            }, "").Count());
            Assert.Equal(2, timetableGeneratorService.GenerateTimetableList(new TimetableData {
                CourseList = GetCourseWithTwoGroupsDataMock().Concat(GetCourseDataMock()), CourseLecturerSettings = GetCourseLecturerSettings()
            }, "").Count());
            Assert.Equal(4, timetableGeneratorService.GenerateTimetableList(new TimetableData {
                CourseList = GetCourseWithTwoGroupsDataMock().Concat(GetCourseWithTwoGroupsDataMock()), CourseLecturerSettings = GetCourseLecturerSettings()
            }, "").Count());
            Assert.Equal(8, timetableGeneratorService.GenerateTimetableList(new TimetableData {
                CourseList = GetCourseWithTwoGroupsDataMock().Concat(GetCourseWithTwoGroupsDataMock()).Concat(GetCourseWithTwoGroupsDataMock()), CourseLecturerSettings = GetCourseLecturerSettings()
            }, "").Count());
        }
Exemple #2
0
        public IActionResult GenerateTimetable([FromQuery] int hashCode, [FromBody] IEnumerable <CourseLecturerSettings> courseLecturerSettings)
        {
            bool courseUpdate = _timetableConfigService.UpdateUserCourseLecturerSettings(User.Identity.Name, hashCode, courseLecturerSettings);

            string conditions = _accountService.GetUser(User.Identity.Name).Conditions;

            TimetableData data = _timetableConfigService.GetTimetableDataByHashCode(User.Identity.Name, hashCode);

            if (!courseUpdate)
            {
                return(Ok(new { response = "failed to update course lecturer settings!" }));
            }
            if (data != null)
            {
                IEnumerable <Timetable> timetableList = _timetableGeneratorService.GenerateTimetableList(data, conditions);
                return(Ok(new { response = "success", data = timetableList }));
            }
            return(Ok(new { response = "not found" }));
        }