public async void SetTime(int lightBulbID, bool lightBulbStatus, DateTime dateTime) { if (lightBulbStatus == true) { _logger.LogInformation($"IS IN lightBulbStatus True {dateTime}"); _lightBullbModelList.First(lightBulb => lightBulb.ID == lightBulbID).TimeOn = dateTime; } if (lightBulbStatus == false) { _logger.LogInformation($"IS IN lightBulbStatus False Date off {dateTime}"); _logger.LogInformation($"IS IN lightBulbStatus False Date on {_lightBullbModelList.First(lightBulb => lightBulb.ID == lightBulbID).TimeOn}"); _lightBullbModelList.First(lightBulb => lightBulb.ID == lightBulbID).TimeOff = dateTime; double resultMilliseconds = (_lightBullbModelList.First(lightBulb => lightBulb.ID == lightBulbID).TimeOff - _lightBullbModelList.First(lightBulb => lightBulb.ID == lightBulbID).TimeOn) .Milliseconds; _logger.LogInformation($"ResultInmiliseconds {resultMilliseconds}"); double resultMinures1 = (_lightBullbModelList.First(lightBulb => lightBulb.ID == lightBulbID).TimeOff - _lightBullbModelList.First(lightBulb => lightBulb.ID == lightBulbID).TimeOn) .TotalMinutes; double resultInMinutes = resultMilliseconds / 60000; _logger.LogInformation($"ResultInMinutes {resultInMinutes}"); _logger.LogInformation($"ResultInMinutes1 {resultMinures1}"); _lightBullbModelList.First(lightBulb => lightBulb.ID == lightBulbID).BulbOnTimeInMinutesPerDay += resultMinures1; _lightBullbModelList.First(lightBulb => lightBulb.ID == lightBulbID).BulbOffTimeInMinutesPerDay -= resultMinures1; var lightBulbToSaveToDb = _lightBullbModelList.First(lightBulb => lightBulb.ID == lightBulbID); await _lightBulbRepository.Create( new LightBulbDbModel() { ID = lightBulbToSaveToDb.ID, Name = lightBulbToSaveToDb.Name, LightStatus = lightBulbToSaveToDb.LightStatus, TimeOn = lightBulbToSaveToDb.TimeOn, TimeOff = lightBulbToSaveToDb.TimeOff, BulbOffTimeInMinutesPerDay = lightBulbToSaveToDb.BulbOffTimeInMinutesPerDay, BulbOnTimeInMinutesPerDay = lightBulbToSaveToDb.BulbOnTimeInMinutesPerDay } ); _lightBullbModelList.First(lightBulb => lightBulb.ID == lightBulbID).TimeOn = new DateTime(); _lightBullbModelList.First(lightBulb => lightBulb.ID == lightBulbID).TimeOff = new DateTime(); } // await SavePredictionModelToDbAsync(lightBulbID, dateTime, lightBulbStatus); }
public async Task <IActionResult> Post([FromBody] PredictionUsageLightBulbModel lightBulbDbModel) { await _lightBulbRepository.Create(lightBulbDbModel); return(new OkObjectResult(lightBulbDbModel)); }