public string ChangeMyBuy(out string reply_markup) { reply_markup = ""; List <Recycle> p; List <Product> m = new List <Product>(); string[] ar; using (botEntities3 bd = new botEntities3()) { p = bd.Recycle.Where(x => x.TokenId == TokenIds).Where(x => x.UserName == username).ToList(); ar = new string[p.Count]; for (int i = 0; i < p.Count; i++) { try { string namecat = p[i].NameCategory; string nameprod = p[i].NameProduct; Product k = bd.Product.Where(x => x.ProductName == nameprod).Where(x => x.Category.NameCategory == namecat).First(); ar[i] = k.Category.NameCategory; m.Add(k); } catch { } } } if (m.Count == 0) { return("Выберете пункт меню"); } InlineKeyboard keyboard = new InlineKeyboard(); int o = 0; for (int i = 0; i < p.Count; i++) { try { o++; keyboard.AddButton(new InlineKeyboardButton("Удалить " + m[i].ProductName + "(" + ar[i] + ")" + " цена " + m[i].ProductPrice + " 1 шт", "корзина удалить " + ar[i] + " " + m[i].ProductName)); } catch { } } this.Count = o; keyboard.AddButton(new InlineKeyboardButton("Оформить", "корзина оформить")); keyboard.AddButton(new InlineKeyboardButton("⬅️ Назад", "about")); reply_markup = JsonConvert.SerializeObject(keyboard); return("Изменение заказа"); }
string Shop(string category, string nameProduct, Update update, int?id, out string reply_markup) { //string category = shop.Split(' ')[0]; //string nameProduct = shop.Split(' ').Length < 2 ? "" : shop.Split(' ')[1]; string answer = "!"; reply_markup = ""; List <Category> cat = null; List <Product> p = null; // SendMessage(update.callback_query.from.id, category , ReceiveToken(update, id)); using (botEntities3 bd = new botEntities3()) { try { cat = bd.Category.Where(x => x.Token.Id == id).ToList(); p = cat.Where(x => x.NameCategory == category).First().Product.ToList(); if (nameProduct == "") { nameProduct = p[0].ProductName; } } catch { // SendMessage(update.callback_query.from.id, "БД УПало", ReceiveToken(update, id)); } } InlineKeyboard keyboard = new InlineKeyboard(); int i = 0; foreach (Product k in p) { if (nameProduct == k.ProductName) { continue; } keyboard.AddButton(new InlineKeyboardButton( k.ProductName, k.Category.NameCategory + " " + k.ProductName), i++ / 2); } AddRecycle(keyboard, category, nameProduct, update, id); Product chooseProduct = p.Where(x => x.ProductName == nameProduct).First(); if (chooseProduct.ProductPhoto == null) { chooseProduct.ProductPhoto = ""; } answer = "Стоимость товара " + chooseProduct.ProductPrice + "руб" + Environment.NewLine + "Описание" + " " + chooseProduct.ProductDescription + chooseProduct.ProductPhoto; keyboard.AddButton(new InlineKeyboardButton("⬅️ Назад", "about")); AddMainButtons(keyboard, update, id); reply_markup = JsonConvert.SerializeObject(keyboard); return(answer); }
string Recycle(Update update, int?id, out string reply_markup) { string answer = ""; reply_markup = ""; TelegramRecycle rec = new TelegramRecycle(update, id); string[] _data = update.callback_query.data.Split(); switch (_data[1] ?? "") { case "покупка": rec.AddBuy(_data[2], _data[3]); answer = Shop(_data[2], _data[3], update, id, out reply_markup); break; default: break; } answer = "В корзине" + rec.Count + " шт"; InlineKeyboard keyboard = new InlineKeyboard(); keyboard.AddButton(new InlineKeyboardButton("Назад", "about")); AddMainButtons(keyboard); reply_markup = JsonConvert.SerializeObject(keyboard); return(answer); }
string MainMenu(Update update, int?id, out string reply_markup) { List <Category> list; string token = ""; int i = 0; using (botEntities3 bd = new botEntities3()) { list = bd.Category.Where(x => x.Token.Id == id).ToList(); token = ReceiveToken(update, id); } InlineKeyboard keyboard = new InlineKeyboard(); foreach (Category k in list) { keyboard.AddButton(new InlineKeyboardButton( k.NameCategory ), i++ / 2); } AddRecycle(keyboard, "", "", update, id); AddMainButtons(keyboard, update, id); reply_markup = JsonConvert.SerializeObject(keyboard); return("Все категории"); }
//void editMessageCaption(Update update,string answer,int ? id ,string reply_markup) // { // } string Recycle(Update update, int?id, out string reply_markup) { string answer = ""; reply_markup = ""; TelegramRecycle rec = new TelegramRecycle(update, id); string[] _data = update.callback_query.data.Split(); switch (_data[1] ?? "") { case "покупка": rec.AddBuy(_data[2], _data[3]); answer = Shop(_data[2], _data[3], update, id, out reply_markup); break; case "отобразить": answer = rec.ShowMyBuy(); InlineKeyboard keyboard = new InlineKeyboard(); List <InlineKeyboardButton> line = new List <InlineKeyboardButton>() { new InlineKeyboardButton("Оформить", "корзина оформить"), new InlineKeyboardButton("Изменить", "корзина изменить") }; keyboard.AddLine(line); keyboard.AddButton(new InlineKeyboardButton("⬅️ Назад", "about")); reply_markup = JsonConvert.SerializeObject(keyboard); break; case "изменить": answer = rec.ChangeMyBuy(out reply_markup); break; case "удалить": rec.DeleteElement(_data[2], _data[3]); answer = rec.ChangeMyBuy(out reply_markup); break; case "оформить": answer = "Выберете вариант:" + Environment.NewLine + Environment.NewLine + "Отправить телефон и мы с вами свяжемся n"; reply_markup = ReturnReplyToAdmin(); SendMessage(update.callback_query.from.id, answer, ReceiveToken(update, id), reply_markup); return("отмена"); default: break; } // answer = "В корзине" + rec.Count + " шт"; //InlineKeyboard keyboard = new InlineKeyboard(); //keyboard.AddButton(new InlineKeyboardButton("Назад", "about")); //AddMainButtons(keyboard); //reply_markup = JsonConvert.SerializeObject(keyboard); //Shop(_data[2], _data[3], update, id, out reply_markup); if (reply_markup == "") { MainMenu(update, id, out reply_markup); } return(answer); }
void AddMainButtons(InlineKeyboard keyboard, Update update) { List <InlineKeyboardButton> line = new List <InlineKeyboardButton>() { new InlineKeyboardButton("Добавить магазин", "reg"), new InlineKeyboardButton("Восстановить пароль", "voc") }; keyboard.AddLine(line); keyboard.AddButton(new InlineKeyboardButton("Как пользоваться", "about")); }
string Shop(string category, string nameProduct, Update update, int?id, out string reply_markup) { //string category = shop.Split(' ')[0]; //string nameProduct = shop.Split(' ').Length < 2 ? "" : shop.Split(' ')[1]; string answer = "Привет"; reply_markup = ""; List <Category> cat = null; List <Product> p = null; // SendMessage(update.callback_query.from.id, category , ReceiveToken(update, id)); using (botEntities2 bd = new botEntities2()) { try { cat = bd.Category.Where(x => x.Token.Id == id).ToList(); p = cat.Where(x => x.NameCategory == category).First().Product.ToList(); if (nameProduct == "") { nameProduct = p[0].ProductName; } } catch { // SendMessage(update.callback_query.from.id, "БД УПало", ReceiveToken(update, id)); } } //try //{ // SendMessage(update.callback_query.from.id, p.Count.ToString(), ReceiveToken(update, id)); //} //catch //{ // SendMessage(update.callback_query.from.id, "равно 0", ReceiveToken(update, id)); //} //list = cat.Where(x => x.NameCategory == category).First(); //if (list == null) //{ // SendMessage(update.callback_query.from.id, "null", ReceiveToken(update, id)); //} //else SendMessage(update.callback_query.from.id, list.Product.Count.ToString(), ReceiveToken(update, id)); InlineKeyboard keyboard = new InlineKeyboard(); int i = 0; foreach (Product k in p) { if (nameProduct == k.ProductName) { continue; } keyboard.AddButton(new InlineKeyboardButton( k.ProductName, k.Category.NameCategory + " " + k.ProductName), i++ / 2); } AddRecycle(keyboard, category, nameProduct); Product chooseProduct = p.Where(x => x.ProductName == nameProduct).First(); answer += chooseProduct.ProductPrice + Environment.NewLine + " " + " " + chooseProduct.ProductDescription; keyboard.AddButton(new InlineKeyboardButton("Назад", "about")); AddMainButtons(keyboard); reply_markup = JsonConvert.SerializeObject(keyboard); return(answer); }