abenteuerzeit / viva-la-carte

E-commerce Eating Lifestyle Service
2 stars 1 forks source link

Implement Nutrient Facts #44

Open abenteuerzeit opened 1 year ago

abenteuerzeit commented 1 year ago
public class NutritionFacts : INutritionFacts
{
    // Properties
    public int ServingSize { get; set; }
    public int Calories { get; set; }
    public Dictionary<string, int> Macronutrients { get; set; }
    public Dictionary<string, int> Micronutrients { get; set; }

    // Constructor
    public NutritionFacts(int servingSize, int calories, Dictionary<string, int> macronutrients, Dictionary<string, int> micronutrients)
    {
        ServingSize = servingSize;
        Calories = calories;
        Macronutrients = macronutrients;
        Micronutrients = micronutrients;
    }

    // Methods
    public Dictionary<string, int> GetMacronutrientDictionary()
    {
        // Returns the dictionary of macronutrients
        return Macronutrients;
    }

    public Dictionary<string, int> GetMicronutrientDictionary()
    {
        // Returns the dictionary of micronutrients
        return Micronutrients;
    }
}

You can then use this class to store information about the nutritional content of foods. For example:

var nutritionFacts = new NutritionFacts(1, 150,
                                   new Dictionary<string, int>() {
                                       {"Protein", 15},
                                       {"Fat", 8},
                                       {"Carbohydrates", 20}
                                   },