예제 #1
0
        public ActionResult Edit(ProductCategoryRelation pcr, int id, HttpPostedFileBase file)
        {
            try
            {
                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    file.SaveAs(Server.MapPath("~/Images/" + fileName));
                    pcr.product.Picture = WebConfigurationManager.AppSettings["ImageUpload"] + fileName;
                }

                pcr.product.ProductId = id;

                pcr.categories            = LetsShopImplementation.GetCategoryIdByName(pcr.categories.CategoryName, pcr.categories.SubCategoryName);
                pcr.product.CategoryId    = pcr.categories.CategoryId;
                pcr.product.SubCategoryId = pcr.categories.SubCategoryId;

                LetsShopImplementation.UpdateProduct(pcr.product);

                //cache.Add("ProductData", LetsShopImplementation.GetProducts(),
                //                   CacheItemPriority.High, null, absolutetime);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
예제 #2
0
        public ActionResult CreateProduct(ProductCategoryRelation pcr, HttpPostedFileBase file)
        {
            try
            {
                if (file != null && file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    file.SaveAs(Server.MapPath("~/Images/" + fileName));
                    pcr.product.Picture = WebConfigurationManager.AppSettings["ImageUpload"] + fileName;
                }
                else
                {
                    pcr.product.Picture = WebConfigurationManager.AppSettings["ImageUpload"] + "defaultimage.jpg";
                }


                pcr.categories            = LetsShopImplementation.GetCategoryIdByName(pcr.categories.CategoryName, pcr.categories.SubCategoryName);
                pcr.product.CategoryId    = pcr.categories.CategoryId;
                pcr.product.SubCategoryId = pcr.categories.SubCategoryId;

                LetsShopImplementation.CreateProduct(pcr.product);

                cache.Add("ProductData", LetsShopImplementation.GetProducts(),
                          CacheItemPriority.High, null, absolutetime);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, "UI Policy");
                if (rethrow)
                {
                    throw;
                }
                return(View());
            }
        }