Beispiel #1
0
        public ActionResult RefreshBarChart(DateTime start, DateTime end, string nutrient)
        {
            User user = _userServices.GetUser(User.Identity.Name);

            List <Day>     days      = _foodItemServices.GetDays(start, end, user.Id).ToList();
            List <Product> products  = _productServices.GetProducts(days).ToList();
            var            viewModel = new BarChartViewModel();

            if (nutrient.ToLower() == "totalenergy")
            {
                viewModel.BarNames   = _chartServices.GetTotalEnergyCategories();
                viewModel.ChartTitle = _chartServices.GetTitle(nutrient);
                viewModel.BarData    = _chartServices.CalculateTotalEnergyData(days, products);
            }
            else if (nutrient.ToLower() == "alcohol")
            {
                viewModel.BarNames   = _chartServices.GetBarNames(days);
                viewModel.ChartTitle = _chartServices.GetTitle(nutrient);
                viewModel.BarData    = _chartServices.CalculateAlcoholByProduct(days, products);
            }
            else
            {
                viewModel.BarNames   = _chartServices.GetBarNames(days);
                viewModel.ChartTitle = _chartServices.GetTitle(nutrient);
                viewModel.BarData    = _chartServices.CalculateNutrientByProduct(days, products, nutrient);
            }

            return(Json(viewModel, JsonRequestBehavior.AllowGet));
        }
        public IEnumerable <Series> GetSeries(DateTime start, DateTime end, IEnumerable <int> selectedIds, string UserId)
        {
            var            series   = new List <Series>();
            List <Day>     days     = _foodItemServices.GetDays(start, end, UserId).ToList();
            List <Product> products = _productServices.GetProducts(UserId, days).ToList();

            foreach (int id in selectedIds)
            {
                series.Add(GetSeries(start, end, id, UserId));
            }

            return(series);
        }