protected void InsertData(DataTransactionMessage result, Information currentInformation) { if (result.State == DataTransactionState.Valid) { Repositories.Informations.Insert(currentInformation); } }
protected DataTransactionMessage CheckAndInsertData(string[] row, int lineId) { var result = new DataTransactionMessage(lineId); var currentInformation = new Information(); for (var i = 0; i < Columns.Length; i++) { if (!IsValid(row[i], i, result, currentInformation)) { break; } } InsertData(result, currentInformation); return result; }
protected bool IsValid(string cell, int index, DataTransactionMessage result, Information info) { if (string.IsNullOrWhiteSpace(cell)) { result.AddError(DataCellErrorType.FieldRequired, Columns[index]); } else { if (index == 0) { info.Account = cell; } if (index == 1) { info.Description = cell; } if (index == 2) { var region = CultureInfo.GetCultures(CultureTypes.SpecificCultures) .Select(c => new RegionInfo(c.LCID)) .FirstOrDefault(ri => ri != null && ri.ISOCurrencySymbol == cell.ToString()); if (region == null) { result.AddError(DataCellErrorType.FieldNotCurrency, Columns[index]); } else { info.CurrencyCode = cell; } } if (index == 3) { decimal amount; if (!decimal.TryParse(cell, NumberStyles.Currency, CultureInfo.InvariantCulture, out amount)) { result.AddError(DataCellErrorType.FieldMustBeDecimal, Columns[index]); } else { info.Amount = amount; } } } return result.State == DataTransactionState.Valid; }
protected DataTransactionMessage CheckAndInsertData(IRow row) { var result = new DataTransactionMessage(row.RowNum); var currentInformation = new Information(); for (var i = 0; i < Columns.Length; i++) { var cell = row.GetCell(i); var currentCell = string.Empty; if (cell != null) { currentCell = cell.ToString(); } if (!IsValid(currentCell, i, result, currentInformation)) { break; } } InsertData(result, currentInformation); return result; }