public List <FscForeign> ExtractFscForeign(string oracleConnString) { using (OracleConnection con = new OracleConnection(oracleConnString)) { using (OracleCommand cmd = con.CreateCommand()) { try { con.Open(); cmd.BindByName = true; cmd.CommandText = @"select ID, FSC_NAME, FK_LINE, FK_SUBSTATION, LOCATION_ID, PERC_COMPENSATION, LINE_REACTANCE_OHMS, CAPACITOR_REACTANCE_OHMS, RATED_MVAR_PHASE, RATED_CURRENT_AMPS, DATETIME_OF_COMMISSIONING, DATETIME_OF_COD, DATETIME_OF_DECOMMISSIONING from REPORTING_WEB_UI_UAT.FSC where :id=1"; // Assign id parameter OracleParameter id = new OracleParameter("id", 1); cmd.Parameters.Add(id); //Execute the command and use DataReader to display the data OracleDataReader reader = cmd.ExecuteReader(); List <FscForeign> fscsForeign = new List <FscForeign>(); while (reader.Read()) { FscForeign fscForeign = new FscForeign(); fscForeign.WebUatId = reader.GetInt32(0); fscForeign.Name = reader.GetString(1); fscForeign.AcTransLineCktWebUatId = reader.GetInt32(2); fscForeign.SubstationWebUatId = reader.GetInt32(3); fscForeign.StateWebUatId = reader.GetInt32(4); fscForeign.PercComp = reader.GetInt32(5); fscForeign.LineReactance = reader.GetInt32(6); fscForeign.CapacitiveReactance = reader.GetInt32(7); fscForeign.RatedMvarPhase = reader.GetInt32(8); fscForeign.RatedCurrentAmps = reader.GetInt32(9); fscForeign.CommDate = reader.GetDateTime(10); fscForeign.CodDate = reader.GetDateTime(11); fscForeign.DeCommDate = reader.GetDateTime(12); fscsForeign.Add(fscForeign); } reader.Dispose(); return(fscsForeign); } catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } } } }
public async Task <Fsc> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, FscForeign fscForeign, EntityWriteOption opt) { // check if entity already exists Fsc existingFsc = await _context.Fscs.SingleOrDefaultAsync(lr => lr.WebUatId == fscForeign.WebUatId); // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingFsc != null) { return(existingFsc); } // find the Substation via the SubstationWebUatId int substationWebUatId = fscForeign.SubstationWebUatId; Substation substation = await _context.Substations.SingleOrDefaultAsync(ss => ss.WebUatId == substationWebUatId); // if Substation doesnot exist, skip the import. Ideally, there should not be such case if (substation == null) { _log.LogCritical($"Unable to find Substation with webUatId {substationWebUatId} while inserting Fsc with webUatId {fscForeign.WebUatId} and name {fscForeign.Name}"); return(null); } // find the State via the State WebUatId int stateWebUatId = fscForeign.StateWebUatId; State state = await _context.States.SingleOrDefaultAsync(s => s.WebUatId == stateWebUatId); // if state doesnot exist, skip the import. Ideally, there should not be such case if (state == null) { _log.LogCritical($"Unable to find state with webUatId {stateWebUatId} while inserting Fsc with webUatId {fscForeign.WebUatId} and name {fscForeign.Name}"); return(null); } int cktWebUatId = fscForeign.AcTransLineCktWebUatId; AcTransLineCkt ckt = await _context.AcTransLineCkts.SingleOrDefaultAsync(v => v.WebUatId == cktWebUatId); // if ckt doesnot exist, skip the import. Ideally, there should not be such case if (ckt == null) { _log.LogCritical($"Unable to find AcTransLineCkt with webUatId {cktWebUatId} while inserting Fsc with webUatId {fscForeign.WebUatId} and name {fscForeign.Name}"); return(null); } // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingFsc != null) { _context.Fscs.Remove(existingFsc); } // if entity is not present, then insert or check if we have to replace the entity completely if (existingFsc == null || (opt == EntityWriteOption.Replace && existingFsc != null)) { Fsc newFsc = new Fsc(); newFsc.Name = fscForeign.Name; newFsc.AcTransLineCktId = ckt.AcTransLineCktId; newFsc.SubstationId = substation.SubstationId; newFsc.StateId = state.StateId; newFsc.PercComp = fscForeign.PercComp; newFsc.LineReactance = fscForeign.LineReactance; newFsc.CapacitiveReactance = fscForeign.CapacitiveReactance; newFsc.RatedMvarPhase = fscForeign.RatedMvarPhase; newFsc.RatedCurrentAmps = fscForeign.RatedCurrentAmps; newFsc.CommDate = fscForeign.CommDate; newFsc.CodDate = fscForeign.CodDate; newFsc.DeCommDate = fscForeign.DeCommDate; newFsc.WebUatId = fscForeign.WebUatId; _context.Fscs.Add(newFsc); await _context.SaveChangesAsync(); return(newFsc); } // check if we have to modify the entity if (opt == EntityWriteOption.Modify && existingFsc != null) { existingFsc.Name = fscForeign.Name; existingFsc.AcTransLineCktId = ckt.AcTransLineCktId; existingFsc.SubstationId = substation.SubstationId; existingFsc.StateId = state.StateId; existingFsc.PercComp = fscForeign.PercComp; existingFsc.LineReactance = fscForeign.LineReactance; existingFsc.CapacitiveReactance = fscForeign.CapacitiveReactance; existingFsc.RatedMvarPhase = fscForeign.RatedMvarPhase; existingFsc.RatedCurrentAmps = fscForeign.RatedCurrentAmps; existingFsc.CommDate = fscForeign.CommDate; existingFsc.CodDate = fscForeign.CodDate; existingFsc.DeCommDate = fscForeign.DeCommDate; await _context.SaveChangesAsync(); return(existingFsc); } return(null); }