public async Task ImportForeignConductorTypes(WRLDCWarehouseDbContext _context, ILogger _log, string oracleConnStr, EntityWriteOption opt) { ConductorTypeExtract condTypeExtract = new ConductorTypeExtract(); List <ConductorType> condTypes = condTypeExtract.ExtractConductorTypes(oracleConnStr); LoadConductorType loadCondType = new LoadConductorType(); foreach (ConductorType condType in condTypes) { ConductorType insertedCondType = await loadCondType.LoadSingleAsync(_context, _log, condType, opt); } }
public List <ConductorType> ExtractConductorTypes(string oracleConnString) { using (OracleConnection con = new OracleConnection(oracleConnString)) { using (OracleCommand cmd = con.CreateCommand()) { try { con.Open(); cmd.BindByName = true; //Use the command to display employee names from // the EMPLOYEES table cmd.CommandText = "select ID, CONDUCTOR_TYPE from CONDUCTOR_MASTER where :id=1 and CONDUCTOR_TYPE IS NOT NULL"; // 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 <ConductorType> condTypes = new List <ConductorType>(); while (reader.Read()) { ConductorType condType = new ConductorType(); condType.WebUatId = reader.GetInt32(0); condType.Name = reader.GetString(1); condTypes.Add(condType); } reader.Dispose(); return(condTypes); } catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } } } }
public async Task <ConductorType> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, ConductorType condType, EntityWriteOption opt) { // check if frequencySummary already exists for the date and delete it ConductorType existingCondType = await _context.ConductorTypes.SingleOrDefaultAsync(ct => ct.WebUatId == condType.WebUatId); // if entity is not present, then insert if (existingCondType == null) { _context.ConductorTypes.Add(condType); await _context.SaveChangesAsync(); return(condType); } // check if we should not modify existing entities if (opt == EntityWriteOption.DontReplace && existingCondType != null) { return(existingCondType); } // check if we have to replace the entity completely if (opt == EntityWriteOption.Replace && existingCondType != null) { _context.ConductorTypes.Remove(existingCondType); _context.ConductorTypes.Add(condType); await _context.SaveChangesAsync(); return(condType); } // check if we have to modify the entity if (opt == EntityWriteOption.Modify && existingCondType != null) { existingCondType.Name = condType.Name; await _context.SaveChangesAsync(); return(existingCondType); } return(null); }
public async Task <AcTransLineCkt> LoadSingleAsync(WRLDCWarehouseDbContext _context, ILogger _log, AcTransLineCktCondTypeForeign acLineCondTypeForeign, EntityWriteOption opt) { // get the conductor type of the entity ConductorType condType = await _context.ConductorTypes.SingleOrDefaultAsync(ct => ct.WebUatId == acLineCondTypeForeign.CondTypeWebUatId); // if conductor type doesnot exist, skip the import. Ideally, there should not be such case if (condType == null) { _log.LogCritical($"Unable to find ConductorType with webUatId {acLineCondTypeForeign.CondTypeWebUatId} while inserting AcTransLineCktCondType with webUatId {acLineCondTypeForeign.WebUatId}"); return(null); } // get the ac transmission line ckt of the entity AcTransLineCkt existingAcTransLineCkt = await _context.AcTransLineCkts.SingleOrDefaultAsync(acCkt => acCkt.WebUatId == acLineCondTypeForeign.AcTransLineCktWebUatId); // if ac transmission line ckt doesnot exist, skip the import. Ideally, there should not be such case if (existingAcTransLineCkt == null) { _log.LogCritical($"Unable to find AcTransLineCkt with webUatId {acLineCondTypeForeign.AcTransLineCktWebUatId} while inserting AcTransLineCktCondType with webUatId {acLineCondTypeForeign.WebUatId}"); return(null); } // check if we should not modify existing conductor type if (existingAcTransLineCkt.ConductorTypeId.HasValue && opt == EntityWriteOption.DontReplace) { return(existingAcTransLineCkt); } // if conductor type is not present, then insert or replace conductor type if (!existingAcTransLineCkt.ConductorTypeId.HasValue || opt == EntityWriteOption.Replace || opt == EntityWriteOption.Modify) { existingAcTransLineCkt.ConductorTypeId = condType.ConductorTypeId; await _context.SaveChangesAsync(); return(existingAcTransLineCkt); } return(null); }