public virtual async Task <ActionResult <ProductResponse> > Post(T model)
        {
            //Create logs here
            var result = await _productBL.AddProduct <T>(model);

            //Check if result does not return any products then instead of Ok, return Not Found
            return(Ok(result));
        }
 public bool AddProduct([FromBody] ProductViewModel product)
 {
     try
     {
         return(_productBusiness.AddProduct(product));
     }
     catch (InvalidProductException ex)
     {
         throw ex;
     }
 }
        // POST: api/Product
        public IHttpActionResult Post([FromBody] Product value)
        {
            var product = productBusiness.AddProduct(value);

            if (product != null)
            {
                return(Ok());
            }
            else
            {
                return(InternalServerError());
            }
        }
Exemplo n.º 4
0
        public ActionResult UploadNewProduct(String Title, String Description, HttpPostedFileBase photo)
        {
            HttpPostedFileBase photo2 = Request.Files["photo"];

            if (photo != null && photo.ContentLength > 0)
            {
                if (photo.ContentLength > maxImageSize)
                {
                    ViewBag.Error = "Image File size should be less than 5MB.";
                    return(View());
                }

                var supportedTypes = new[] { "jpg", "jpeg", "png" };

                var fileExt = System.IO.Path.GetExtension(photo.FileName).Substring(1);

                if (!supportedTypes.Contains(fileExt))
                {
                    ViewBag.Error = "Invalid type. Only the following types (jpg, jpeg, png) are supported.";
                    return(View());
                }

                // check if file name already exists
                var fileName = Path.GetFileName(photo.FileName);
                var fileInfo = MakeUnique(Path.Combine(Server.MapPath("~/Images"), fileName));
                photo.SaveAs(fileInfo.ToString());

                // create model
                var model = new ProductViewModel()
                {
                    Description = Description,
                    Title       = Title,
                    ImageURL    = "/Images/" + fileInfo.Name
                };
                // save model to database
                var dbUpdateStatus = _productBuisness.AddProduct(ProductViewModel.Convert(model));

                if (dbUpdateStatus)
                {
                    // db update successful - redirect to list view
                    TempData["success"] = "Product Added Successful";
                    return(RedirectToAction("DisplayProducts"));
                }
                else
                {
                    // delete the image and show error saving to db msg
                }
            }
            ViewBag.Error = "Image Required.";
            return(View());
        }
Exemplo n.º 5
0
        public void TestAddProductExpectTrue()
        {
            var product = new ProductInput()
            {
                ProductId   = Guid.NewGuid(),
                ProductName = "SurfaceX",
                Quantity    = 100
            };
            var addProduct = productService.AddProduct(product);
            var valConv    = JsonConvert.DeserializeObject(addProduct.Content.ToString());
            var _result    = valConv.ToString() == "Success" ? true : false;

            Assert.True(_result);
        }
Exemplo n.º 6
0
        public ApplicationServiceResponse AddProduct(ProductViewModel model)
        {
            model.Validate();
            if (!model.IsValid)
            {
                return(BadRequest(model.GetValidationMessagesList()));
            }

            var product = _mapper.Map <Product>(model);

            _productBusiness.AddProduct(product);

            return(Ok(product));
        }
Exemplo n.º 7
0
        public ActionResult <string> AddProduct()
        {
            var data = HttpContext.Request.Form;
            var file = HttpContext.Request.Form.Files["Image"];

            IProductDTO productDTO = new ProductDTO();

            productDTO.Product_name        = data["Product_name"];
            productDTO.Product_category    = data["Product_category"];
            productDTO.Product_quantity    = Convert.ToInt32(data["Product_quantity"]);
            productDTO.Product_price       = Convert.ToDouble(data["Product_price"]);
            productDTO.Product_description = data["Product_description"];


            productDTO.Image = file;

            _productBusiness.AddProduct(productDTO);
            return(Ok(new { str = "success" }));
        }
Exemplo n.º 8
0
 public ContentResult AddProduct([FromBody] ProductInput productInput)
 {
     return(product.AddProduct(productInput));
 }
Exemplo n.º 9
0
 public IHttpActionResult Post([FromBody] ProductContract productContract)
 {
     return(Ok(_productBusiness.AddProduct(productContract)));
 }
Exemplo n.º 10
0
 public Guid AddProduct(Product product)
 {
     _productBusiness.AddProduct(product);
     return(product.Key);
 }
Exemplo n.º 11
0
        public IActionResult Add(AddProductDto addProduct)
        {
            _productBusiness.AddProduct(addProduct);

            return(RedirectToAction(nameof(Index)));
        }