Example #1
0
        public static NutritionFact Create(Nutrient nutrient, int value = 0)
        {
            var fact = new NutritionFact
            {
                Nutrient = nutrient,
                Value    = value
            };

            return(fact);
        }
Example #2
0
        public static List <NutritionFact> GetDefaultNutritionFacts()
        {
            List <NutritionFact> t = new List <NutritionFact>();

            foreach (Nutrient n in Enum.GetValues(typeof(Nutrient)))
            {
                t.Add(NutritionFact.Create(n));
            }

            return(t);
        }
Example #3
0
        public void AddOrChangeDeclaration(Nutrient nutrient, int value)
        {
            var fact = NutritionFacts.FirstOrDefault(f => f.Nutrient == nutrient);

            if (fact == null)
            {
                fact = NutritionFact.Create(nutrient, value);
                NutritionFacts.Add(fact);
            }
            else
            {
                foreach (var f in NutritionFacts.Where(i => i.Nutrient == nutrient))
                {
                    f.ChangeValue(value);
                }
            }
        }