public void Save(MovieList entity) { var connString = "Host=localhost;Port=5432;Username=postgres;Password=123456;Database=MyMovieList"; using (var conn = new NpgsqlConnection(connString)) { conn.Open(); using (var cmd = new NpgsqlCommand()) { cmd.Connection = conn; cmd.CommandText = "INSERT INTO MyMovieList (movie, rating, sender_id) " + "VALUES (@movie, @rating, @sender_id)"; cmd.Parameters.AddWithValue("movie", entity.Movie); cmd.Parameters.AddWithValue("rating", Convert.ToInt32(entity.Rating)); cmd.Parameters.AddWithValue("sender_id", Convert.ToInt32(entity.SenderId)); cmd.ExecuteNonQuery(); } }; }
static async void Bot_OnMessage(object sender, MessageEventArgs e) { if (e.Message.Text == "/start") { var rkm = new ReplyKeyboardMarkup { Keyboard = new KeyboardButton[][] { new KeyboardButton[] { new KeyboardButton("Найти фильм"), new KeyboardButton("Записать фильм в список буду смотреть"), new KeyboardButton("Посмотреть список буду смотреть"), }, new KeyboardButton[] { new KeyboardButton("Поставить оценку просмотренному фильму"), new KeyboardButton("Посмотреть мои просмотренные фильмы"), } } }; await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : "Что вы хотите сделать?", replyMarkup : rkm); return; } if (e.Message.Text == "Записать фильм в список буду смотреть") { unwatchedList = new UnwatchedList(); Count = 0; unwatchedList.SenderId = e.Message.From.Id; Count = Count + 10; await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : "Название фильма?", replyMarkup : new ReplyKeyboardRemove() { }); return; } if (Count == 10) { unwatchedList.Movie = e.Message.Text; Count = 0; unwatchedListService.Save(unwatchedList); await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : "Сохранён"); } if (e.Message.Text == "Поставить оценку просмотренному фильму") { movieList = new MovieList(); Count = 0; movieList.SenderId = e.Message.From.Id; Count++; await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : "Название фильма?", replyMarkup : new ReplyKeyboardRemove() { }); return; } if (Count == 1) { movieList.Movie = e.Message.Text; Count++; var rkm = new ReplyKeyboardMarkup { Keyboard = new KeyboardButton[][] { new KeyboardButton[] { new KeyboardButton("1"), new KeyboardButton("2"), new KeyboardButton("3"), new KeyboardButton("4"), new KeyboardButton("5"), }, new KeyboardButton[] { new KeyboardButton("6"), new KeyboardButton("7"), new KeyboardButton("8"), new KeyboardButton("9"), new KeyboardButton("10"), } } }; await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : "Какую оценку ты ему ставишь?", replyMarkup : rkm); return; } if (Count == 2) { movieList.Rating = e.Message.Text; Count = 0; service.Save(movieList); await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : "Сохранён"); var rkm = new ReplyKeyboardMarkup { Keyboard = new KeyboardButton[][] { new KeyboardButton[] { new KeyboardButton("Найти фильм"), new KeyboardButton("Записать фильм в список буду смотреть"), new KeyboardButton("Посмотреть список буду смотреть"), }, new KeyboardButton[] { new KeyboardButton("Поставить оценку просмотренному фильму"), new KeyboardButton("Посмотреть мои просмотренные фильмы"), } } }; await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : "Что вы хотите сделать?", replyMarkup : rkm); return; } if (e.Message.Text == "Посмотреть мои просмотренные фильмы") { ListService listService = new ListService(); await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : listService.WatchedMovieListService(service.OpenList(e.Message.From.Id))); Thread.Sleep(500); await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : "Ваш список фильмов с оценками"); Thread.Sleep(500); var rkm = new ReplyKeyboardMarkup { Keyboard = new KeyboardButton[][] { new KeyboardButton[] { new KeyboardButton("Найти фильм"), new KeyboardButton("Записать фильм в список буду смотреть"), new KeyboardButton("Посмотреть список буду смотреть"), }, new KeyboardButton[] { new KeyboardButton("Поставить оценку просмотренному фильму"), new KeyboardButton("Посмотреть мои просмотренные фильмы"), } } }; await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : "Что вы хотите сделать?", replyMarkup : rkm); return; //Thread.Sleep(500); //await botClient.SendTextMessageAsync( // chatId: e.Message.Chat, // text: "Вы можете посмотеть фильмы с определенными оценками либо выйти в главное меню"); //Thread.Sleep(500); //var rkm = new ReplyKeyboardMarkup //{ // Keyboard = new KeyboardButton[][] // { // new KeyboardButton[] // { // new KeyboardButton("Посмотреть список фильмов с определенными оценками"), // new KeyboardButton("Выйти в главное меню"), // } // } //}; //await botClient.SendTextMessageAsync( // chatId: e.Message.Chat, // text: "Так что же вы хотите сделать?", // replyMarkup: rkm); //return; } //if (e.Message.Text == "Посмотреть список фильмов с определенными оценками") //{ // var t = 0; // var rkm = new ReplyKeyboardMarkup // { // Keyboard = new KeyboardButton[][] // { // new KeyboardButton[] // { // new KeyboardButton("1"), // new KeyboardButton("2"), // new KeyboardButton("3"), // new KeyboardButton("4"), // new KeyboardButton("5"), // }, // new KeyboardButton[] // { // new KeyboardButton("6"), // new KeyboardButton("7"), // new KeyboardButton("8"), // new KeyboardButton("9"), // new KeyboardButton("10"), // } // } // }; // t++; // await botClient.SendTextMessageAsync( // chatId: e.Message.Chat, // text: "С какой оценкой список фильмов тебе нужен?", // replyMarkup: rkm); // return; //} //if (t == 1) //{ // ListService listService = new ListService(); // await botClient.SendTextMessageAsync( // chatId: e.Message.Chat, // text: listService.WatchedMovieListService(service.ListWithRating(e.Message.From.Id, e.Message.Text))); //} if (e.Message.Text == "Посмотреть список буду смотреть") { var t = 0; //unwatchedList = new UnwatchedList(); ListService listService = new ListService(); await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : listService.UnwatchedMovieListService(unwatchedListService.OpenUnwatchedList(e.Message.From.Id))); Thread.Sleep(500); await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : "Ваш список буду смотреть"); var rkm = new ReplyKeyboardMarkup { Keyboard = new KeyboardButton[][] { new KeyboardButton[] { new KeyboardButton("Я посмотрел фильм и хочу поставить ему оценку"), new KeyboardButton("Выйти в главное меню"), } } }; await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : "Что вы хотите сделать?", replyMarkup : rkm); return; } //ТУТ СДЕЛАТЬ ФАКТ ЧЕКИНГ И ПОФИКСИТЬ if (e.Message.Text == "Я посмотрел фильм и хочу поставить ему оценку") { t++; await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : "Какой фильм вы посмотрели?"); return; } if (t == 1) { movieList = new MovieList(); service = new MovieListService(); unwatchedList = new UnwatchedList(); unwatchedListService = new UnwatchedListService(); // if() unwatchedListService.Delete(e.Message.Text); movieList.SenderId = e.Message.From.Id; movieList.Movie = e.Message.Text; t++; var rkm = new ReplyKeyboardMarkup { Keyboard = new KeyboardButton[][] { new KeyboardButton[] { new KeyboardButton("1"), new KeyboardButton("2"), new KeyboardButton("3"), new KeyboardButton("4"), new KeyboardButton("5"), }, new KeyboardButton[] { new KeyboardButton("6"), new KeyboardButton("7"), new KeyboardButton("8"), new KeyboardButton("9"), new KeyboardButton("10"), } } }; await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : "Какую оценку ты ему ставишь?", replyMarkup : rkm); return; } if (t == 2) { movieList.Rating = e.Message.Text; Count = 0; service.Save(movieList); await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : "Сохранён"); var rkm = new ReplyKeyboardMarkup { Keyboard = new KeyboardButton[][] { new KeyboardButton[] { new KeyboardButton("Найти фильм"), new KeyboardButton("Записать фильм в список буду смотреть"), new KeyboardButton("Посмотреть список буду смотреть"), }, new KeyboardButton[] { new KeyboardButton("Поставить оценку просмотренному фильму"), new KeyboardButton("Посмотреть мои просмотренные фильмы"), } } }; await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : "Что вы хотите сделать?", replyMarkup : rkm); return; } if (e.Message.Text == "Выйти в главное меню") { var rkm = new ReplyKeyboardMarkup { Keyboard = new KeyboardButton[][] { new KeyboardButton[] { new KeyboardButton("Найти фильм"), new KeyboardButton("Записать фильм в список буду смотреть"), new KeyboardButton("Посмотреть список буду смотреть"), }, new KeyboardButton[] { new KeyboardButton("Поставить оценку просмотренному фильму"), new KeyboardButton("Посмотреть мои просмотренные фильмы"), } } }; await botClient.SendTextMessageAsync( chatId : e.Message.Chat, text : "Что вы хотите сделать?", replyMarkup : rkm); return; } }