Exemplo n.º 1
0
        [HttpPost]//posting to the view
        public ActionResult AddProductCategory(ProductCatogeryModel productCategoryModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string filename  = Path.GetFileNameWithoutExtension(productCategoryModel.ImageUpload.FileName);
                    string extension = Path.GetExtension(productCategoryModel.ImageUpload.FileName);
                    filename = filename + DateTime.Now.ToString("yymmssfff") + extension;
                    productCategoryModel.ProductImagePath = filename;
                    OnlineJewellShop.Entity.ProductCatogeries productCategoryMap = AutoMapper.Mapper.Map <ProductCatogeryModel, ProductCatogeries>(productCategoryModel);
                    filename = Path.Combine(Server.MapPath("~/ProductCatogeryImages/"), filename);
                    if (extension == ".jpg" || extension == ".png")
                    {
                        productCategoryModel.ImageUpload.SaveAs(filename);
                        int result = productCategoryDetails.AddProductCategory(productCategoryMap);

                        if (result > 0)
                        {
                            return(RedirectToAction("ViewProductCategory"));
                        }
                    }
                    else
                    {
                        ViewBag.AddImage = "Selected file is not in the correct format please select image file";
                    }
                    return(View());
                }
                return(View());
            }
            catch
            {
                return(RedirectToAction("Error", "Error"));
            }
        }//view the category to the admin
Exemplo n.º 2
0
        [HttpPost]//posting to the view
        public ActionResult EditProductCategory(ProductCatogeryModel productCategoryModel)
        {
            string filename = null;
            string extension;

            try
            {
                ViewBag.ProductCategories = new SelectList(productCategoryDetails.DisplayProduct(), "ProductCatogeryId", "productCatogeryName");
                if (productCategoryModel.ImageUpload == null)
                {
                    productCategoryModel.ProductImagePath = Convert.ToString(TempData["CatogeryImage"]);
                }
                else
                {
                    filename  = Path.GetFileNameWithoutExtension(productCategoryModel.ImageUpload.FileName);
                    extension = Path.GetExtension(productCategoryModel.ImageUpload.FileName);
                    filename  = filename + DateTime.Now.ToString("yymmssfff") + extension;
                    productCategoryModel.ProductImagePath = filename;
                }


                OnlineJewellShop.Entity.ProductCatogeries productCategoryMap = AutoMapper.Mapper.Map <ProductCatogeryModel, ProductCatogeries>(productCategoryModel);
                if (productCategoryDetails.UpdateProductCategory(productCategoryMap) > 0)
                {
                    if (productCategoryModel.ImageUpload != null)
                    {
                        filename = Path.Combine(Server.MapPath("~/ProductCatogeryImages/"), filename);
                        productCategoryModel.ImageUpload.SaveAs(filename);
                    }
                    return(RedirectToAction("ViewProductCategory"));
                }
                return(View());
            }

            catch
            {
                return(RedirectToAction("Error", "Error"));
            }
        }