コード例 #1
0
        public async Task <IActionResult> Save(Product SaveProduct, IFormFile image = null, int balance = 0)
        {
            bool NameIsProhibited = false;

            BotInfo = Bot.GeneralFunction.GetBotInfo();

            ProductFunc = new ProductFunction();


            if (SaveProduct != null)
            {
                NameIsProhibited = ProductFunc.NameIsProhibited(SaveProduct.Name);
            }

            if (NameIsProhibited)
            {
                return(Json("Данное имя запрещено"));
            }

            if (SaveProduct != null && SaveProduct.CurrentPrice.Value <= 0)
            {
                return(Json("Стоимость должна быть больше 0"));
            }

            if (SaveProduct != null && SaveProduct.CategoryId < 1)
            {
                return(Json("Выбертие категорию"));
            }

            if (SaveProduct != null && SaveProduct.Text != null && SaveProduct.Text.Length > 100)
            {
                return(Json("Ошибка. Максимальная длина описания 100 символов"));
            }

            if (!NameIsProhibited && SaveProduct != null && SaveProduct.Id > 0) // обновление уже сущ. товара
            {
                await UpdateProduct(SaveProduct, image);

                ProductFunc.Dispose();
                return(new RedirectResult("Editor\\" + SaveProduct.Id));
            }

            ///добавление нового товара
            if (!NameIsProhibited && SaveProduct != null && SaveProduct.Name != null &&
                SaveProduct.Id == 0 && SaveProduct.CurrentPrice.Value > 0 && SaveProduct.CategoryId > 0)
            {
                int id = await CreateProduct(SaveProduct, image, balance);

                return(new RedirectResult("Editor\\" + id));
            }


            else
            {
                return(Json("Ошибка"));
            }
        }
コード例 #2
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));
                }
            }
        }