public ActionResult RecordMetric() { MetricsMainModel model = new MetricsMainModel(); model.MetricClasses = GetMetricClasses().Select(a => new SelectListItem { Value = a.Id.ToString(), Text = a.Class }).ToList(); model.MetricTypes = new List <SelectListItem>(); return(View(model)); }
private string AddNewMetric(MetricsMainModel obj) { string JsonQuery = "{"; if (Session["ClientId"] == null && !(User.IsInRole("System Administrator") || User.IsInRole("Coach"))) { string loggedInUserId = HttpContext.GetOwinContext().Authentication.User.Claims.First(x => x.Type == ClaimTypes.NameIdentifier).Value; JsonQuery += "\"UserId\":\"" + loggedInUserId + "\","; } else { JsonQuery += "\"UserId\":\"" + Session["ClientId"].ToString() + "\","; } JsonQuery += "\"MetricClass\":" + obj.MetricClass + "," + "\"MetricType\":\"" + obj.MetricType + "\"," + "\"Quantity\":" + obj.Quantity.ToString("0.#############", System.Globalization.CultureInfo.InvariantCulture) + "," + "\"Timestamp\":\"" + obj.Timestamp + "\"" + "}"; JObject jObj = QueryMicroService(AddNewMetricRecordEndpoint, "POST", JsonQuery); string message = ""; if (jObj["status"].ToString() == "OK") { message = jObj["result"].ToString(); } else { message = $"Failed to record metric.\n{jObj["result"].ToString()}"; } return(message); }
public ActionResult AddMetric(MetricsMainModel obj) { return(Json(new { result = AddNewMetric(obj) }, JsonRequestBehavior.AllowGet)); }