public async Task <IActionResult> EndCurrentExperiment() { Experiment experiment = await _experimentServices.GetCurrentExperiment(); if (experiment == null) { return(StatusCode(412, "There is no active experiment")); } experiment.EndTime = DateTime.Now; _context.Experiments.Update(experiment); await _context.SaveChangesAsync(); return(Ok(experiment)); }
private void DoWork(object state) { Console.WriteLine("Timed Background Service is working."); Console.WriteLine("Estoy corriendo cada 5 secs"); using (var scope = _scopeFactory.CreateScope()) { IRipeningServices ripeningServices = scope.ServiceProvider.GetRequiredService <IRipeningServices>(); IExperimentServices experimentServices = scope.ServiceProvider.GetRequiredService <IExperimentServices>(); Ripening ripening = ripeningServices.GetCurrentRipening().Result; Experiment experiment = experimentServices.GetCurrentExperiment().Result; string message = ""; if (ripening != null) { DateTime ripeDay = DateTime.Now.AddDays(ripening.Cheese.DaysToRipe); if (ripeDay < DateTime.Now) { message += "¡Tu maduracion esta lista!"; } } if (experiment != null && experiment.EstimatedEndTime < DateTime.Now) { message += "¡Tu experimento esta listo!"; } if (!string.IsNullOrEmpty(message)) { string token = TokenRepository.GetInstance().FirebaseToken; _messaging.SendNotification(token, "Maduracion Terminada", message); } } }