Exemple #1
0
        public ActionResult Post(Product webProduct)
        {
            if (!_validator.ValidateTitle(webProduct))
            {
                ModelState.AddModelError("Title", "Название товара не должно быть пустым");
            }

            if (!_validator.ValidatePrice(webProduct))
            {
                ModelState.AddModelError("Price", "Цена товара должно быть больше или равна 1");
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                _products.AddNewProduct(webProduct);
                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemple #2
0
        public IActionResult Product(ProductViewModel product)
        {
            var model = new Product {
                Colour = product.Colour,
                Price  = product.Price,
                Sku    = product.Sku,
                Stock  = product.Stock,
                Style  = product.Style,
                Title  = product.Title
            };

            _ProductRepo.AddNewProduct(model);

            return(RedirectToAction(nameof(Product)));
        }
        public async Task <HttpResponseMessage> SaveProductDetails(ProductDetails product)
        {
            ProductModel prodModel = new ProductModel();

            try
            {
                await Task.Run(() =>
                {
                    prodModel = iproduct.AddNewProduct(product);
                });

                return(Request.CreateResponse(HttpStatusCode.OK, prodModel));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Exemple #4
0
        public ActionResult AddNewProduct(AddProductViewModel model, HttpPostedFileBase file)
        {
            try
            {
                if (file != null && file.ContentLength > 0)
                {
                    if (file.FileName != null)

                    {
                        model.AddImage = file;
                        if (ModelState.IsValid)
                        {
                            var res = iproduct.AddNewProduct(model, UserId);
                            if (res == "Success")
                            {
                                ViewBag.ModelMessage = model.ProductName + " Product Added";
                                return(View(model));
                            }
                            else
                            {
                                ViewBag.ModelMessage = "Error Occurred";
                                return(View(model));
                            }
                        }
                    }
                }
                else
                {
                    ViewBag.ModelMessage = "Please Upload an Image";
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                ViewBag.Message = "ERROR:" + ex.Message.ToString();
            }



            ViewBag.ModelMessage = "An Error Ocurred in Model";
            return(View(model));
        }
 public async Task <IActionResult> AddNewProduct(Product newProduct)
 {
     return(Ok(await productService.AddNewProduct(newProduct)));
 }
Exemple #6
0
 public void AddNewProduct(Product product, string category)
 {
     productDao.AddNewProduct(product, category);
 }