Exemplo n.º 1
0
        private void SelectBlock(MouseEventArgs e, TimetableBlock block)
        {
            if (!e.CtrlKey && !e.ShiftKey)
            {
                SelectedBlocks.Clear();
            }

            if (e.ShiftKey)
            {
                var lastBlock   = SelectedBlocks.LastOrDefault();
                int difference  = block.Number - lastBlock.Number;
                var emptyBlocks = Timetable.Blocks.Where(t => t.Number > lastBlock.Number && t.Number <= block.Number);
                if (lastBlock != null)
                {
                    foreach (var item in emptyBlocks)
                    {
                        SelectUnselectedBlock(item);
                    }
                }
            }
            else
            {
                SelectUnselectedBlock(block);
            }



            SelectedBlocksChanged.InvokeAsync(SelectedBlocks);
            TimetableChanged.InvokeAsync(Timetable);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetCourseTimetable(string courseId, string studentId)
        {
            bool isValidCourseGUID = Guid.TryParse(courseId, out Guid courseGuid);

            if (!isValidCourseGUID)
            {
                return(ErrorResponse($"Course id: {courseId} is not valid GUID."));
            }

            bool isValidStudentGUID = Guid.TryParse(studentId, out Guid studentGuid);
            var  _student           = await _studentService.FindByIdAsync(studentGuid);

            if (!isValidStudentGUID)
            {
                return(ErrorResponse($"Student id: {studentGuid} is not valid GUID."));
            }
            if (_student == null)
            {
                return(ErrorResponse($"Student with id: {studentId} does not exist."));
            }
            var _course = await _courseService.FindCourseTimetableFromProxy(courseGuid);

            if (_course == null)
            {
                return(ErrorResponse($"Course with id: {courseId} does not exist."));
            }
            var timetable = new Timetable();
            var Blocks    = new List <TimetableBlock>();

            foreach (var block in _course.Timetable.AllBlocks)
            {
                TimetableBlock timetableBlock = new TimetableBlock
                {
                    Id         = block.BlockId.ToString(),
                    Day        = block.Day.GetHashCode(),
                    StartBlock = block.StartHour - 6,
                    EndBlock   = block.StartHour - 6 + block.Duration,
                    CourseId   = _course.Id.ToString(),
                    CourseName = _course.CourseName,
                    CourseCode = _course.CourseCode ?? "",
                    Room       = block.Room,
                    Teacher    = block.Teacher,
                    Type       = (TimetableBlockType)block.BlockType
                };
                if (!_student.Timetable.ContainsBlock(block))
                {
                    Blocks.Add(timetableBlock);
                }
            }
            timetable.Blocks = Blocks;

            return(Ok(timetable));
        }
Exemplo n.º 3
0
        private void SelectUnselectedBlock(TimetableBlock block)
        {
            var timetableBlock = Timetable.Blocks.SingleOrDefault(b => b.StartDate == block.StartDate);

            if (CheckSelection(block))
            {
                SelectedBlocks.Remove(block);
                timetableBlock.WorkItem = null;
            }
            else
            {
                SelectedBlocks.Add(block);
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> EditBlock([FromBody] UpdateBlockModel updateBlockModel)
        {
            var _user = await _userService.GetUserByEmailAsync(updateBlockModel.User.Email);

            bool isValidGUID = Guid.TryParse(_user.Student.Id.ToString(), out Guid guid);

            if (!isValidGUID)
            {
                return(ErrorResponse($"Student id: {_user.Student.Id.ToString()} is not valid GUID."));
            }

            var student = await _studentService.FindByIdAsync(guid);

            if (student == null)
            {
                return(ErrorResponse($"Student with id: {updateBlockModel.User.Student.Id} does not exist."));
            }

            if (student.Timetable == null)
            {
                return(ErrorResponse($"Timetable for student with id: {student.Id} does not exist."));
            }

            Course newCourse = await _courseService.FindByCodeAsync(updateBlockModel.TimetableBlock.CourseCode);

            if (newCourse == null)
            {
                return(ErrorResponse($"New course: {updateBlockModel.TimetableBlock.CourseName} does not exist."));
            }

            Block newBlock = TimetableBlock.ConvertToBlock(updateBlockModel.TimetableBlock, newCourse.Id);

            if (student.Timetable.UpdateBlock(newBlock))
            {
                student.Timetable.UpdateColorOfBlocksWithSameCourseId(newBlock);
                await _studentService.UpdateStudentAsync(student);
            }
            else
            {
                return(ErrorResponse($"Block {newBlock.ToString()} is not updated"));
            }

            return(Ok(newBlock));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> AddNewBlock([FromBody] AddNewBlockModel newBlockModel)
        {
            var _user = await _userService.GetUserByEmailAsync(newBlockModel.User.Email);

            var student = await _studentService.FindByIdAsync(_user.Student.Id);

            if (student == null)
            {
                return(ErrorResponse($"Student with id: {_user.Student.Id} does not exist."));
            }

            if (student.Timetable == null)
            {
                return(ErrorResponse($"Timetable for student with id: {student.Id} does not exist."));
            }

            TimetableBlock timetableBlock = newBlockModel.TimetableBlock;
            Course         course         = await _courseService.GetOrAddNotExistsCourse(timetableBlock.CourseCode,
                                                                                         timetableBlock.CourseName);

            if (course == null)
            {
                return(ErrorResponse($"Course: {timetableBlock.CourseName} does not exist."));
            }

            Block block = TimetableBlock.ConvertToBlock(timetableBlock, course.Id);

            if (student.Timetable.IsSubjectPresentInTimetable(block))
            {
                return(ErrorResponse($"Course: {timetableBlock.CourseName} is already present."));
            }

            student.Timetable.AddNewBlock(block);
            student.Timetable.UpdateColorOfBlocksWithSameCourseId(block);
            await _studentService.UpdateStudentAsync(student);

            //return block with new id
            return(Ok(newBlockModel.TimetableBlock));
        }
Exemplo n.º 6
0
 private bool CheckSelection(TimetableBlock block)
 {
     return(SelectedBlocks.Contains(block));
 }
Exemplo n.º 7
0
        public async Task <IActionResult> GetStudentTimetable(string userEmail)
        {
            try
            {
                _logger.LogInformation($"[API getStudentTimetable] Setting timetable for test student");
                User user = await _userService.GetUserByEmailAsync(userEmail);

                if (user?.Student == null)
                {
                    _logger.Log(LogLevel.Information, $"Student for user: {userEmail} does not exist.");
                    return(Ok(new Timetable()));
                }
                string studentId = user.Student.Id.ToString();
                if (!Guid.TryParse(studentId, out Guid guid))
                {
                    _logger.Log(LogLevel.Error, $"Student id: {studentId} is not valid GUID.");
                    return(ErrorResponse($"Student id: {studentId} is not valid GUID."));
                }
                var student = await _studentService.FindByIdAsync(guid);

                if (student == null)
                {
                    _logger.Log(LogLevel.Error, $"Student with id: {studentId} does not exist.");
                    return(ErrorResponse($"Student with id: {studentId} does not exist."));
                }
                if (student.Timetable == null)
                {
                    _logger.Log(LogLevel.Error, $"Timetable for student with id: {studentId} does not exist.");
                    return(Ok(new Timetable()));
                }
                if (student.Timetable.IsOutDated() && !string.IsNullOrEmpty(student.PersonalNumber))
                {
                    var scheduleTimetable = await _schoolScheduleProxy.GetByPersonalNumber(student.PersonalNumber);

                    if (scheduleTimetable == null)
                    {
                        return(ErrorResponse($"Student with number: {student.PersonalNumber} does not exist."));
                    }
                    await _studentService.UpdateStudentTimetableAsync(student,
                                                                      await ConverterApiToDomain.ConvertTimetableForPersonalNumberAsync(scheduleTimetable, _courseService)
                                                                      );

                    await _userService.UpdateUserAsync(user);

                    var requests = await _blockChangesService.FindWaitingStudentRequests(student.Id);

                    foreach (var item in requests)
                    {
                        await _blockChangesService.CancelExchangeRequest(item);
                    }
                }
                var timetable = new Timetable();
                var Blocks    = new List <TimetableBlock>();
                foreach (var block in student.Timetable.AllBlocks)
                {
                    TimetableBlock timetableBlock = new TimetableBlock();
                    Course         course         = await _courseService.FindByIdAsync(block.CourseId);

                    timetableBlock.Id         = block.BlockId.ToString();
                    timetableBlock.Day        = block.Day.GetHashCode();
                    timetableBlock.StartBlock = block.StartHour - 6;
                    timetableBlock.EndBlock   = timetableBlock.StartBlock + block.Duration;
                    timetableBlock.CourseId   = course.Id.ToString();
                    timetableBlock.CourseName = course.CourseName;
                    timetableBlock.CourseCode = course.CourseCode;
                    timetableBlock.Room       = block.Room;
                    timetableBlock.Teacher    = block.Teacher;
                    timetableBlock.Type       = (TimetableBlockType)block.BlockType;
                    timetableBlock.BlockColor = block.BlockColor;
                    Blocks.Add(timetableBlock);
                }
                timetable.Blocks = Blocks;
                return(Ok(timetable));
            }
            catch (Exception e)
            {
                _logger.Log(LogLevel.Error, $"When processing user: {userEmail} exception was invoked: {e}");
                return(ErrorResponse($"Student: {userEmail} produced exception."));
            }
        }