public async Task <bool> CreateAsync(ReportConstant obj) { _Contect.ReportConstants.Add(obj); await _Contect.SaveChangesAsync(); return(true); }
//================================================================ //Setters //Create PrimarySource public async Task <bool> CreatePrimarySourceAsync(PrimarySourceDataModel obj) { //mapping var PriamrySource = MappingToPrimarySource(obj); //Adding To Db _Context.PrimarySource.Add(PriamrySource); await _Context.SaveChangesAsync(); var value = _Context.PrimarySource.Last(); //value.Code = "" + value.Id; _Context.SaveChanges(); // PEAK POWER TABLE powerPeak peak = new powerPeak() { primarySourceId = Convert.ToInt16(value.Code), peakP1 = 0, peakP2 = 0, peakP3 = 0, }; _Context.powerPeak.Add(peak); _Context.SaveChanges(); return(true); }
public async Task <bool> CreatProductionAsync(ProductionViewModel obj) { var prod = MappingToproductionModel(obj); _Context.Production.Add(prod); await _Context.SaveChangesAsync(); return(true); }
public async Task <ResultModel> Post([FromBody] Appliance a) { var result = new ResultModel(); var query = from Appliance in _context.Appliances where Appliance.name == a.name select Appliance; if (query.FirstOrDefault() != null) { result.IsSuccess = false; result.Message = "Dublicated Appliance Name."; return(result); } await _context.Appliances.AddAsync(a); await _context.SaveChangesAsync(); result.Data = a.id; result.IsSuccess = true; return(result); }
public async Task <ResultModel> Post([FromBody] WatthourMeter w) { var result = new ResultModel(); var query = from meter in _context.WatthourMeters where meter.wattHourMeterName == w.wattHourMeterName select meter; if (query.FirstOrDefault() != null) { result.IsSuccess = false; result.Message = "Dublicated Meter."; return(result); } await _context.WatthourMeters.AddAsync(w); await _context.SaveChangesAsync(); result.Data = w.id; result.IsSuccess = true; return(result); }
public async Task <ResultModel> Post([FromBody] Floor f) { var result = new ResultModel(); var query = from floor in _context.Floors where floor.floorName == f.floorName select floor; if (query.Count() != 0) { result.IsSuccess = false; result.Message = "Dublicated Floor."; return(result); } await _context.Floors.AddAsync(f); await _context.SaveChangesAsync(); result.Data = f.id; result.IsSuccess = true; return(result); }
//Create New Factory public async Task <bool> CreateFactory(FactoryDataModel obj) { string business; if (obj.businessType == "-1") { business = obj.businessTypeOthers; bool CheckBusiness = CheckBusinessTypeByName(obj.businessTypeOthers); if (CheckBusiness == false) { BusinessTypeFac busfac = new BusinessTypeFac { busnisstype = business }; _context.businessTypeFac.Add(busfac); await _context.SaveChangesAsync(); } } else { business = obj.businessType; } Factory DbObj = new Factory() { Name = obj.Name, Scale = obj.Scale, businessType = business }; _context.Factory.Add(DbObj); await _context.SaveChangesAsync(); return(true); }
public async Task <bool> CreateLoadAsync(LoadDataModel obj) { //mapping var load = MappingtoLoad(obj); //Adding To Db _con.Load.Add(load); await _con.SaveChangesAsync(); Loadparameter par = new Loadparameter { Power = obj.Power, PowerFactor = obj.PowerFactor, RatingCurrent = obj.RatingCurrent, RatingTemp = obj.RatingTemp, RatingVoltage = obj.RatingVoltage, Type = obj.Type, }; _con.Loadparameter.Add(par); var value = _con.Load.Last(); value.code = value.Id; value.LoadInfo = par; _con.SaveChanges(); // lw mtwsl b primary if (obj.SourceId % 2 != 0) { PhasesConnection phase = new PhasesConnection(); phase.SourceId = obj.SourceId; phase.SourceType = new PrimarySourceSerivce(_con).GetPrimarySourceFromDBByCode(obj.SourceId).Type; if (obj.Type == "1") { if (obj.dN1 == 1) { phase.dN1 = 1; phase.sN1 = "l" + value.Id; } else if (obj.dN1 == 2) { phase.dN2 = 1; phase.sN2 = "l" + value.Id; } else { phase.dN3 = 1; phase.sN3 = "l" + value.Id; } } else { if (obj.dN1 == 1) { phase.dN1 = 1; phase.sN1 = "l" + value.Id; } else if (obj.dN1 == 2) { phase.dN2 = 1; phase.sN2 = "l" + value.Id; } else { phase.dN3 = 1; phase.sN3 = "l" + value.Id; } if (obj.dN2 == 1) { phase.dN1 = 2; phase.sN1 = "l" + value.Id; } else if (obj.dN2 == 2) { phase.dN2 = 2; phase.sN2 = "l" + value.Id; } else { phase.dN2 = 2; phase.sN3 = "l" + value.Id; } if (obj.dN3 == 1) { phase.dN1 = 3; phase.sN1 = "l" + value.Id; } else if (obj.dN3 == 2) { phase.dN2 = 3; phase.sN2 = "l" + value.Id; } else { phase.dN3 = 3; phase.sN3 = "l" + value.Id; } } _con.PhasesConnection.Add(phase); await _con.SaveChangesAsync(); } // lw mtwsl bsec else { //connect to secondry source phases PhasesConnection phase = new PhasesConnectionService(_con).getPhaseBySourceId(obj.SourceId); if (obj.PhaseType == "1") { if (obj.dN1 == 1) { phase.dN1 = 1; phase.sN1 = "l" + value.Id; } else if (obj.dN1 == 2) { phase.dN2 = 1; phase.sN2 = "l" + value.Id; } else { phase.dN3 = 1; phase.sN3 = "l" + value.Id; } } else { if (obj.dN1 == 1) { phase.dN1 = 1; phase.sN1 = "l" + value.Id; } else if (obj.dN1 == 2) { phase.dN2 = 1; phase.sN2 = "l" + value.Id; } else { phase.dN3 = 1; phase.sN3 = "l" + value.Id; } if (obj.dN2 == 1) { phase.dN1 = 2; phase.sN1 = "l" + value.Id; } else if (obj.dN2 == 2) { phase.dN2 = 2; phase.sN2 = "l" + value.Id; } else { phase.dN2 = 2; phase.sN3 = "l" + value.Id; } if (obj.dN3 == 1) { phase.dN1 = 3; phase.sN1 = "l" + value.Id; } else if (obj.dN3 == 2) { phase.dN2 = 3; phase.sN2 = "l" + value.Id; } else { phase.dN3 = 3; phase.sN3 = "l" + value.Id; } } _con.PhasesConnection.Update(phase); } await _con.SaveChangesAsync(); return(true); }
//Define Route [Primary Source -- Secoundry Source ] //Calculate Avg And insert It // api ///api/source?pid=12&pv1=0.0&pv2=0.0&pv3=0.0&pI1=0.0&pI2=0.0&pI3=0.0&ppf1=0.0&ppf2=0.0&ppf3=0.0&pfreq1=0.0&pfreq2=0.0&pfreq3=0.0&pp1=0.0&pp2=0.0&pp3=0.0&pho=0.0&pIo=0.0&ptime=156777789877 public async Task <string> DoProcess(querySource query) { if (Context.PrimarySource.FirstOrDefault(n => n.Code == query.code) != null) { var line = Context.PrimarySource.Single(n => n.Code == query.code); if (query.PowerFactor1 == -1) { query.PowerFactor1 = 0; } if (query.PowerFactor2 == -1) { query.PowerFactor2 = 0; } if (query.PowerFactor3 == -1) { query.PowerFactor3 = 0; } if (query.frequency1 == -1) { query.frequency1 = 0; } if (query.frequency2 == -1) { query.frequency2 = 0; } if (query.frequency3 == -1) { query.frequency3 = 0; } var Model = new SourceReading() { Fac_Id = line.FactoryId, Voltage1 = query.Voltage1, Current1 = query.Current1, PowerFactor1 = query.PowerFactor1, frequency1 = query.frequency1, Power1 = query.Power1, Voltage2 = query.Voltage2, Current2 = query.Current2, PowerFactor2 = query.PowerFactor2, frequency2 = query.frequency2, Power2 = query.Power2, Voltage3 = query.Voltage3, Current3 = query.Current3, PowerFactor3 = query.PowerFactor3, frequency3 = query.frequency3, Power3 = query.Power3, mCurrent1 = query.mCurrent1, mCurrent2 = query.mCurrent2, mCurrent3 = query.mCurrent3, HarmonicOrder = query.HarmonicOrder, HarmonicOrder1 = query.HarmonicOrder1, HarmonicOrder2 = query.HarmonicOrder2, HarmonicOrder3 = query.HarmonicOrder3, ReturnCurrent = query.ReturnCurrent, PrimarySourceId = Convert.ToInt32(line.Code), SecondarySourceId = null, TimeStamp = query.Timestamp }; //avg calc by yasser CurrentValuesList.Add(query.Current1); CurrentValues2List.Add(query.Current2); CurrentValues3List.Add(query.Current3); if (CurrentValuesList.Count() == 10) { var avg1 = CurrentValuesList.Average(); var avg2 = CurrentValues2List.Average(); var avg3 = CurrentValues3List.Average(); // var avg = new SourceAvg() { Current1Avg = avg1, Time = DateTime.Now, PrimarySourceId = line.Id, SecondarySourceId = null, Current2Avg = avg2, Current3Avg = avg3 }; //save into Database await Context.SourceAvgs.AddAsync(avg); await Context.SaveChangesAsync(); //clear list CurrentValuesList = new List <decimal>(); CurrentValues2List = new List <decimal>(); CurrentValues3List = new List <decimal>(); } Context.SourceReading.Add(Model); await Context.SaveChangesAsync(); // peak calc peakPower(Model); return($"Ok," + DateTimeOffset.UtcNow.ToUnixTimeSeconds()); } else if (Context.secondarySource.FirstOrDefault(n => n.Code == query.code) != null) { var line = Context.secondarySource.Single(n => n.Code == query.code); if (query.PowerFactor1 == -1) { query.PowerFactor1 = 0; } if (query.PowerFactor2 == -1) { query.PowerFactor2 = 0; } if (query.PowerFactor3 == -1) { query.PowerFactor3 = 0; } if (query.frequency1 == -1) { query.frequency1 = 0; } if (query.frequency2 == -1) { query.frequency2 = 0; } if (query.frequency3 == -1) { query.frequency3 = 0; } var Model = new SourceReading() { Fac_Id = line.Fac_Id, Voltage1 = query.Voltage1, Current1 = query.Current1, PowerFactor1 = query.PowerFactor1, frequency1 = query.frequency1, Power1 = query.Power1, Voltage2 = query.Voltage2, Current2 = query.Current2, PowerFactor2 = query.PowerFactor2, frequency2 = query.frequency2, Power2 = query.Power2, Voltage3 = query.Voltage3, Current3 = query.Current3, PowerFactor3 = query.PowerFactor3, frequency3 = query.frequency3, Power3 = query.Power3, ReturnCurrent = query.ReturnCurrent, PrimarySourceId = null, SecondarySourceId = Convert.ToInt32(line.Code), TimeStamp = query.Timestamp, mCurrent1 = query.mCurrent1, mCurrent2 = query.mCurrent2, mCurrent3 = query.mCurrent3, HarmonicOrder = query.HarmonicOrder, HarmonicOrder1 = query.HarmonicOrder1, HarmonicOrder2 = query.HarmonicOrder2, HarmonicOrder3 = query.HarmonicOrder3, }; CurrentValuesList.Add(query.Current1); CurrentValues2List.Add(query.Current2); CurrentValues3List.Add(query.Current3); if (CurrentValuesList.Count() == 10) { var avg1 = CurrentValuesList.Average(); var avg2 = CurrentValues2List.Average(); var avg3 = CurrentValues3List.Average(); // adding to avg tbl var avg = new SourceAvg() { Current1Avg = avg1, Time = DateTime.Now, PrimarySourceId = null, SecondarySourceId = Convert.ToInt32(line.Code), Current2Avg = avg2, Current3Avg = avg3 }; //save into Database await Context.SourceAvgs.AddAsync(avg); await Context.SaveChangesAsync(); //clear list CurrentValuesList = new List <decimal>(); CurrentValues2List = new List <decimal>(); CurrentValues3List = new List <decimal>(); } Context.SourceReading.Add(Model); await Context.SaveChangesAsync(); peakPower(Model); return($"Ok," + DateTimeOffset.UtcNow.ToUnixTimeSeconds()); // peak calc } else { return("worng format or missing Code"); } }
//================================================================ //Setters //Create Secondary public async Task <bool> CreateSecoundrySourceAsync(SecoundrySouresDataModelSim obj) { //mapping var secondarySource = MappingToPrimarySource(obj); //Adding To Db _Context.secondarySource.Add(secondarySource); await _Context.SaveChangesAsync(); var value = _Context.secondarySource.Last(); //value.Code = "" + value.Id; _Context.SaveChanges(); // create secondary source phase PhasesConnectionService phs = new PhasesConnectionService(_Context); phs.Create(value.Id, value.Type); // PEAK POWER TABLE powerPeak peak = new powerPeak() { secondrySourceId = Convert.ToInt16(value.Code), peakP1 = 0, peakP2 = 0, peakP3 = 0, }; _Context.powerPeak.Add(peak); _Context.SaveChanges(); //connect to primary source phases PhasesConnection phase = new PhasesConnection(); phase.SourceId = obj.PS_Id; phase.SourceType = new PrimarySourceSerivce(_Context).GetPrimarySourceFromDBByCode(obj.PS_Id).Type; if (obj.Type == "1") { if (obj.dN1 == 1) { phase.dN1 = 1; phase.sN1 = "s" + value.Id; } else if (obj.dN1 == 2) { phase.dN2 = 1; phase.sN2 = "s" + value.Id; } else { phase.dN3 = 1; phase.sN3 = "s" + value.Id; } } else { if (obj.dN1 == 1) { phase.dN1 = 1; phase.sN1 = "s" + value.Id; } else if (obj.dN1 == 2) { phase.dN2 = 1; phase.sN2 = "s" + value.Id; } else { phase.dN3 = 1; phase.sN3 = "s" + value.Id; } if (obj.dN2 == 1) { phase.dN1 = 2; phase.sN1 = "s" + value.Id; } else if (obj.dN2 == 2) { phase.dN2 = 2; phase.sN2 = "s" + value.Id; } else { phase.dN2 = 2; phase.sN3 = "s" + value.Id; } if (obj.dN3 == 1) { phase.dN1 = 3; phase.sN1 = "s" + value.Id; } else if (obj.dN3 == 2) { phase.dN2 = 3; phase.sN2 = "s" + value.Id; } else { phase.dN3 = 3; phase.sN3 = "s" + value.Id; } } _Context.PhasesConnection.Add(phase); await _Context.SaveChangesAsync(); return(true); }