private void UpdateCallUploadDetail(CallUpload callUpload, List <CallUploadLog> failedCustomerList, string fileName) { if (failedCustomerList.Any()) { try { var location = _mediaRepository.GetCallUploadMediaFileLocation(); var failedFilePath = location.PhysicalPath + Path.GetFileNameWithoutExtension(fileName) + "_FailedCustomer.csv"; var modelData = Mapper.Map <IEnumerable <CallUploadLog>, IEnumerable <CallUploadLogViewModel> >(failedCustomerList); var exporter = ExportableDataGeneratorProcessManager <ViewModelBase, ModelFilterBase> .GetCsvExporter <CallUploadLogViewModel>(); WriteCsv(failedFilePath, exporter, modelData); var failedRecords = new FileInfo(failedFilePath); var file = new File { Path = failedRecords.Name, FileSize = failedRecords.Length, Type = FileType.Csv, UploadedBy = new OrganizationRoleUser(1), UploadedOn = DateTime.Now }; file = _fileRepository.Save(file); callUpload.FailedUploadCount = failedCustomerList.Count(); callUpload.LogFileId = file.Id; } catch (Exception ex) { _logger.Error("exception Raised While Creating Failed Customer Records \n message: " + ex.Message + " stacktrace: " + ex.StackTrace); } } _callUploadRepository.Save(callUpload); }
public ActionResult Upload(CallUploadEditModel model) { var uploadMediaLocation = _mediaRepository.GetCallUploadMediaFileLocation(); model.UploadCsvMediaUrl = uploadMediaLocation.Url; HttpPostedFileBase postedFile = Request.Files[0]; if (postedFile == null || postedFile.ContentLength < 1) { model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("No file has been uploaded. Please upload a csv file."); return(View(model)); } if (System.IO.Path.GetExtension(postedFile.FileName).ToLower() != ".csv") { model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Please upload a csv file!"); return(View(model)); } var physicalPath = uploadMediaLocation.PhysicalPath; var fileContent = System.IO.Path.GetFileNameWithoutExtension(postedFile.FileName) + "_" + DateTime.Now.ToString("MMddyyyyhhmmss") + System.IO.Path.GetExtension(postedFile.FileName); var fullPath = physicalPath + fileContent; postedFile.SaveAs(fullPath); var customerTable = _csvReader.ReadWithTextQualifier(fullPath); if (customerTable.Rows.Count == 0) { model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Uploaded file has no data."); return(View(model)); } var missingColumnNames = _callUploadHelper.CheckForColumns(customerTable.Rows[0]); if (!string.IsNullOrEmpty(missingColumnNames)) { model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Missing Column Name(s) : " + missingColumnNames); return(View(model)); } var file = new File { Path = fileContent, FileSize = postedFile.ContentLength, Type = FileType.Csv, UploadedBy = new OrganizationRoleUser(_session.UserSession.CurrentOrganizationRole.OrganizationRoleUserId), UploadedOn = DateTime.Now }; file = _fileRepository.Save(file); var callUpload = new CallUpload { FileId = file.Id, UploadTime = DateTime.Now, StatusId = (long)CallUploadStatus.Uploaded, UploadedBy = _session.UserSession.CurrentOrganizationRole.OrganizationRoleUserId }; callUpload = _callUploadRepository.Save(callUpload); if (callUpload != null && callUpload.Id > 0) { model.FeedbackMessage = FeedbackMessageModel.CreateSuccessMessage("File Uploaded Successfull."); } return(View(model)); }