public JsonResult Delete(Customer_VM Model) { if (CheckAccessDelete(Model.CurrentScreenID, "Customer")) { try { GetUserInfo(Model); if (Model.CustomerID > 0 && Model.CustomerID != null) { List <Customer_VM> vm = _CustomerRepo.GetData(Model); FolderFile_VM model = new FolderFile_VM(); if (vm.Count > 0) { model.FileID = vm[0].Logo; } string filePath = null; filePath = Path.Combine(Server.MapPath("~/" + WebConfigurationManager.AppSettings["CustomerLogo"])); var data = _CustomerRepo.Delete(Model); if (model.FileID != null) { new FileSystem().RemoveFile(model, filePath); } return(GetAddEditDeleteResponse(data, "Delete")); } } catch (Exception ex) { logger.Error("CustomerController_Delete Error: ", ex); return(GetAddEditErrorException(ex)); } } return(GetModelStateIsValidException(ViewData)); }
public JsonResult AddUpdateData() { var ModelJson = Request.Form["Model"]; Customer_VM Model = (Customer_VM)JsonConvert.DeserializeObject(ModelJson, (typeof(Customer_VM))); if (ModelState.IsValid && Model != null) { // Get all files from Request object HttpFileCollectionBase files = Request.Files; FolderFile_VM model = new FolderFile_VM(); model.ObjectType = "Customer"; string filePath = null; filePath = Path.Combine(Server.MapPath("~/" + WebConfigurationManager.AppSettings["CustomerLogo"])); FolderFile_VM vm = new Common.Utilities.Global.FolderFile_VM(); try { GetUserInfo(Model); var data = 0; if (Model.CustomerID == 0 || Model.CustomerID == null) { data = _CustomerRepo.Add(Model); model.ObjectInstanceID = data; for (int i = 0; i < files.Count; i++) { HttpPostedFileBase file = files[i]; model.FileSize = file.ContentLength; vm = new FileSystem().AddFile(model, file, filePath); } Model.CustomerID = Convert.ToInt16(data); Model.Logo = vm.FileID; if (files.Count > 0) { _CustomerRepo.UpdateCustomerLogo(Model); } return(GetAddEditDeleteResponse(data, "Add")); } else if (Model.CustomerID > 0) { data = _CustomerRepo.Update(Model); model.ObjectInstanceID = data; if (files.Count > 0) { for (int i = 0; i < files.Count; i++) { HttpPostedFileBase file = files[i]; model.FileSize = file.ContentLength; vm = new FileSystem().AddFile(model, file, filePath); } try { Model.Logo = vm.FileID; _CustomerRepo.UpdateCustomerLogo(Model); } catch (Exception) { } } return(GetAddEditDeleteResponse(data, "Update")); } } catch (Exception ex) { logger.Error("CustomerController_AddUpdateData Error: ", ex); return(GetAddEditErrorException(ex)); } } return(GetModelStateIsValidException(ViewData)); }