Exemplo n.º 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));
            }
        }
Exemplo n.º 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)));
        }
Exemplo n.º 3
0
        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));
            }
        }
Exemplo n.º 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));
        }
Exemplo n.º 5
0
 public async Task <IActionResult> AddNewProduct(Product newProduct)
 {
     return(Ok(await productService.AddNewProduct(newProduct)));
 }
Exemplo n.º 6
0
 public void AddNewProduct(Product product, string category)
 {
     productDao.AddNewProduct(product, category);
 }