public IActionResult Upload(HomeModel model) { List <IMeterReading> meterReadings = new List <IMeterReading>(); using var reader = new StreamReader(model.CsvUpload.OpenReadStream()); //Ignores headers reader.ReadLine(); //https://stackoverflow.com/questions/40045147/how-to-read-into-memory-the-lines-of-a-text-file-from-an-iformfile-in-asp-net-co/40045456 while (reader.Peek() >= 0) { //You would validate this better, incase values had commas or something else. I don't have time to improve this. string[] commaDelimitedList = reader.ReadLine().Split(','); //This is not a good way to do this and is prone to failures, I would clean this up given the time. meterReadings.Add(MeterReadingFactory.CreateMeterReading( int.Parse(commaDelimitedList[0]), DateTime.Parse(commaDelimitedList[1]), commaDelimitedList[2]) ); } //I wouldn't need to do this without duplicate objects which i don't have time to fix. I have to deliver in 30 mins!! IInsertResult result = ApiRepo.SendReadingsAsync(meterReadings); model.InsertResult.FailedInsertions = result.failedInsertions; model.InsertResult.SuccessfulInsertions = result.successfulInsertions; return(View("Index", model)); }
public IInsertResult InsertSingle(IInsertReq req, IInsertResult result, CommandType cmdType, string cmdText, string cmdParamPrefix, List <IDbDataParameter> InsertReqOutParamsList, bool ignoreConflict) { this.command = this.command ?? ObjectFactory.CreateCommandObject(SystemCoreManager.DbEngine, SystemCoreManager.DbConnctivity); this.genericDataMapper = this.SystemCoreManager.GenericDataMapper ?? this.SystemCoreManager.GenericDataMapper; if (this.SystemCoreManager.GenericDataMapper.MapCommandFromBusinessObject <IInsertReq>(req, ref this.command, cmdParamPrefix, ignoreConflict)) { this.connection = this.connection ?? ObjectFactory.CreateConnectionObject(SystemCoreManager.DbEngine, SystemCoreManager.DbConnctivity); this.connectionString = SystemCoreManager.ConnectionString; this.dbApi = this.dbApi ?? this.SystemCoreManager.DbContextAPI; if (ObjectFactory.PrepareInsertReqOutParams(ref this.command, InsertReqOutParamsList, this.SystemCoreManager.DbEngine, this.SystemCoreManager.DbConnctivity)) { this.dbApi.ExcecuteNonQuery(this.command, cmdText, cmdType, this.connection, this.connectionString); this.SystemCoreManager.GenericDataMapper.MapBusinssObjectFromCommand(ref result, this.command, cmdParamPrefix, ignoreConflict); return(result); } throw new GenericFrameworkException(new GenericFrameworkError() { ErrorType = ErrorType.SysError, ErrorCode = ErrorCode.SysError_GenericDataMapUtilityError_MapCommandFromBusinessObject, ErrorMessage = "Failed to Populate OutParams" }); } throw new GenericFrameworkException(new GenericFrameworkError() { ErrorType = ErrorType.SysError, ErrorCode = ErrorCode.SysError_GenericDataMapUtilityError_MapCommandFromBusinessObject, ErrorMessage = "Failed to Populate Command from Type " + req.GetType().ToString() }); }
public IInsertResult Insert(IInsertReq req, IInsertResult result, string commandText, string cmdParamPrefix, List <IDbDataParameter> InsertReqOutParamsList, System.Data.CommandType cmdType, bool ignoreConflict) { ErrorCode errorCode = ErrorCode.Other; if (req.ValidateRequest(req, out errorCode)) { this.insertGateway = this.insertGateway ?? this.SystemCoreManager.InsertGateway; return(this.insertGateway.InsertSingle(req, result, cmdType, commandText, cmdParamPrefix, InsertReqOutParamsList, ignoreConflict)); } result.HasError = 1; //result.Message = prepare error message return(result); }
public IInsertResult InsertItem(IInsertReq reqModel, IInsertResult resultModel, string commandText, string cmdPrefix, CommandType cmdType, List <IDbDataParameter> outParamsList, bool ignoreConflict) { return(this.insertConnector.Insert(reqModel, resultModel, commandText, cmdPrefix, outParamsList, cmdType, ignoreConflict)); }