コード例 #1
0
        private async Task <IActionResult> UpdStock()
        {
            ProductFunction = new ProductFunction();

            string product_name = OriginalMessage.Substring(StockValueForceReply.Length);

            var product = ProductFunction.GetProduct(product_name);

            try
            {
                int balance = Convert.ToInt32(ReplyToMessageText);

                if (balance >= 0 && product != null)
                {
                    product = ProductFunction.UpdateStock(product.Id, balance, "Добавление нового товара через диалог с ботом");
                    ProductFunction.Dispose();
                    return(await SendForceReplyMessage(UploadImageForceReply + product.Name));
                }

                else
                {
                    return(await SendTextMessageAndForceReply(product.Name + " /adminproduct" + product.Id + " Ошибка! Значение должно быть больше 0", StockValueForceReply + product.Name));
                }
            }

            catch
            {
                return(await SendTextMessageAndForceReply(product_name + "Ошибка! Неверный формат данных", StockValueForceReply + product_name));
            }
        }
コード例 #2
0
        private async Task <IActionResult> UpdText()
        {
            ProductFunction = new ProductFunction();

            string product_name = OriginalMessage.Substring(EnterTextForceReply.Length);

            Product = ProductFunction.GetProduct(product_name);

            string units = UnitsList();

            if (Product != null && ReplyToMessageText.Length <= 100)
            {
                Product = ProductFunction.UpdateText(Product.Id, ReplyToMessageText);
                ProductFunction.Dispose();
                await SendTextMessageAndForceReply("Еденица измерения:" + units, EnterUnitForceReply + Product.Name);

                return(OkResult);
            }

            if (Product != null && ReplyToMessageText.Length > 100)
            {
                ProductFunction.Dispose();
                return(await SendTextMessageAndForceReply("Ошибка! Максимум 100 символов", EnterTextForceReply + Product.Name));
            }

            else
            {
                ProductFunction.Dispose();
                return(await SendTextMessageAndForceReply("Введите краткое описание вашего товара. Максмимум 100 символов", EnterTextForceReply + Product.Name));
            }
        }
コード例 #3
0
        private async Task <IActionResult> UpdPrice()
        {
            ProductFunction = new ProductFunction();

            string product_name = OriginalMessage.Substring(EnterPriceForceReply.Length);

            var product = ProductFunction.GetProduct(product_name);

            try
            {
                double price = Convert.ToDouble(ReplyToMessageText);

                if (price > 0 && product != null)
                {
                    product = ProductFunction.UpdatePrice(product.Id, price, Convert.ToInt32(BotInfo.Configuration.CurrencyId));
                    ProductFunction.Dispose();
                    return(await SendForceReplyMessage(StockValueForceReply + product.Name));
                }

                else
                {
                    return(await SendTextMessageAndForceReply(product.Name + "Ошибка! Значение должно быть больше 0", EnterPriceForceReply + product.Name));
                }
            }

            catch
            {
                return(await SendTextMessageAndForceReply(product_name + "Ошибка! Неверный формат данных", EnterPriceForceReply + product_name));
            }
        }
コード例 #4
0
        /// <summary>
        /// Добавить доп фото
        /// </summary>
        /// <returns></returns>
        private async Task <IActionResult> InsertAdditionallyPhoto()
        {
            AttachmentTelegram TgAttach = null;

            int ProductId = ProductGet(ProductAdditionallyPhotoReply);

            ProductFunction = new ProductFunction();

            var ProductPhoto = ProductFunction.InsertAdditionallPhoto(ProductId, await base.GetFileAsync(base.PhotoId), base.Caption);

            if (ProductPhoto != null && base.PhotoId != null)
            {
                TgAttach = AttachmentTelegramFunction.AddAttachmentTelegram(ProductPhoto.AttachmentFsId, BotInfo.Id, base.PhotoId);
            }

            var product = ProductFunction.GetProduct(ProductId);

            ProductFunction.Dispose();

            if (ProductPhoto != null && ProductPhoto.AttachmentFsId > 0 && TgAttach != null && TgAttach.Id > 0)
            {
                await SendMessage(new BotMessage { TextMessage = "Добавлено" });
            }

            return(await SendProductFunc(product));
        }
コード例 #5
0
        private async Task <IActionResult> UpdCategory()
        {
            string product_name = OriginalMessage.Substring(EnterCategoryForceReply.Length);

            string category_name = ReplyToMessageText;

            var category = CategoryFunction.GetCategory(category_name);

            var category_list = CategoryList();

            ProductFunction = new ProductFunction();

            Product = ProductFunction.GetProduct(product_name);


            if (category == null)
            {
                category = CategoryFunction.InsertCategory(category_name);
            }

            if (category != null && Product != null)
            {
                Product = ProductFunction.GetProduct(product_name);

                ProductFunction.UpdateCategory(Product.Id, category.Id);

                ProductFunction.Dispose();

                return(await SendTextMessageAndForceReply("Введите краткое описание вашего товара. Максмимум 100 символов",
                                                          EnterTextForceReply + Product.Name));
            }

            else
            {
                ProductFunction.Dispose();
                return(await SendTextMessageAndForceReply("Введите название новой категории или выберите уже существующую."
                                                          + "Список категорий:" + category_list, EnterCategoryForceReply + product_name));
            }
        }
コード例 #6
0
        private async Task <IActionResult> UpdUnit()
        {
            string product_name = OriginalMessage.Substring(EnterUnitForceReply.Length);

            string unit_name = ReplyToMessageText.Trim();

            var UnitList = UnitsList();

            ProductFunction = new ProductFunction();

            var product = ProductFunction.GetProduct(product_name);

            var Unit = UnitsFunction.GetUnits(unit_name);

            ProductFunction = new ProductFunction();

            if (Unit != null && product != null)
            {
                product = ProductFunction.UpdateUnit(product.Id, Unit.Id);
                ProductFunction.Dispose();
            }

            if (Unit == null && product != null) // пользваотель указа ед. измерения но ее не удалось найти. Выбираем первую из существующих
            {
                var list = UnitsFunction.UnitsList();
                await SendMessage(new BotMessage { TextMessage = "Не удалось найти еденицу измерения. Выбрано:" + list.FirstOrDefault().Name });

                product = ProductFunction.UpdateUnit(product.Id, list.FirstOrDefault().Id);
                ProductFunction.Dispose();
            }

            if (product != null && product.UnitId > 0)
            {
                return(await SendTextMessageAndForceReply(product.Name + " /adminproduct" + product.Id, EnterPriceForceReply + product.Name));
            }


            else
            {
                return(await SendTextMessageAndForceReply(product.Name + " /adminproduct" + product.Id +
                                                          " Еденицы измерения:" + UnitList, EnterUnitForceReply + product.Name));
            }
        }
コード例 #7
0
        public IActionResult Editor(int id)
        {
            ProductFunc = new ProductFunction();

            if (id > 0)
            {
                var product = ProductFunc.GetProduct(id);

                if (product.MainPhotoNavigation != null) // вытаскиваем главную фотографию и готовим ее к отображению на странице
                {
                    string imageBase64Data = Convert.ToBase64String(product.MainPhotoNavigation.Fs);
                    string imageDataURL    = string.Format("data:image/png;base64,{0}", imageBase64Data);
                    ViewBag.ImageData = imageDataURL;
                }

                ViewBag.Category = new SelectList(CategoryFunction.GetListCategory(), "Id", "Name", product.CategoryId);

                ViewBag.Currency = CurrencyFunction.CurrencyList();

                ViewBag.Unit = new SelectList(UnitsFunction.UnitsList(), "Id", "Name", product.UnitId);

                ProductFunc.Dispose();

                if (product != null)
                {
                    return(View(product));
                }

                else
                {
                    return(NoContent());
                }
            }



            else
            {
                return(null);
            }
        }
コード例 #8
0
        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));
                }
            }
        }
コード例 #9
0
        private async Task <IActionResult> UpdPhoto()
        {
            ProductFunction = new ProductFunction();

            string product_name = OriginalMessage.Substring(UploadImageForceReply.Length);

            Product = ProductFunction.GetProduct(product_name);

            int ProductId = -1;

            if (base.PhotoId != null && Product != null)
            {
                int FsId = await InsertToAttachmentFs(base.PhotoId);

                Product = ProductFunction.UpdateMainPhoto(Product.Id, FsId);
                AttachmentTelegramFunction.AddAttachmentTelegram(FsId, base.BotInfo.Id, base.PhotoId);
                ProductFunction.Dispose();
                ProductId = Product.Id;
            }

            if (Product != null) // удалось загрузить файл
            {
                ProductFuncMsg = new ProductFuncMessage(Product);
                await SendMessage(ProductFuncMsg.BuildMsg());
            }

            else
            {
                await SendMessage(new BotMessage { TextMessage = "Не удалось загрузить файл!" });

                ProductFuncMsg = new ProductFuncMessage(ProductId);
                await SendMessage(ProductFuncMsg.BuildMsg());
            }

            return(OkResult);
        }