示例#1
0
        public async Task <IActionResult> DisableSubjects(Guid studentId, Guid subjectId)
        {
            if (string.IsNullOrEmpty(studentId.ToString()))
            {
                return(NotFound());
            }
            var student = await _repository.GetStudentAsync(studentId);

            if (student == null)
            {
                return(BadRequest("Student don`t exists"));
            }

            var subject = await _repository.GetSubjectAsync(subjectId);

            if (subject == null)
            {
                return(BadRequest("Subject won`t exists"));
            }
            // disable
            await _repository.DisableSubjectAsync(student.Id, subject.Id);

            await _repository.SaveAsync();

            return(NoContent());
        }
        public async Task <ActionResult> SetNotifications(Guid studentId,
                                                          [FromBody] NotificationsModel notificationsModel)
        {
            var student = await _repository.GetStudentWithNotification(studentId);

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

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

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

            await _repository.SaveAsync();

            var telegramDataExists = _repository.UserTelegramDataExists(studentId);

            if (notificationsModel.NotificationType == "Telegram" && !telegramDataExists)
            {
                return(Ok(new { message = "Для роботи нотифікацій через телеграм бот, потрібно авторизуватись через телеграм, зайти в телеграмм бот і натиснути /start" }));
            }
            return(NoContent());
        }
示例#3
0
        public async Task <ActionResult> PatchSubject(Guid subjectId, [FromBody] JsonPatchDocument <SubjectToUpdate> patchDocument)
        {
            if (patchDocument == null)
            {
                return(BadRequest());
            }

            var subjectFromRepo = await _repository.GetSubjectAsync(subjectId);

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

            var subjectToPatch = _mapper.Map <SubjectToUpdate>(subjectFromRepo);

            patchDocument.ApplyTo(subjectToPatch, ModelState);
            if (!TryValidateModel(subjectToPatch))
            {
                return(ValidationProblem());
            }

            _mapper.Map(subjectToPatch, subjectFromRepo);

            _repository.UpdateSubject(subjectFromRepo);

            await _repository.SaveAsync();

            return(NoContent());
        }
示例#4
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
        }
        public async Task <IActionResult> OnUpdate([FromBody] Update update)
        {
            if (update == null)
            {
                return(Ok());
            }

            var message = update.Message;
            var command = _commandFactory.GetCommand(message);

            if (command != null)
            {
                await command.Execute(message, Bot.BotClient);
            }
            await _repository.SaveAsync();

            return(Ok());
        }
示例#6
0
        public async Task Execute(Message message, TelegramBotClient client)
        {
            // todo перевірка наяності свовіщень
            Console.WriteLine("We are here !");
            var student = await _repository.GetUserByTelegramId(message.From.Id);

            var notificationEntity = new NotificationsSettings
            {
                StudentId         = student.Id,
                IsNotificationsOn = false
            };
            await _repository.UpdateNotification(notificationEntity);

            await _repository.SaveAsync();

            await _jobsManager.RefreshJobs();

            await Bot.BotClient.SendTextMessageAsync(message.Chat.Id, "Сповіщення вимкнено !");
        }
示例#7
0
        public async Task Execute(Message message, TelegramBotClient client)
        {
            // todo перевірка наявності сповіщень
            var student = await _repository.GetUserByTelegramId(message.From.Id);

            if (student == null)
            {
                // todo Bot : винести текст команд в статичний класс
                await Bot.BotClient.SendTextMessageAsync(message.Chat.Id, "Щоб користуватись сповіщеннями, їх потрібно увімкнути на сайті <domain> ");
            }
            var notificationEntity = new NotificationsSettings
            {
                StudentId         = student.Id,
                IsNotificationsOn = true
            };
            await _repository.UpdateNotification(notificationEntity);

            await _repository.SaveAsync();

            await _jobsManager.RefreshJobs();

            await Bot.BotClient.SendTextMessageAsync(message.Chat.Id, "Сповіщення увімкнено !");
        }