Пример #1
0
        public async Task <ActionResult> SetNotification(Guid studentId, [FromBody] NotificationsModel notificationsModel)
        {
            // check if student exists
            // update notifications
            //return 204
            var studentExists = _repository.StudentExists(studentId);

            if (!studentExists)
            {
                return(NotFound());
            }

            var notificationEntity = _mapper.Map <NotificationsSettings>(notificationsModel);

            notificationEntity.StudentId = studentId;
            await _repository.UpdateNotification(notificationEntity);

            await _repository.SaveAsync();

            await _jobsManager.RefreshJobs();

            var telegramDataExists = _repository.UserTelegramDataExists(studentId);

            if (notificationsModel.NotificationType == "Telegram" && !telegramDataExists)
            {
                return(Ok(new { message = "Для роботи нотифікацій через телеграм бот, потрібно авторизуватись через телеграм, зайти в телеграмм бот і натиснути /start" }));
            }
            return(NoContent());
            // if student telegram chat not exists, return it to client
        }
Пример #2
0
        public ActionResult <IEnumerable <SubjectDto> > GetAvailableSubjects(string studentId)
        {
            if (!_repository.StudentExists(studentId))
            {
                return(NotFound());
            }
            var subjectFromRepo = _repository.GetAvailableSubjectsForStudent(studentId);
            var subjectsDtos    = subjectFromRepo.Select(s => _mapper.Map <SubjectDto>(s)).ToList();

            return(subjectsDtos);
        }
Пример #3
0
        public async Task <ActionResult <IEnumerable <LessonWithSubjectDto> > > GetTimetableAsync(string studentId)
        {
            // Todo optimize time of request
            if (!_repository.StudentExists(studentId))
            {
                return(NotFound());
            }

            var lessonsEntities = await _repository.GetLessonsWithSubjectsForStudentAsync(studentId);

            var lessonDtos = lessonsEntities.Select(l => _mapper.Map <LessonWithSubjectDto>(l));

            return(Ok(lessonDtos.OrderBy(l => l.Week)
                      .ThenBy(l => l.DayOfWeek)
                      .ThenBy(l => l.TimeStart)));
        }
Пример #4
0
        public ActionResult DeleteStudent(string studentId)
        {
            if (!_repository.StudentExists(studentId))
            {
                return(NotFound());
            }

            var studentFromRepo = _repository.GetStudent(studentId);

            if (studentFromRepo == null)
            {
                return(NotFound());
            }
            _repository.DeleteStudent(studentFromRepo);

            return(NoContent());
        }
Пример #5
0
        public async Task <ActionResult <IEnumerable <SubjectDto> > > GetTimetableAsync(Guid studentId)
        {
            if (!_repository.StudentExists(studentId))
            {
                return(NotFound());
            }

            // get lessons
            // order lessons
            var student = await _repository.GetStudentAsync(studentId);

            if (student == null)
            {
                return(NotFound());
            }

            var lessons = await _repository.GetLessonsForStudent(studentId);

            return(Ok(lessons));
        }