Пример #1
0
        public ActionResult ProductAdmin(int productID, string productName, string description, int price, int categoryid, HttpPostedFileBase ImageURL)
        {
            if (ImageURL != null && ImageURL.ContentLength > 0)
            {
                // create file name mapping with product name
                var fileName = Path.GetFileName(ImageURL.FileName);
                // store the file inside ~/App_Data/uploads folder
                var path = Path.Combine(Server.MapPath("~/images"), fileName);
                checkFileExist(path);
                ImageURL.SaveAs(path);
            }
            ViewBag.Product = new Product()
            {
                ProductID   = productID,
                ProductName = productName,
                Description = description,
                Price       = price,
                CategoryID  = categoryid,
                ImageName   = Path.GetFileName(ImageURL.FileName)
            };
            HttpResult result = ProductAPIController.ProductMerge(ViewBag.Product);

            if (result.Result)
            {
                ViewBag.Success = true;
            }
            else
            {
                ViewBag.Error = result.Message;
            }
            ViewBag.CategoryList = CategoryAPIController.getAllCategoryAdmin();
            foreach (Category c in ViewBag.CategoryList)
            {
                if (c.CategoryID == ViewBag.Product.CategoryID)
                {
                    ViewBag.Product.CategoryName = c.CategoryName;
                }
            }
            return(View());
        }