public ContentResult SaveExcel(string item) { //string b = Request["item"]; JsonObject obj = new JsonObject(); try { IEnumerable <T_CMS_Master_Contract> objItemList = JsonConvert.DeserializeObject <IEnumerable <T_CMS_Master_Contract> >(item, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); obj.StatusCode = 200; obj.Message = "The process is sucessed"; T_CMS_Master_ContractCollection ErrorList = T_CMS_Master_ContractManager.ImportData(objItemList, CurrentUser.EmployeeCode); obj.Data = ErrorList; if (ErrorList.Count > 0) { obj.StatusCode = 400; obj.Message = "Can't import into system :" + ErrorList.Count + "/" + objItemList.Count <T_CMS_Master_Contract>(); } } catch (Exception objEx) { obj.StatusCode = 400; obj.Message = objEx.Message; } return(Content(JsonConvert.SerializeObject(obj), "application/json")); }
/// <summary> /// Upload The Excel File /// </summary> /// <returns></returns> public ContentResult ImportExcelFile() { JsonObject obj = new JsonObject(); HttpPostedFileBase file = Request.Files[0] as HttpPostedFileBase; // string fileName = file.FileName; // string fileContentType = file.ContentType; // byte[] fileBytes = new byte[file.ContentLength]; // var data = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength)); //DataTable dt = ExcelHelper.getClassFromExcelPackage<EPPosition>(file.InputStream, 2,1); obj.StatusCode = 200; obj.Message = "Upload Success"; try { DataTable dt = ExcelHelper.ToDataTable(file.InputStream); IEnumerable <T_CMS_Master_Contract> objItemList = dt.ToList <T_CMS_Master_Contract>(); // CommonHelper.SaveImportFile<T_CMS_Master_Contract>(CurrentUser, "T_CMS_Master_Contract", file.FileName, objItemList); T_CMS_Master_ContractCollection ErrorList = T_CMS_Master_ContractManager.ImportData(objItemList, CurrentUser.EmployeeCode); if (ErrorList.Count > 0) { obj.Data = ErrorList; } if (ErrorList.Count > 0) { CommonHelper.SaveImportErrorFile <T_CMS_Master_Contract>(CurrentUser, "T_CMS_Master_Contract", ErrorList); obj.StatusCode = 400; obj.Message = "Can't import into system :" + ErrorList.Count + "/" + objItemList.Count <T_CMS_Master_Contract>(); } //obj.Data = dt; } catch (Exception objEx) { obj.StatusCode = 400; obj.Message = objEx.Message; } return(Content(JsonConvert.SerializeObject(obj), "application/json")); }