Ejemplo n.º 1
0
        public async Task <IActionResult> MetricUpdate(MetricUpdateViewModel model)
        {
            if (await _context.Metrics.AnyAsync(mt => mt.Source == model.Source && mt.Type == model.MetricType.AsInt()))
            {
                if (await _context.ManualLabels.AnyAsync(lbl => lbl.Id == model.ManualLabelId))
                {
                    var manualLabel = await _context.ManualLabels.FirstAsync(lbl => lbl.Id == model.ManualLabelId);

                    var metric = await _context.Metrics.FirstAsync(mt => mt.Source == model.Source && mt.Type == model.MetricType.AsInt());

                    metric.ManualLabel = manualLabel;
                    metric.Public      = model.Public;

                    await _context.SaveChangesAsync();

                    return(Ok("Metric manual label has been updated."));
                }
                else
                {
                    return(NotFound($"Manual label with id {model.ManualLabelId} is not found"));
                }
            }
            else
            {
                return(NotFound($"Metric of type {model.MetricType} and source {model.Source} is not found"));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateMetric(MetricUpdateViewModel model)
        {
            var response = await _provider.GetRequiredService <IApiController>().MetricUpdate(model);

            if (response is OkObjectResult)
            {
                TempData["MessageSeverity"] = "success";
                TempData["MessageContent"]  = $"Metric has been updated.";

                return(RedirectToAction("Metric", "Home", new { type = model.Type.ToString(), source = model.Source }));
            }
            else
            {
                return(response);
            }
        }