private decimal?GetQuantity(DateTime date, int selectedId, string UserId) { Day day = _foodItemServices.GetDay(date, UserId); List <Product> products = _productServices.GetProducts(UserId, day).ToList(); var nutrientResults = new List <decimal?>(); // Make a big list of all the fooditems in the day. List <FoodItem> foodItems = new List <FoodItem>(); foodItems.AddRange(day.Food); // Now group the fooditems to get rid of repeats. var groupedFoodItems = foodItems. GroupBy(f => f.Code). Select(fg => new { Code = fg.Key, Total = fg.Sum(f => f.Quantity) }).ToList(); foreach (var g in groupedFoodItems) { if (Macronutrients.Nutrient(selectedId).Name.ToLower() == "alcohol") { nutrientResults.Add(GetTotalAlcoholUnits(g.Total, products.Where(p => p.Code == g.Code).First())); } else { nutrientResults.Add(GetTotalMacroNutrient(g.Total, products.Where(p => p.Code == g.Code).First(), Macronutrients.Nutrient(selectedId).Name)); } } return(nutrientResults.Sum()); }
public List <string> GetMacronutrientTitle(string name) { Nutrient nutrient = Macronutrients.Nutrient(name); return(new List <string> { nutrient.Name + " in " + nutrient.MeasurementUnit }); }
private Series GetSeries(DateTime start, DateTime end, int selectedId, string UserId) { var series = new Series(); series.Name = Macronutrients.Nutrient(selectedId).Name; while (start <= end) { series.Data.Add(GetQuantity(start, selectedId, UserId)); start = start.AddDays(1); } return(series); }
public decimal GetMacronutrientRDA(string name) { return(Macronutrients.Nutrient(name).RDA); }