public ImportFile Import(Guid importFileId) { ImportFile file = _importFileService.FindById(importFileId); ImportMap map = _importMapService.FindById(file.ImportMapId); var data = new List <dynamic>().DeserializeFromJson(file.Content); this.ImportCore(file, map, data, (rowIndex, d, rowError, errorType, recordId) => { var importDataEntity = new ImportData { Data = ((JArray)d).ToString(), ErrorMessage = rowError.ToString(), HasError = rowError.Length > 0, ImportFileId = file.ImportFileId, LineNumber = rowIndex, RecordId = recordId, ErrorType = errorType }; _importDataService.Create(importDataEntity); }); return(file); }
public IActionResult ExportFailures(Guid importFileId) { var file = _importFileService.FindById(importFileId); var map = _importMapService.FindById(file.ImportMapId); var datas = _importDataService.Query(x => x.Where(f => f.ImportFileId == importFileId && f.HasError == true)); var data = datas.Select(x => new object().DeserializeFromJson(x.Data)).ToList(); var header = new List <string>().DeserializeFromJson(file.HeaderRow); var mappings = new List <ColumnMapping>().DeserializeFromJson(map.MapCustomizations); var columns = new Dictionary <string, string>(); foreach (var m in mappings) { columns.Add(m.Mapping.Attribute, m.Column); } var stream = _dataExporter.ToExcelStream(data, file.Name, columns); if (stream != null) { return(File(stream.ToArray(), "application/vnd.ms-excel", file.Name)); } return(new EmptyResult()); }