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()); }
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 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, "Сповіщення вимкнено !"); }
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, "Сповіщення увімкнено !"); }