public ActionResult DeleteProductSubCategory(Int64 Id) { ResponseModel _response = new ResponseModel(); var details = _productSubCategoryRepository.FindBy(x => x.ProductSubCategoryId == Id).FirstOrDefault(); details.IsDeleted = true; details.ModifiedDate = DateTime.Now; details.ModifiedBy = UserAuthenticate.UserId; bool IsTrue = _productSubCategoryRepository.EditProductSubCategory(details); if (IsTrue) { _response.Type = "success"; _response.Message = "Brand deleted successfully"; } else { _response.Type = "error"; _response.Message = "Somehing went wrong"; } return(Json(_response, JsonRequestBehavior.AllowGet)); }
public HttpResponseMessage EditProductSubCategory(ProductSubCategoryModel productSubCategoryModel) { ResponseModel _response = new ResponseModel(); var _getSubCategory = _productSubCategoryRepository.FindBy(x => x.ProductSubCategoryId != productSubCategoryModel.ProductSubCategoryId && x.ProductCategoryId == productSubCategoryModel.ProductCategoryId && x.ProductSubCategoryName.Trim().ToLower() == productSubCategoryModel.ProductSubCategoryName.Trim().ToLower() && x.Status == (int)Status.Active && x.IsDeleted == false).FirstOrDefault(); if (_getSubCategory != null) { _response.Type = "error"; _response.Message = "Brand already Exist"; return(Request.CreateResponse(HttpStatusCode.OK, _response)); } // var model = Mapper.Map<ProductSubCategoryModel, ProductSubCategory>(productSubCategoryModel); var _productSubCategory = _productSubCategoryRepository.FindBy(x => x.ProductSubCategoryId == productSubCategoryModel.ProductSubCategoryId).FirstOrDefault(); _productSubCategory.ProductSubCategoryId = productSubCategoryModel.ProductSubCategoryId; _productSubCategory.ProductCategoryId = productSubCategoryModel.ProductCategoryId; _productSubCategory.ProductSubCategoryName = productSubCategoryModel.ProductSubCategoryName; _productSubCategory.ModifiedBy = productSubCategoryModel.ModifiedBy; _productSubCategory.ModifiedDate = DateTime.Now; var IsResponse = _productSubCategoryRepository.EditProductSubCategory(_productSubCategory); if (IsResponse) { // For Uploading image ---- if (productSubCategoryModel.DocProductSubCategory != null) { UploadDocumentModel UploadDocument = new UploadDocumentModel(); UploadDocument.documents = new List <DocumentModel>(); UploadDocument.ImageSize = 250; UploadDocument.ImageQuality = 250; UploadDocument.documents.Add(productSubCategoryModel.DocProductSubCategory); List <string> uploadedFileName = SavePicture(UploadDocument); if (uploadedFileName.Count > 0) { if (_productSubCategory != null) { // delete exiting images string ImgPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Images/UploadImg/" + _productSubCategory.ProductSubCategoryImagePath); if (System.IO.File.Exists(ImgPath)) { System.IO.File.Delete(ImgPath); } string ImgOriginalPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Images/UploadImg/" + "Original_" + _productSubCategory.ProductSubCategoryImagePath); if (System.IO.File.Exists(ImgOriginalPath)) { System.IO.File.Delete(ImgOriginalPath); } string TImgPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Images/UploadImg/" + "T" + _productSubCategory.ProductSubCategoryImagePath); if (System.IO.File.Exists(TImgPath)) { System.IO.File.Delete(TImgPath); } //------------------------------ _productSubCategory.ProductSubCategoryImagePath = uploadedFileName[0].ToString(); _productSubCategoryRepository.Update(_productSubCategory); _productSubCategoryRepository.SaveChanges(); } } } _response.Type = "success"; _response.Message = "Brand updated successfully"; return(Request.CreateResponse(HttpStatusCode.OK, _response)); } else { _response.Type = "error"; _response.Message = "Something went wrong"; return(Request.CreateResponse(HttpStatusCode.OK, _response)); } }