public string AdminText() { try { using (MarketBotDbContext db = new MarketBotDbContext()) { if (Product.Unit == null) { Product.Unit = db.Units.Where(u => u.Id == Product.UnitId).FirstOrDefault(); } if (Product.Stock == null || Product.Stock.Count == 0) { Product.Stock = db.Stock.Where(s => s.ProductId == ProductId).OrderByDescending(s => s.Id).ToList(); } if (Price == null || Price.Currency == null) { Price = db.ProductPrice.Where(p => p.Id == PriceId).Include(p => p.Currency).FirstOrDefault(); } } if (Price != null && Product != null && Product.Unit != null && Product.Stock.Count > 0 && Product.Stock.FirstOrDefault().Balance >= Count && Price.Currency != null) { return(Product.Name + " " + Price.Value.ToString() + " " + Price.Currency.ShortName + " x " + Count.ToString() + " " + Product.Unit.ShortName + " = " + (Count * Price.Value).ToString() + " " + Price.Currency.ShortName + " | в наличии: " + Product.Stock.FirstOrDefault().Balance.ToString() + " " + Product.Unit.ShortName); } //если заказывают больше чем есть. Выделяем жирным if (Price != null && Product != null && Product.Unit != null && Product.Stock.Count > 0 && Product.Stock.FirstOrDefault().Balance < Count && Price.Currency != null) { return(Product.Name + " " + Price.Value.ToString() + " " + Price.Currency.ShortName + " x " + Count.ToString() + " " + Product.Unit.ShortName + " = " + (Count * Price.Value).ToString() + " " + Price.Currency.ShortName + " |" + BotMessage.Bold("в наличии: " + Product.Stock.FirstOrDefault().Balance.ToString() + " " + Product.Unit.ShortName)); } //в наличии 0 if (Price != null && Product != null && Product.Unit != null && Product.Stock.Count == 0 && Price.Currency != null) { return(Product.Name + " " + Price.Value.ToString() + " " + Price.Currency.ShortName + " x " + Count.ToString() + " " + Product.Unit.ShortName + " = " + (Count * Price.Value).ToString() + " " + Price.Currency.ShortName + " |" + BotMessage.Bold(" в наличии: 0 " + Product.Unit.ShortName)); } else { return(String.Empty); } } catch (Exception e) { return(null); } }
/// <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 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); } } }
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); } }