public override string ToString() { try { string StockStatus = String.Empty; const string StockStatusOutOfStock = "Нет в наличии"; if (Stock.Count > 0 && Stock.ElementAt(Stock.Count - 1) == null || Stock.Count > 0 && Stock.ElementAt(Stock.Count - 1) != null && Stock.ElementAt(Stock.Count - 1).Balance == 0) { StockStatus = StockStatusOutOfStock; } if (Stock.Count == 0) { StockStatus = StockStatusOutOfStock; } string price = CurrentPrice.ToString(); return("Название: " + Name + BotMessage.NewLine() + "Цена: " + price + " / " + Unit.ShortName + BotMessage.NewLine() + "Описание: " + Text + BotMessage.NewLine() + StockStatus); } catch { return(String.Empty); } }
public override InlineQueryResult[] GetResult() { db = new MarketBotDbContext(); var ProductList = GetProductList().Take(MaxResult).ToList(); InputTextMessageContent[] textcontent = new InputTextMessageContent[ProductList.Count]; InlineQueryResultArticle[] article = new InlineQueryResultArticle[ProductList.Count]; InlineQueryResult[] result = new InlineQueryResult[ProductList.Count]; int i = 0; foreach (Product prod in ProductList) { textcontent[i] = new InputTextMessageContent(); textcontent[i].ParseMode = Telegram.Bot.Types.Enums.ParseMode.Html; textcontent[i].DisableWebPagePreview = true; textcontent[i].MessageText = "/adminproduct" + prod.Id.ToString(); article[i] = new InlineQueryResultArticle(); article[i].HideUrl = true; article[i].Id = prod.Id.ToString(); article[i].Title = prod.Name; article[i].Description = "Категория:" + prod.Category.Name + BotMessage.NewLine() + "Цена:" + prod.CurrentPrice.Value; article[i].ThumbUrl = "https://cdn2.iconfinder.com/data/icons/shop-payment-vol-6/128/shop-07-256.png"; article[i].InputMessageContent = textcontent[i]; result[i] = article[i]; i++; } db.Dispose(); return(result); }
public override InlineQueryResult[] GetResult() { var Orders = FollowerFunction.FollowerOrder(FollowerId).Take(MaxResult).ToList(); InputTextMessageContent[] textcontent = new InputTextMessageContent[Orders.Count]; InlineQueryResultArticle[] article = new InlineQueryResultArticle[Orders.Count]; InlineQueryResult[] result = new InlineQueryResult[Orders.Count]; int i = 0; foreach (var order in Orders) { textcontent[i] = new InputTextMessageContent(); textcontent[i].ParseMode = Telegram.Bot.Types.Enums.ParseMode.Html; textcontent[i].DisableWebPagePreview = true; textcontent[i].MessageText = "/order" + order.Number.ToString(); article[i] = new InlineQueryResultArticle(); article[i].HideUrl = false; article[i].Id = order.Id.ToString(); article[i].Title = "Заказ №" + order.Number.ToString(); article[i].Description = "Время:" + order.DateAdd.ToString() + BotMessage.NewLine(); article[i].ThumbUrl = "https://cdn2.iconfinder.com/data/icons/shop-payment-vol-6/128/shop-19-256.png"; article[i].InputMessageContent = textcontent[i]; result[i] = new InlineQueryResult(); result[i] = article[i]; i++; } return(result); }
/// <summary> /// Присылает сообщение с инструкцией как добавить новый товар в БД. /// </summary> /// <returns></returns> private async Task <IActionResult> SendInsertProductFAQ() { string Currencies = ""; string Units = ""; using (MarketBotDbContext db = new MarketBotDbContext()) { var CurrencyList = db.Currency.ToList(); var UnitList = db.Units.ToList(); foreach (Currency c in CurrencyList) { Currencies += c.Name + " - " + c.ShortName; } foreach (Units u in UnitList) { Units += u.Name + "-" + u.ShortName; } } const string quote = "\""; string Example = "Пришлите фотографию товара, а в поле под фотографией(можно без фотографии, просто ответьте на сообщение бота) добавьте комментарий следующего вида:" + " Название товара, Категория, Цена, Валюта, Еденица измерения, В наличии, " + quote + "Краткое описание [не обязательно]" + quote + BotMessage.NewLine() + BotMessage.Bold("Например: ") + "Хреновуха, Настойки,500, руб., шт., 5, " + quote + "40 градусов" + quote + BotMessage.NewLine() + BotMessage.Bold("Например: ") + "Рис, Крупы,100, руб., кг., 100" + BotMessage.NewLine() + BotMessage.Bold("Например: ") + "Сникерс, Конфеты, 50, руб., г., 1000" + quote + "Вкусные конфеты. Ага" + quote + BotMessage.NewLine() + BotMessage.NewLine() + BotMessage.Bold("Доступные валюты: ") + Currencies + BotMessage.NewLine() + BotMessage.Bold("Еденицы измерения: ") + Units; ForceReply forceReply = new ForceReply { Force = true, Selective = true }; if (await SendMessage(new BotMessage { TextMessage = Example }) != null && await SendMessage(new BotMessage { TextMessage = EnterNameNewProductCmd, MessageReplyMarkup = forceReply }) != null) { return(base.OkResult); } else { return(base.NotFoundResult); } }
public override InlineQueryResult[] GetResult() { db = new MarketBotDbContext(); this.FollowerList = GetFollower().Take(MaxResult).ToList(); InputTextMessageContent[] textcontent = new InputTextMessageContent[FollowerList.Count]; InlineQueryResultArticle[] article = new InlineQueryResultArticle[FollowerList.Count]; InlineQueryResult[] result = new InlineQueryResult[FollowerList.Count]; int i = 0; foreach (var follower in FollowerList) { string telephoneLine = ""; FollowerControlMessage followerControlMessage = new FollowerControlMessage(follower.Id); var message = followerControlMessage.BuildMsg(); if (follower.Telephone != null && follower.Telephone != "") { telephoneLine = BotMessage.NewLine() + "Телефон: " + follower.Telephone; } textcontent[i] = new InputTextMessageContent(); textcontent[i].ParseMode = Telegram.Bot.Types.Enums.ParseMode.Html; textcontent[i].DisableWebPagePreview = true; textcontent[i].MessageText = message.TextMessage; article[i] = new InlineQueryResultArticle(); article[i].HideUrl = false; article[i].Id = follower.Id.ToString(); article[i].Title = follower.FirstName + " " + follower.LastName; article[i].Description = telephoneLine; article[i].ReplyMarkup = followerControlMessage.SetInline(); article[i].ThumbUrl = "https://cdn3.iconfinder.com/data/icons/user-avatars-1/512/users-11-2-256.png"; article[i].Url = "https://t.me/" + follower.UserName; article[i].InputMessageContent = textcontent[i]; result[i] = new InlineQueryResult(); result[i] = article[i]; i++; } return(result); }
public static string GetPositionInfo(int FollowerID, int BotId) { using (MarketBotDbContext db = new MarketBotDbContext()) { var basket = db.Basket.Where(b => b.FollowerId == FollowerID && b.Enable && b.BotInfoId == BotId); var IdList = basket.Select(b => b.ProductId).Distinct().AsEnumerable(); int counter = 1; double total = 0.0; string message = String.Empty; string currency = String.Empty; if (IdList.Count() > 0) { foreach (int id in IdList) { Product product = db.Product.Where(p => p.Id == id).Include(p => p.CurrentPrice).FirstOrDefault(); int count = basket.Where(p => p.ProductId == id).Count(); product.CurrentPrice.Currency = db.Currency.Find(product.CurrentPrice.CurrencyId); message += counter.ToString() + ") " + product.Name + " " + product.CurrentPrice.ToString() + " x " + count.ToString() + " = " + (count * product.CurrentPrice.Value).ToString() + product.CurrentPrice.Currency.ShortName + " | " + Bot.ProductBot.ProductCmd + product.Id.ToString() + BotMessage.NewLine(); total += product.CurrentPrice.Value * count; counter++; currency = product.CurrentPrice.Currency.ShortName; } return(message + BotMessage.NewLine() + BotMessage.Bold("Общая стоимость: ") + total.ToString() + " " + currency); } else { return(null); } } }
public override InlineQueryResult[] GetResult() { db = new MarketBotDbContext(); var Follower = db.Follower.Where(f => f.ChatId == ChatId).FirstOrDefault(); if (Follower != null) { OrderList = db.Orders.Where(o => o.FollowerId == Follower.Id).OrderByDescending(o => o.Id).Take(MaxResult).ToList(); int i = 0; InputTextMessageContent[] textcontent = new InputTextMessageContent[OrderList.Count]; InlineQueryResultArticle[] article = new InlineQueryResultArticle[OrderList.Count]; InlineQueryResult[] result = new InlineQueryResult[OrderList.Count]; foreach (Orders order in OrderList) { textcontent[i] = new InputTextMessageContent(); textcontent[i].ParseMode = Telegram.Bot.Types.Enums.ParseMode.Html; textcontent[i].DisableWebPagePreview = true; textcontent[i].MessageText = "/myorder" + order.Number.ToString(); article[i] = new InlineQueryResultArticle(); article[i].HideUrl = true; article[i].Id = order.Id.ToString(); article[i].Title = order.Number.ToString(); article[i].Description = "№:" + order.Number.ToString() + BotMessage.NewLine() + "Дата:" + order.DateAdd.ToString(); article[i].ThumbUrl = "https://cdn2.iconfinder.com/data/icons/shop-payment-vol-6/128/shop-04-256.png"; article[i].InputMessageContent = textcontent[i]; result[i] = article[i]; i++; } db.Dispose(); return(result); } return(null); }
public override InlineQueryResult[] GetResult() { list = HelpDeskFunction.GetHelpDeskList(Number).Take(MaxResult).ToList(); InputTextMessageContent[] textcontent = new InputTextMessageContent[list.Count]; InlineQueryResultArticle[] article = new InlineQueryResultArticle[list.Count]; InlineQueryResult[] result = new InlineQueryResult[list.Count]; int i = 0; foreach (var help in list) { textcontent[i] = new InputTextMessageContent(); textcontent[i].ParseMode = Telegram.Bot.Types.Enums.ParseMode.Html; textcontent[i].DisableWebPagePreview = true; textcontent[i].MessageText = "/ticket" + help.Number.ToString(); article[i] = new InlineQueryResultArticle(); article[i].HideUrl = false; article[i].Id = help.Id.ToString(); article[i].Title = "Заявка №" + help.Number.ToString(); article[i].Description = help.Number + BotMessage.NewLine() + "Время:" + help.Timestamp; article[i].ThumbUrl = "https://cdn2.iconfinder.com/data/icons/shop-payment-vol-6/128/shop-10-256.png"; article[i].InputMessageContent = textcontent[i]; result[i] = new InlineQueryResult(); result[i] = article[i]; i++; } return(result); }
private async Task <IActionResult> AddProduct() { string product_name = ReplyToMessageText.Trim(); ProductFunction = new ProductFunction(); var product = ProductFunction.GetProduct(product_name); var categorys = CategoryList(); bool IsProhibited = ProductFunction.NameIsProhibited(product_name); if (product != null) { return(await SendTextMessageAndForceReply("Товар с таким именем уже существует", EnterProductNameForceReply)); } if (IsProhibited) { return(await SendTextMessageAndForceReply("Запрещенное название!", EnterProductNameForceReply)); } else { product = ProductFunction.InsertProduct(product_name, true); if (product != null && !IsProhibited) { return(await SendTextMessageAndForceReply("Введите название новой категории или выберите уже существующую." + BotMessage.NewLine() + BotMessage.Bold("Список категорий:") + categorys, EnterCategoryForceReply + product.Name)); } else { return(await SendTextMessageAndForceReply("Неизвестная ошибка", EnterProductNameForceReply)); } } }
public string AdminMessage() { string MenuStatus = "Активно"; string MainPhotoString = ""; string CodeString = ""; string Url = ""; int?Balance = 0; if (Enable == false) { MenuStatus = "Скрыто от пользователей"; } if (Stock.Count > 0) { Balance = Stock.OrderByDescending(s => s.Id).FirstOrDefault().Balance; } if (Unit == null) { Unit = Connection.getConnection().Units.Where(u => u.Id == UnitId).FirstOrDefault(); } if (MainPhoto > 0) { MainPhotoString = "Есть"; } else { MainPhotoString = "Отсутствует"; } if (TelegraphUrl != null) { Url = TelegraphUrl; } if (Code != null) { CodeString = Code; } try { return(BotMessage.Bold("Название: ") + Name + BotMessage.NewLine() + BotMessage.Bold("Цена: ") + CurrentPrice.ToString() + " / " + Unit.ShortName + BotMessage.NewLine() + BotMessage.Bold("Категория: ") + Category.Name + BotMessage.NewLine() + BotMessage.Bold("Описание: ") + Text + BotMessage.NewLine() + BotMessage.Bold("В наличии: ") + Balance.ToString() + BotMessage.NewLine() + BotMessage.Bold("Артикул:") + CodeString + BotMessage.NewLine() + BotMessage.Bold("Ссылка на подробное описание:") + Url + BotMessage.NewLine() + BotMessage.Bold("В меню: ") + MenuStatus + BotMessage.NewLine() + BotMessage.Bold("Фотография:") + MainPhotoString + BotMessage.NewLine() + BotMessage.Bold("Доп. фото:") + ProductPhoto.Count.ToString() + " шт."); } catch (Exception e) { return(String.Empty); } }
/// <summary> /// Сообщение с инстуркцией по импорту данных и csv /// </summary> /// <returns></returns> private async Task <IActionResult> SendImportFAQ() { try { await base.SendMessage(new BotMessage { TextMessage = "1) Заполните csv файл " + BotMessage.NewLine() + "2) Сохраните файл как Import.csv" + BotMessage.NewLine() + "3) Отправьте файл боту" }); using (MarketBotDbContext db = new MarketBotDbContext()) { Configuration configuration = db.Configuration.FirstOrDefault(); // FileId файла Пример.csv есть в базе if (configuration != null && configuration.ExampleCsvFileId != null) { FileToSend fileToSend = new FileToSend { Filename = "Пример.csv", FileId = configuration.ExampleCsvFileId }; var message = await SendDocument(fileToSend, "Пример заполнения"); } // FileID в базе нет, отправляяем файл и сохраняем в бд FileID if (configuration != null && configuration.ExampleCsvFileId == null) { var stream = System.IO.File.Open("Пример.csv", FileMode.Open); FileToSend fileToSend = new FileToSend { Filename = "Пример.csv", Content = stream }; var message = await SendDocument(fileToSend, "Пример заполнения"); configuration.ExampleCsvFileId = message.Document.FileId; db.SaveChanges(); } // FileId файла Шаблон.csv есть в базе if (configuration != null && configuration.TemplateCsvFileId != null) { FileToSend fileToSend = new FileToSend { Filename = "Шаблон.csv", FileId = configuration.ExampleCsvFileId }; var message = await SendDocument(fileToSend, "Пример заполнения"); } // FileID в базе нет, отправляяем файл и сохраняем в бд FileID if (configuration != null && configuration.TemplateCsvFileId == null) { var stream = System.IO.File.Open("Шаблон.csv", FileMode.Open); FileToSend fileToSend = new FileToSend { Filename = "Шаблон.csv", Content = stream }; var message = await SendDocument(fileToSend, "Пример заполнения"); configuration.TemplateCsvFileId = message.Document.FileId; db.SaveChanges(); } } return(base.OkResult); } catch (Exception exp) { return(base.NotFoundResult); } }