Esempio n. 1
0
 public IActionResult Index()
 {
     TrackerViewModel tvm = new TrackerViewModel();
     var userId = _userManager.GetUserId(HttpContext.User);
     tvm.Entries = _ctx.Tracker.GetEntriesForUser(Guid.Parse(userId));
     tvm.SportsList = _ctx.Tracker.GetSportsList();
     ViewBag.PieData = new ChartData<string, double>();
     GeneratePieItemsFromTracker(tvm, ViewBag.PieData);
     ViewBag.PieData.Title = "Proportions de suivi des sports";
     return View(tvm);
 }
Esempio n. 2
0
        public IActionResult GetSportDistributionGraph()
        {
            TrackerViewModel tvm = new TrackerViewModel();
            var userId = _userManager.GetUserId(HttpContext.User);
            tvm.Entries = _ctx.Tracker.GetEntriesForUser(Guid.Parse(userId));
            tvm.SportsList = _ctx.Tracker.GetSportsList();

            ChartData<string, double> pie = new ChartData<string, double>();
            GeneratePieItemsFromTracker(tvm, pie);

            return PartialView("Chart/PieChart", pie);
        }
Esempio n. 3
0
        public IActionResult Entries(int sportId = -1)
        {
            if (sportId == -1)
                return RedirectToAction("index");

            TrackerViewModel tvm = new TrackerViewModel();
            var userId = _userManager.GetUserId(HttpContext.User);
            tvm.Entries = _ctx.Tracker.GetEntriesForUserAndSport(Guid.Parse(userId), sportId);
            tvm.SportsList = _ctx.Tracker.GetSportsList();
            ViewBag.SportId = sportId;

            return View("Index", tvm);
        }
Esempio n. 4
0
        private static void GeneratePieItemsFromTracker(TrackerViewModel tvm, ChartData<string, double> pie)
        {
            foreach (KeyValuePair<int, string> kvp in tvm.SportsList)
            {
                double value = tvm.Entries.Where(x => x.SportId == kvp.Key).Count();
                if (value == 0)
                    continue;

                ChartItem<string, double> slice = new ChartItem<string, double>();
                slice.ValueY = value;
                slice.LabelY = kvp.Value;
                slice.ValueX = kvp.Value;
                slice.LabelX = kvp.Value;
                slice.Color = ChartColorHelper.GetColorFromId(kvp.Key);
                pie.Items.Add(slice);
            }
        }