public JsonResult AddOrEditProductCategory(ProductCategoryViewModel model) { try { if (model.IsAdd) { ProductCategory cate = new ProductCategory { FolderName = model.FolderName, ProductCategoryName = model.ProductCategoryName, CreatedDate = DateTime.Now }; _prodCateService.AddProductCategory(cate); ProductCategoryExtend cateEx = new ProductCategoryExtend { ProductCategoryId = cate.ProductCategoryId, FileName = model.FileUpload.FileName, FileSize = model.FileUpload.ContentLength, FilePath = Util.CreateProductCategoryImage(model.FileUpload, User.Identity.GetUserId()) }; _prodCateService.AddProductCategoryExtend(cateEx); var category = new { ProductCategoryName = cate.ProductCategoryName, FilePath = cate.ProductCategoryExtend.FilePath, ProductCategoryId = cate.ProductCategoryId, FolderName = cate.FolderName }; return(Json(new { success = true, category = category, IsAdd = true })); //return Json(true); } else { var cate = _prodCateService.GetProductCategoryById(model.ProductCategoryId); if (model.FileUpload == null) { cate.ProductCategoryName = model.ProductCategoryName; _prodCateService.Save(); } else { Util.DeleteFileLocal(cate.ProductCategoryExtend.FilePath); cate.ProductCategoryExtend.FilePath = Util.CreateProductCategoryImage(model.FileUpload, User.Identity.GetUserId()); cate.ProductCategoryExtend.FileName = model.FileUpload.FileName; cate.ProductCategoryExtend.FileSize = model.FileUpload.ContentLength; cate.ProductCategoryName = model.ProductCategoryName; _prodCateService.Save(); } var category = new { ProductCategoryName = cate.ProductCategoryName, FilePath = cate.ProductCategoryExtend.FilePath, ProductCategoryId = cate.ProductCategoryId, FolderName = cate.FolderName }; return(Json(new { success = true, category = category, IsAdd = false })); } } catch { return(Json(new { success = false })); } }