public async Task <IActionResult> Edit(int id, [Bind("Id,FileId,DeliveryDate,ProductName,Amount,UnitaryValue")] SheetAdmission sheetAdmission) { if (id != sheetAdmission.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(sheetAdmission); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SheetAdmissionExists(sheetAdmission.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["FileId"] = new SelectList(_context.File, "Id", "Id", sheetAdmission.FileId); return(View(sheetAdmission)); }
public async Task <IActionResult> Create([Bind("Id,FileId,DeliveryDate,ProductName,Amount,UnitaryValue")] SheetAdmission sheetAdmission) { if (ModelState.IsValid) { _context.Add(sheetAdmission); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["FileId"] = new SelectList(_context.File, "Id", "Id", sheetAdmission.FileId); return(View(sheetAdmission)); }
public bool Validate(DataTable Data, ref List <SheetAdmissionValidationErrors> Errors, ref List <SheetAdmission> ValidItems) { DataRow[] oDataRow = Data.Select(); string erros = ""; int line = 0; bool isValid = true; foreach (DataRow dr in oDataRow) { SheetAdmission lSheetAdmission = new SheetAdmission(); lSheetAdmission.FileId = 0; try { lSheetAdmission.DeliveryDate = DateTime.Parse(dr[0].ToString()); } catch (Exception e) { // Block of code to handle errors } if (string.IsNullOrEmpty(dr[0].ToString())) { break; } try { lSheetAdmission.Amount = Int32.Parse(dr[2].ToString()); } catch (Exception e) { // Block of code to handle errors } lSheetAdmission.ProductName = dr[1].ToString(); try { lSheetAdmission.UnitaryValue = Decimal.Parse(dr[3].ToString()); } catch (Exception e) { // Block of code to handle errors } line++; erros = ""; var isError = _validationErros.FormatErros(lSheetAdmission, ref erros); if (!isError) { SheetAdmissionValidationErrors _sheetAdmissionValidationError = new SheetAdmissionValidationErrors(); _sheetAdmissionValidationError.Line = line; _sheetAdmissionValidationError.Errors = erros; Errors.Add(_sheetAdmissionValidationError); isValid = false; } else { ValidItems.Add(lSheetAdmission); } } return(isValid); }
// GET: Process/id public async Task <IActionResult> Process(int id) { if (id == null) { return(NotFound()); } var file = await _fileService.GetByIdAsync(id); if (file == null) { return(NotFound()); } var datatable2 = _excelServices.ReadSheet(file.Data, 0); List <SheetAdmissionValidationErrors> _lsheetAdmissionValidationError = new List <SheetAdmissionValidationErrors>(); List <SheetAdmission> ValidItems = new List <SheetAdmission>(); var isValid = _sheetAdmissionValidation.Validate(datatable2, ref _lsheetAdmissionValidationError, ref ValidItems); //Create a new workbook Workbook workbook = new Workbook(); //Load a file and imports its data System.IO.Stream stream = new System.IO.MemoryStream(file.Data); workbook.LoadFromStream(stream); //Initialize worksheet Worksheet sheet = workbook.Worksheets[0]; // get the data source that the grid is displaying data for DataTable datatable = sheet.ExportDataTable(); DataRow[] oDataRow = datatable.Select(); foreach (DataRow dr in oDataRow) { SheetAdmission lSheetAdmission = new SheetAdmission(); lSheetAdmission.FileId = id; try { lSheetAdmission.DeliveryDate = DateTime.Parse(dr[0].ToString()); } catch (Exception e) { // Block of code to handle errors } try { lSheetAdmission.Amount = Int32.Parse(dr[2].ToString()); } catch (Exception e) { // Block of code to handle errors } lSheetAdmission.ProductName = dr[1].ToString(); try { lSheetAdmission.UnitaryValue = Decimal.Parse(dr[3].ToString()); } catch (Exception e) { // Block of code to handle errors } string erros = ""; _validationErros.FormatErros(lSheetAdmission, ref erros); //Adiciona Itens await _sheetAdmissionService.AddAsync(lSheetAdmission); } //List<SheetAdmission> lsheetAdmission = new List<SheetAdmission>(); //var lsheetAdmission = _sheetAdmissionService.GetByIdIncludingTasksAsync(23); //List<ReportFileImports> reportFileImports = new List<ReportFileImports>(); var reportFileImports = _importsRepository.GetAllImports(); var reportFileImportsById = await _importsRepository.GetImportById(23); var FileStreamResult = FileDownload(file.Data, file.Name); return(FileStreamResult); }