Example #1
0
        public IActionResult Index(string repositoryName, string metricName, string metricValue, string metricColor, string token)
        {
            if (!ValidateToken(token))
            {
                return(Unauthorized());
            }

            Repository repository = context.Repository.Where(r => r.Name == repositoryName).SingleOrDefault();

            if (repository == null)
            {
                var trackedRepository = context.Repository.Add(new Repository {
                    Name = repositoryName
                });
                context.SaveChanges();
                repository = trackedRepository.Entity;
            }

            Metric metric = context.Metric.Where(m => m.Name == metricName).SingleOrDefault();

            if (metric == null)
            {
                var trackedMetric = context.Metric.Add(new Metric {
                    Name = metricName
                });
                context.SaveChanges();
                metric = trackedMetric.Entity;
            }

            context.Measurement.Add(new Measurement
            {
                RepositoryId = repository.Id,
                MetricId     = metric.Id,
                Value        = metricValue,
                Color        = metricColor
            });

            context.SaveChanges();

            return(NoContent());
        }