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

            return(fact);
        }
Esempio n. 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);
        }
Esempio n. 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);
                }
            }
        }