public ActionResult EditProduct(ProductCategoryViewModel pcvm, string id) { try { if (ModelState.IsValid) { if (pcvm.ImageFileProduct == null) { try { pp.EditVendorProductPost(pcvm); return(RedirectToAction("ViewAllProducts", "Product")); } catch (Exception exd) { TempData["ProRegMsg"] = "Product Updation Failed - " + exd.Message; return(RedirectToAction("EditProductGet", "Product")); } } else { int bytecount = pcvm.ImageFileProduct.ContentLength; if (bytecount > 0 && bytecount <= 5000000) { string fileName = Path.GetFileNameWithoutExtension(pcvm.ImageFileProduct.FileName); string extension = Path.GetExtension(pcvm.ImageFileProduct.FileName); if (extension == ".jpg" || extension == ".jpeg" || extension == ".png" || extension == ".JPG" || extension == ".JPEG" || extension == ".PNG" && ModelState.IsValid) { fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; pcvm.ProImg_Name = fileName; pcvm.ProImg_Path = "~/Content/Pictures/VendorProductImages/" + fileName; fileName = Path.Combine(Server.MapPath("~/Content/Pictures/VendorProductImages/"), fileName); pcvm.ImageFileProduct.SaveAs(fileName); //ProductPresenter.EditVendorProductPost(pcvm); TempData["ProRegMsg"] = "Product Entered Successfully."; ModelState.Clear(); return(RedirectToAction("ViewAllProducts", "Product")); } else { TempData["ModelError"] = "Only .jpg , .jpeg & .png file supported."; return(RedirectToAction("EditProductGet", "Product")); } } else { TempData["ModelError"] = "File size must be less than 5MB."; return(RedirectToAction("EditProductGet", "Product")); } } } return(RedirectToAction("EditProductGet", "Product")); } catch (Exception ex) { TempData["ProRegMsg"] = "Product Updation Failed - " + ex.Message; return(RedirectToAction("EditProductGet", "Product")); } }