public async Task UpdateAsync(ExcelRowDto excelRowDto) { excelRowDto.ModifiedDate = DateTime.Now; if (excelRowDto != null) { if (_excel1Repository.AnyAsync(x => x.Id == excelRowDto.Id).Result) { var excelModel1 = _autoMapper.Map <ExcelModel1>(excelRowDto); await _excel1Repository.UpdateAsyn(excelModel1, excelRowDto.Id); } else if (_excel2Repository.AnyAsync(x => x.Id == excelRowDto.Id).Result) { var excelModel2 = _autoMapper.Map <ExcelModel2>(excelRowDto); await _excel2Repository.UpdateAsyn(excelModel2, excelRowDto.Id); } else { throw new Exception($"Id {excelRowDto.Id} not found"); } } else { throw new Exception("excelRowDto is null"); } }
public Task Put(int id, [FromBody] ExcelRowDto excelRowDto) { if (excelRowDto == null) { throw new BadReadException("Body is empty"); } return(_transferExcelService.UpdateAsync(excelRowDto)); }
/// <summary> /// Получить список excel dto по sheet. /// </summary> /// <param name="fileName">Имя файла</param> /// <param name="excelModel">Модель файла.</param> private List <ExcelRowDto> GetExcelModelDto(ExcelSheetModel excelSheetModel, string fileName) { var listExcelModelDto = new List <ExcelRowDto>(); if (excelSheetModel == null || excelSheetModel.Rows == null) { return(listExcelModelDto); } var rows = excelSheetModel.Rows.ToList(); for (int i = 1; i < rows.Count; i++) { try { var cells = rows[i].Cells.ToList(); ExcelRowDto excelModelDto = new ExcelRowDto { col1 = cells[0]?.Value?.ToString() ?? "", col2 = cells[1]?.Value?.ToString() ?? "", col3 = cells[2]?.Value?.ToString() ?? "", col4 = cells[3]?.Value?.ToString() ?? "", col5 = cells[4]?.Value?.ToString() ?? "", col6 = cells[5]?.Value?.ToString() ?? "", col7 = cells[6]?.Value?.ToString() ?? "", col8 = cells[7]?.Value?.ToString() ?? "", col9 = cells[8]?.Value?.ToString() ?? "", col10 = cells[9]?.Value?.ToString() ?? "", col11 = cells[10]?.Value?.ToString() ?? "", col12 = cells[11]?.Value?.ToString() ?? "", col13 = cells[12]?.Value?.ToString() ?? "", col14 = cells[13]?.Value?.ToString() ?? "", col15 = cells[14]?.Value?.ToString() ?? "", col16 = cells[15]?.Value?.ToString() ?? "", col17 = cells[16]?.Value?.ToString() ?? "", col18 = cells[17]?.Value?.ToString() ?? "", col19 = cells[18]?.Value?.ToString() ?? "", col20 = cells[19]?.Value?.ToString() ?? "", }; listExcelModelDto.Add(excelModelDto); } catch (Exception ex) { _logger.Error(ex, $"Excel Order reports. File: {fileName} at line {i}"); } } return(listExcelModelDto); }
private List <ExcelRowDto> GetDataFromRowColumns(ISheet sheet) { var rowDtos = new List <ExcelRowDto>(); const int cellCount = 12; int dataStartRowNum = (sheet.FirstRowNum + 4); for (int dataRow = dataStartRowNum; dataRow <= sheet.LastRowNum; dataRow++) { var row = sheet.GetRow(dataRow); var dataRowDto = new ExcelRowDto(); if (row is null) { continue; } if (row.Cells.All(d => d.CellType == CellType.Blank)) { continue; } for (var cellNum = row.FirstCellNum; cellNum < cellCount; cellNum++) { if (row.GetCell(cellNum) != null) { dataRowDto.RowColumns.Add(row.GetCell(cellNum).ToString().Trim()); } else { dataRowDto.RowColumns.Add(string.Empty); } } rowDtos.Add(dataRowDto); } return(rowDtos); }