[HttpPost]//posting to the view public ActionResult EditProduct(ProductModel image) { string filename = null; string extension; ViewBag.ProductCategories = new SelectList(productCategoryDetails.DisplayProduct(), "ProductCatogeryId", "productCatogeryName"); if (image.ImageUpload == null) { image.ProductImagePath = Convert.ToString(TempData["Image"]); } else { filename = Path.GetFileNameWithoutExtension(image.ImageUpload.FileName); extension = Path.GetExtension(image.ImageUpload.FileName); filename = filename + DateTime.Now.ToString("yymmssfff") + extension; image.ProductImagePath = filename; } OnlineJewellShop.Entity.Product productMap = AutoMapper.Mapper.Map <ProductModel, Product>(image); if (productDetails.UpdateProduct(productMap) > 0) { if (image.ImageUpload != null) { filename = Path.Combine(Server.MapPath("~/ProductImages/"), filename); image.ImageUpload.SaveAs(filename); } return(RedirectToAction("ViewProduct")); } return(View()); }
[HttpPost]//posting to the view public ActionResult AddProduct(ProductModel image) { try { ViewBag.ProductCategories = new SelectList(productCategoryDetails.DisplayProduct(), "ProductCatogeryId", "productCatogeryName"); if (ModelState.IsValid) { string filename = Path.GetFileNameWithoutExtension(image.ImageUpload.FileName); string extension = Path.GetExtension(image.ImageUpload.FileName); filename = filename + DateTime.Now.ToString("yymmssfff") + extension; image.ProductImagePath = filename; OnlineJewellShop.Entity.Product productMap = AutoMapper.Mapper.Map <ProductModel, Product>(image); filename = Path.Combine(Server.MapPath("~/ProductImages/"), filename); if (extension == ".jpg" || extension == ".png") { image.ImageUpload.SaveAs(filename); int result = productDetails.AddProduct(productMap); if (result > 0) { return(RedirectToAction("ViewProduct")); } } else { ViewBag.Image = "Selected file is not in the correct format please select image file"; } } return(View()); } catch { return(RedirectToAction("Error", "Error")); } }