public async Task <IActionResult> AddHistory(Guid token, string value) { var sensor = _sensorManager.GetSensorByToken(token); if (sensor == null) { var result = _sensorManager.AddUnclaimedSensor(token, value); if (result.Succeeded) { result = _historyManager.AddHistory(value, Convert.ToInt32(result.Data["id"])); if (result.Succeeded) { result = await _notificationManager.CreateNotification(Convert.ToInt32(result.Data["id"])); } if (result.Succeeded) { await _notificationManager.NotifyAboutInvalidSensor(Convert.ToInt32(result.Data["id"])); } return(Ok(result.Message)); } } var historyResult = _historyManager.AddHistory(value, sensor.Id); if (historyResult.Succeeded) { await _historyManager.UpdateGraph(token, value); await _toastManager.ShowMessage(token, value); return(Ok(historyResult.Message)); } return(BadRequest(historyResult.Message)); }