public void Add(MetricDTO metric) { _metricRepository.Add(new Entities.Metric() { ApplicationName = metric.ApplicationName, Duration = metric.Duration, MetricName = metric.MetricName }); _metricRepository.UnitOfWork.Commit(); }
public void Add(MetricDTO metric) { if (string.IsNullOrEmpty(Setup.GetAPIKey())) { _metricRepository.Add(new Entities.Metric() { ApplicationName = metric.ApplicationName, Duration = metric.Duration, MetricName = metric.MetricName }); _metricRepository.UnitOfWork.Commit(); } else { using (var metricHelper = new MetricHelper(Guid.Parse(Setup.GetAPIKey()))) { metricHelper.Add(new Entities.Metric() { ApplicationName = metric.ApplicationName, Duration = metric.Duration, MetricName = metric.MetricName }); } } }
public async Task Visit(TextUpdateMessage message) { var source = GetSource(message); source.UpdateLastActionDate(); // Need to check the user's state to understand how to process text if (source.State == StateType.HasMetric) { // Processing the value for the main metric await _valueHandlerService.HandleAsync(message); _sourceRepository.Update(source); return; } else if (source.State == StateType.NeedAddMetric) { // Create new metric with name var newMetric = new Metric(message.Content); newMetric.UpdateSource(source); var mainMetric = _metricRepository.GetMainBySourceId(source.Id); newMetric.UpdateMain(mainMetric == null); _metricRepository.Add(newMetric); source.UpdateState(StateType.NeedAddUnit); } else if (source.State == StateType.NeedAddUnit) { // Adding metric unit for existing metric var editedMetric = _metricRepository.GetNotCreatedMetric(source.Id) ?? throw new ArgumentException($"Can't add main unit, there is no edited metric for source {message.ChatId}"); editedMetric.UpdateUnit(message.Content); editedMetric.SetCreated(); _metricRepository.Update(editedMetric); source.UpdateState(StateType.HasMetric); } _sourceRepository.Update(source); await _botClient.SendTextMessageAsync(message, GetMessageCode(source.State)); }
public void CreateMetric(Metric metric) { metricRepository.Add(metric); SaveMetric(); }