public CsvReader(ImportOptionsViewModel importOptions) { _importOptions = importOptions; _stream = new MemoryStream(importOptions.Data) { Position = 0 }; }
public XlsReader(ImportOptionsViewModel importOptions) { _stream = new MemoryStream(importOptions.Data); _workbook = new XLWorkbook(_stream); _worksheet = _workbook.Worksheet(1); _tableReader = new TableFactory().CreateXlsxReader <TItem>(_worksheet, importOptions.SkipFirstRows > 0 ? importOptions.SkipFirstRows : 1, 1, typeof(TItem).GetProperties().Length, importOptions.HasHeader); }
public XmlReader(ImportOptionsViewModel importOptions) { var stream = new MemoryStream(importOptions.Data) { Position = 0 }; using var reader = new StreamReader(stream); var xml = reader.ReadToEnd(); _xDoc = new XmlDocument(); _xDoc.LoadXml(xml); }
async Task Import() { var options = new ImportOptionsViewModel { HasHeader = HasHeader, Reset = Reset, SkipFirstRows = SkipFirstRows, LimitRows = LimitRows, Data = _content, FileName = _options.FileName }; var postResponse = await HttpClient.PostAsJsonAsync(ApiPostFileUrl, options); postResponse.EnsureSuccessStatusCode(); }
private async Task StartProcessImportProduct(ImportOptionsViewModel options, IList <ExchangeDataRow> models, AdsImportResultViewModel importResult) { if (options.Reset) { var duo = _serviceProvider.GetRequiredService <AdsUnitOfWork>(); await duo.CategoriesRepository.RemoveAll((await duo.CategoriesRepository.GetAll())?.Select(t => t.CategoryId).ToList()); await duo.FamiliesRepository.RemoveAll((await duo.FamiliesRepository.GetAll())?.Select(f => f.FamilyId).ToList()); } foreach (var item in models) { if (string.IsNullOrEmpty(item.Type)) { continue; } switch (item.Type.ToLower()) { case "family": await ImportFamily(item, importResult); break; case "attribute": await ImportAttribute(item); break; case "category": await ImportCategory(item, importResult); break; default: _logger.LogWarning($"type {item.Type} not supported"); break; } } }
public async Task Import(ImportOptionsViewModel importOptions) { var extension = System.IO.Path.GetExtension(importOptions.FileName); IList <AdsCategoryViewModel> models = new List <AdsCategoryViewModel>(); if (extension.Equals(".xlsx") || extension.Equals(".xls")) { using var xlsReader = new XlsReader <AdsCategoryViewModel>(importOptions); models = xlsReader.Read(); } else if (extension.Equals(".xml")) { var xmlReader = new XmlReader <AdsCategoryViewModel>(importOptions); models = xmlReader.Read(); ImportSubCategories(models, xmlReader); } // await _adsUnitOfWork.CategoriesRepository.Clear(); // await _adsUnitOfWork.CategoriesRepository.BulkInsertAsync(models); }
public async Task <ActionResult <AdsImportResultViewModel> > ImportReferential(ImportOptionsViewModel options) { var extension = System.IO.Path.GetExtension(options.FileName); if (string.IsNullOrEmpty(extension)) { return(BadRequest("extension")); } IList <ExchangeDataRow> models = new List <ExchangeDataRow>(); var result = new AdsImportResultViewModel(); switch (extension) { case ".xlsx": case ".xls": { using var xlsReader = new XlsReader <ExchangeDataRow>(options); models = xlsReader.Read(); break; } case ".xml": { var xmlReader = new XmlReader <ExchangeDataRow>(options); models = xmlReader.Read(); break; } case ".csv": case ".txt": { var csvReader = new CsvReader <ExchangeDataRow>(options); models = csvReader.Read(); break; } } await StartProcessImportProduct(options, models, result); return(Ok(result)); }
public ImportModal() { Id = Guid.NewGuid().ToString(); _options = new ImportOptionsViewModel(); }