Ejemplo n.º 1
0
        public ActionResult Edit(int id, ProductEditViewModel model, HttpPostedFileBase ImageFile)
        {
            try
            {
                // TODO: Add update logic here
                ProductDO dataModel = new ProductDO();
                dataModel.Product_ID   = model.Product_ID;
                dataModel.Product_Name = model.Product_Name;
                dataModel.Price        = model.Price;
                //dataModel.Category_ID = model.Category_ID;
                dataModel.SubCategory_ID = model.SubCategory_ID;
                dataModel.Brand_ID       = model.Brand_ID;
                dataModel.Size           = model.Size;
                dataModel.Color          = model.Color;


                if (ImageFile == model.ImageFile)
                {
                    dataModel.Product_Image = TempData["ImagesPath"].ToString();
                    //dataModel.Product_Image = model.Product_Image;
                    dataModel.Description = model.Description;
                    dataModel.Quantity    = model.Quantity;

                    ProductManagement productManagement = new ProductManagement();
                    productManagement.EditProduct(dataModel);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    string FileName   = Path.GetFileName(model.ImageFile.FileName);
                    string UploadPath = ConfigurationManager.AppSettings["ImagesPath"].ToString();
                    model.Product_Image = UploadPath + FileName;
                    model.ImageFile.SaveAs(Server.MapPath((model.Product_Image)));
                    dataModel.Product_Image = model.Product_Image;
                    dataModel.Description   = model.Description;
                    dataModel.Quantity      = model.Quantity;

                    ProductManagement productManagement = new ProductManagement();
                    productManagement.EditProduct(dataModel);

                    return(RedirectToAction("Index"));
                }
                //dataModel.Product_Image = model.Product_Image;
            }
            catch (Exception e)
            {
                model.SubCategories = getSubCategoryDropDownData();
                model.Brands        = getBrandDropDownData();
                return(View(model));
            }
        }