private void ChangeNotificationChat() { Channel channel = db.GetChannel(KeyChannel); ButtonAndTextNotication buttonAndTextNotication = db.GetButtonAndTextNotication(user); NotificationChat[] notificationChats = db.GetNotificationChats(); NotificationChat notificationChat = notificationChats.FirstOrDefault(p => p.IdChannel == channel && p.IdNotification == buttonAndTextNotication.Id); if (notificationChat == null) { db.SetValue(new NotificationChat() { IdChannel = channel, IdNotification = buttonAndTextNotication.Id }); } else { db.Remove(notificationChat); } db.Save(); }
private async Task <Boolean> SendNotificationAllUsers(TelegramBotClient botClient) { Channel[] channels = db.GetChannels(); InlineButton inlineButton = new InlineButton(); var temp = inlineButton.PublishNotification(CollectionNotification, true); var picture = db.GetListCollectionPictureNotification(TextAndButton); NotificationChat[] notificationChats = db.GetNotificationChats(); Int32 Count = 0; foreach (var ThisUser in channels) { if (notificationChats == null) { if (notificationChats.Any(p => p.IdChannel == ThisUser && p.IdNotification == TextAndButton.Id)) { if (picture == null) { try { var mes = await botClient.SendTextMessageAsync(ThisUser.IDChannel, TextAndButton.Text.Text, replyMarkup : temp); await botClient.PinChatMessageAsync(ThisUser.IDChannel, mes.MessageId, false); } catch (Exception e) { } } else { try { var mes = await botClient.SendPhotoAsync(ThisUser.IDChannel, picture[0].Picture, TextAndButton.Text.Text, replyMarkup : temp); await botClient.PinChatMessageAsync(ThisUser.IDChannel, mes.MessageId, false); } catch (Exception e) { } } } } else { if (picture == null) { try { var mes = await botClient.SendTextMessageAsync(ThisUser.IDChannel, TextAndButton.Text.Text, replyMarkup : temp); await botClient.PinChatMessageAsync(ThisUser.IDChannel, mes.MessageId, false); } catch (Exception e) { } } else { try { var mes = await botClient.SendPhotoAsync(ThisUser.IDChannel, picture[0].Picture, TextAndButton.Text.Text, replyMarkup : temp); await botClient.PinChatMessageAsync(ThisUser.IDChannel, mes.MessageId, false); } catch (Exception e) { } } } } var tempList = db.GetListCollectionButtonNotification(); foreach (CollectionButtonNotification collectionButtonNotification in tempList) { db.Remove(collectionButtonNotification); } foreach (CollectionPictureNotification collectionPictureNotification in picture) { db.Remove(collectionPictureNotification); } foreach (NotificationChat notificationChat in notificationChats) { db.Remove(notificationChat); } var TextTemp = db.GetTextNotification(TextAndButton.Text); db.Remove(TextAndButton); db.Remove(TextTemp); db.Save(); return(true); }