Exemplo n.º 1
0
        public ActionResult Index(ProductModel data, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null && file.ContentLength > 0)
                {
                    string absolutePathOfImagesFolder = Server.MapPath("\\Images");
                    string filename = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName);
                    file.SaveAs(absolutePathOfImagesFolder + "\\" + filename);

                    ProductsBL pbl = new ProductsBL();
                    pbl.AddProduct(data.ProductName, HttpContext.User.Identity.Name, data.Description, data.Price, "\\Images\\" + filename, data.StockQty, data.CategoryID);
                    return(RedirectToAction("Index", "ViewSellerProduct")); //redirect to view products page
                }
            }
            return(View());
        }