public ResponseModel BulkUploadCategory(IFormFile File, int CategoryFor = 1) { string downloadFilePath = string.Empty; string bulkUploadFilesPath = string.Empty; bool errorfilesaved = false; bool successFilesaved = false; int count = 0; MasterCaller masterCaller = new MasterCaller(); SettingsCaller fileU = new SettingsCaller(); ResponseModel objResponseModel = new ResponseModel(); int statusCode = 0; string statusMessage = ""; DataSet dataSetCSV = new DataSet(); string fileName = ""; string finalAttchment = ""; string timeStamp = DateTime.Now.ToString("ddmmyyyyhhssfff"); string[] filesName = null; List <string> CSVlist = new List <string>(); try { var files = Request.Form.Files; if (files.Count > 0) { for (int i = 0; i < files.Count; i++) { fileName += files[i].FileName.Replace(".", timeStamp + ".") + ","; } finalAttchment = fileName.TrimEnd(','); } var Keys = Request.Form; var exePath = Path.GetDirectoryName(System.Reflection .Assembly.GetExecutingAssembly().CodeBase); Regex appPathMatcher = new Regex(@"(?<!fil)[A-Za-z]:\\+[\S\s]*?(?=\\+bin)"); var appRoot = appPathMatcher.Match(exePath).Value; string Folderpath = appRoot + "\\" + UploadedBulkFile; if (files.Count > 0) { filesName = finalAttchment.Split(","); for (int i = 0; i < files.Count; i++) { using (var ms = new MemoryStream()) { files[i].CopyTo(ms); var fileBytes = ms.ToArray(); MemoryStream msfile = new MemoryStream(fileBytes); FileStream docFile = new FileStream(Folderpath + "\\" + filesName[i], FileMode.Create, FileAccess.Write); msfile.WriteTo(docFile); docFile.Close(); ms.Close(); msfile.Close(); string s = Convert.ToBase64String(fileBytes); byte[] a = Convert.FromBase64String(s); // act on the Base64 data } } } string token = Convert.ToString(Request.Headers["X-Authorized-Token"]); Authenticate authenticate = new Authenticate(); authenticate = SecurityService.GetAuthenticateDataFromTokenCache(Cache, SecurityService.DecryptStringAES(token)); #region FilePath bulkUploadFilesPath = appRoot + "\\" + "BulkUpload\\UploadFiles" + "\\" + CommonFunction.GetEnumDescription((EnumMaster.FileUpload)CategoryFor); downloadFilePath = appRoot + "\\" + "BulkUpload\\DownloadFiles" + "\\" + CommonFunction.GetEnumDescription((EnumMaster.FileUpload)CategoryFor); #endregion dataSetCSV = CommonService.csvToDataSet(Folderpath + "\\" + finalAttchment); CSVlist = masterCaller.CategoryBulkUpload(new CategoryServices(Cache, Db), authenticate.TenantId, authenticate.UserMasterID, CategoryFor, dataSetCSV); #region Create Error and Succes files and Insert in FileUploadLog if (!string.IsNullOrEmpty(CSVlist[0])) { errorfilesaved = CommonService.SaveFile(downloadFilePath + "\\Category\\ Error" + "\\" + "CategoryErrorFile.csv", CSVlist[0]); } if (!string.IsNullOrEmpty(CSVlist[1])) { successFilesaved = CommonService.SaveFile(downloadFilePath + "\\Category\\Success" + "\\" + "CategorySuccessFile.csv", CSVlist[1]); } count = fileU.CreateFileUploadLog(new FileUploadService(Cache, Db), authenticate.TenantId, "Categorymaster.csv", errorfilesaved, "CategoryErrorFile.csv", "CategorySuccessFile.csv", authenticate.UserMasterID, "Category", downloadFilePath + "\\Category\\Error" + "\\" + "CategoryErrorFile.csv", downloadFilePath + "\\Category\\ Success" + "\\" + "CategorySuccessFile.csv", CategoryFor ); #endregion statusCode = count > 0 ? (int)EnumMaster.StatusCode.Success : (int)EnumMaster.StatusCode.RecordNotFound; statusMessage = CommonFunction.GetEnumDescription((EnumMaster.StatusCode)statusCode); objResponseModel.Status = true; objResponseModel.StatusCode = statusCode; objResponseModel.Message = statusMessage; objResponseModel.ResponseData = CSVlist.Count; } catch (Exception) { throw; } return(objResponseModel); }
public ResponseModel BulkUploadUser(int UserFor) { string downloadFilePath = string.Empty; string bulkUploadFilesPath = string.Empty; bool errorFileSaved = false; bool successfilesaved = false; int count = 0; UserCaller userCaller = new UserCaller(); SettingsCaller fileU = new SettingsCaller(); ResponseModel objResponseModel = new ResponseModel(); int statusCode = 0; string statusMessage = ""; string fileName = ""; string finalAttchment = ""; string timeStamp = DateTime.Now.ToString("ddmmyyyyhhssfff"); DataSet dataSetCSV = new DataSet(); string[] filesName = null; List <string> CSVlist = new List <string>(); string successFileName = string.Empty, errorFileName = string.Empty; string errorFilePath = string.Empty; string successFilePath = string.Empty; try { var files = Request.Form.Files; string token = Convert.ToString(Request.Headers["X-Authorized-Token"]); Authenticate authenticate = new Authenticate(); authenticate = SecurityService.GetAuthenticateDataFromTokenCache(Cache, SecurityService.DecryptStringAES(token)); #region FilePath bulkUploadFilesPath = rootPath + "\\" + "BulkUpload\\UploadFiles" + "\\" + CommonFunction.GetEnumDescription((EnumMaster.FileUpload)UserFor); downloadFilePath = rootPath + "\\" + "BulkUpload\\DownloadFiles" + "\\" + CommonFunction.GetEnumDescription((EnumMaster.FileUpload)UserFor); #endregion #region Read from Form if (files.Count > 0) { for (int i = 0; i < files.Count; i++) { fileName += files[i].FileName.Replace(".", timeStamp + ".") + ","; } finalAttchment = fileName.TrimEnd(','); } //var exePath = Path.GetDirectoryName(System.Reflection // .Assembly.GetExecutingAssembly().CodeBase); //Regex appPathMatcher = new Regex(@"(?<!fil)[A-Za-z]:\\+[\S\s]*?(?=\\+bin)"); //var appRoot = appPathMatcher.Match(exePath).Value; //string Folderpath = appRoot + "\\" + "UploadFiles"+"\\"+ CommonFunction.GetEnumDescription((EnumMaster.FIleUpload)HierarchyFor); if (files.Count > 0) { filesName = finalAttchment.Split(","); for (int i = 0; i < files.Count; i++) { using (var ms = new MemoryStream()) { files[i].CopyTo(ms); var fileBytes = ms.ToArray(); MemoryStream msfile = new MemoryStream(fileBytes); FileStream docFile = new FileStream(bulkUploadFilesPath + "\\" + filesName[i], FileMode.Create, FileAccess.Write); msfile.WriteTo(docFile); docFile.Close(); ms.Close(); msfile.Close(); } } } #endregion dataSetCSV = CommonService.csvToDataSet(bulkUploadFilesPath + "\\" + filesName[0]); //dataSetCSV = CommonService.csvToDataSet("D:\\TP\\UserBulk.csv"); CSVlist = userCaller.UserBulkUpload(new UserServices(Cache, Db), authenticate.TenantId, authenticate.UserMasterID, UserFor, dataSetCSV); #region Create Error and Succes files and Insert in FileUploadLog if (!string.IsNullOrEmpty(CSVlist[0])) { if (CSVlist[0].ToLower().Contains("username")) { successFileName = "UserSuccessFile.csv"; successFilePath = downloadFilePath + "\\User\\ Success" + "\\" + successFileName; successfilesaved = CommonService.SaveFile(successFilePath, CSVlist[0]); } else { successFileName = "MappedCategorySuccessFile.csv"; successFilePath = downloadFilePath + "\\MappedCategory\\ Success" + "\\" + successFileName; successfilesaved = CommonService.SaveFile(successFilePath, CSVlist[0]); } } if (!string.IsNullOrEmpty(CSVlist[1])) { if (CSVlist[1].ToLower().Contains("username")) { errorFileName = "UserErrorFile.csv"; errorFilePath = downloadFilePath + "\\User\\ Error" + "\\" + errorFileName; errorFileSaved = CommonService.SaveFile(errorFilePath, CSVlist[0]); } else { errorFileName = "MappedCategoryErrorFile.csv"; errorFilePath = downloadFilePath + "\\MappedCategory\\ Error" + "\\" + errorFileName; errorFileSaved = CommonService.SaveFile(errorFilePath, CSVlist[0]); } } if (!string.IsNullOrEmpty(CSVlist[1])) { errorFileSaved = CommonService.SaveFile(downloadFilePath + "\\User\\Error" + "\\" + "UserErrorFile.csv", CSVlist[1]); } count = fileU.CreateFileUploadLog(new FileUploadService(Cache, Db), authenticate.TenantId, filesName[0], successfilesaved, errorFileName, successFileName, authenticate.UserMasterID, "User", errorFilePath, successFilePath, UserFor); #endregion statusCode = count > 0 ? (int)EnumMaster.StatusCode.Success : (int)EnumMaster.StatusCode.RecordNotFound; statusMessage = CommonFunction.GetEnumDescription((EnumMaster.StatusCode)statusCode); objResponseModel.Status = true; objResponseModel.StatusCode = statusCode; objResponseModel.Message = statusMessage; objResponseModel.ResponseData = count; } catch (Exception) { throw; } return(objResponseModel); }
public ResponseModel BulkUploadUser(int UserFor = 1) { string DownloadFilePath = string.Empty; string BulkUploadFilesPath = string.Empty; bool errorfilesaved = false; bool successfilesaved = false; int count = 0; UserCaller userCaller = new UserCaller(); SettingsCaller fileU = new SettingsCaller(); ResponseModel objResponseModel = new ResponseModel(); int StatusCode = 0; string statusMessage = ""; string fileName = ""; string finalAttchment = ""; string timeStamp = DateTime.Now.ToString("ddmmyyyyhhssfff"); DataSet DataSetCSV = new DataSet(); string[] filesName = null; List <string> CSVlist = new List <string>(); string successfilename = string.Empty, errorfilename = string.Empty; string errorfilepath = string.Empty; string successfilepath = string.Empty; try { var files = Request.Form.Files; if (files.Count > 0) { for (int i = 0; i < files.Count; i++) { fileName += files[i].FileName.Replace(".", timeStamp + ".") + ","; } finalAttchment = fileName.TrimEnd(','); } var Keys = Request.Form; string token = Convert.ToString(Request.Headers["X-Authorized-Token"]); Authenticate authenticate = new Authenticate(); authenticate = SecurityService.GetAuthenticateDataFromToken(_radisCacheServerAddress, SecurityService.DecryptStringAES(token)); #region FilePath string Folderpath = Directory.GetCurrentDirectory(); filesName = finalAttchment.Split(","); BulkUploadFilesPath = Path.Combine(Folderpath, BulkUpload, UploadFiles, CommonFunction.GetEnumDescription((EnumMaster.FileUpload)UserFor)); DownloadFilePath = Path.Combine(Folderpath, BulkUpload, DownloadFile, CommonFunction.GetEnumDescription((EnumMaster.FileUpload)UserFor)); if (!Directory.Exists(BulkUploadFilesPath)) { Directory.CreateDirectory(BulkUploadFilesPath); } if (files.Count > 0) { for (int i = 0; i < files.Count; i++) { using (var ms = new MemoryStream()) { files[i].CopyTo(ms); var fileBytes = ms.ToArray(); MemoryStream msfile = new MemoryStream(fileBytes); FileStream docFile = new FileStream(Path.Combine(BulkUploadFilesPath, filesName[i]), FileMode.Create, FileAccess.Write); msfile.WriteTo(docFile); docFile.Close(); ms.Close(); msfile.Close(); string s = Convert.ToBase64String(fileBytes); byte[] a = Convert.FromBase64String(s); // act on the Base64 data } } } #endregion DataSetCSV = CommonService.csvToDataSet(Path.Combine(BulkUploadFilesPath, filesName[0])); CSVlist = userCaller.UserBulkUpload(new UserServices(_connectioSting), authenticate.TenantId, authenticate.UserMasterID, UserFor, DataSetCSV); #region Create Error and Success files and Insert in FileUploadLog string SuccessFileName = "UserSuccessFile_" + timeStamp + ".csv"; string ErrorFileName = "UserErrorFile_" + timeStamp + ".csv"; string SuccessFileUrl = rootPath + BulkUpload + "/" + DownloadFile + "/" + CommonFunction.GetEnumDescription((EnumMaster.FileUpload)UserFor) + "/Success/" + SuccessFileName; string ErrorFileUrl = rootPath + BulkUpload + "/" + DownloadFile + "/" + CommonFunction.GetEnumDescription((EnumMaster.FileUpload)UserFor) + "/Error/" + ErrorFileName; if (!string.IsNullOrEmpty(CSVlist[0])) { if (!CSVlist[0].ToLower().Contains("username")) { SuccessFileName = "MappedCategorySuccessFile_" + timeStamp + ".csv"; } successfilesaved = CommonService.SaveFile(Path.Combine(DownloadFilePath, "Success", SuccessFileName), CSVlist[0]); } if (!string.IsNullOrEmpty(CSVlist[1])) { if (!CSVlist[1].ToLower().Contains("username")) { ErrorFileName = "MappedCategoryErrorFile" + timeStamp + ".csv"; } errorfilesaved = CommonService.SaveFile(Path.Combine(DownloadFilePath, "Error", ErrorFileName), CSVlist[1]); } count = fileU.CreateFileUploadLog(new FileUploadService(_connectioSting), authenticate.TenantId, filesName[0], errorfilesaved, ErrorFileName, SuccessFileName, authenticate.UserMasterID, "User", SuccessFileUrl, ErrorFileUrl, UserFor); #endregion StatusCode = count > 0 ? (int)EnumMaster.StatusCode.Success : (int)EnumMaster.StatusCode.RecordNotFound; statusMessage = CommonFunction.GetEnumDescription((EnumMaster.StatusCode)StatusCode); objResponseModel.Status = true; objResponseModel.StatusCode = StatusCode; objResponseModel.Message = statusMessage; objResponseModel.ResponseData = count; } catch (Exception) { throw; } return(objResponseModel); }