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());
        }
Beispiel #2
0
        public ImportFile RetryFailures(Guid importFileId)
        {
            ImportFile file  = _importFileService.FindById(importFileId);
            ImportMap  map   = _importMapService.FindById(file.ImportMapId);
            var        datas = _importDataService.Query(x => x.Where(f => f.ImportFileId == importFileId && f.HasError == true));

            if (datas.IsEmpty())
            {
                return(file);
            }
            var data = datas.Select(x => new object().DeserializeFromJson(x.Data)).ToList();

            this.ImportCore(file, map, data, (rowIndex, d, rowError, errorType, recordId) =>
            {
                var importDataEntity          = datas[rowIndex - 1];
                importDataEntity.ErrorMessage = rowError.ToString();
                importDataEntity.HasError     = rowError.Length > 0;
                importDataEntity.RecordId     = recordId;
                importDataEntity.ErrorType    = errorType;
                _importDataService.Update(importDataEntity);
            });
            return(file);
        }