示例#1
0
 /// <summary>
 /// Returns a string of nutrient content information for display purposes
 /// </summary>
 /// <remarks>
 /// Simliar to <see cref="GetNutrientValue(string, string)"/>, but instead of returning a double this method returns a string for display in nutrition labels
 /// </remarks>
 /// <param name="nutrientId">The string identifier of the target <see cref="Nutrient"/> record</param>
 /// <param name="type">A string representation of the detail expected in <see cref="Nutrient"/> record</param>
 /// <returns>A string representinng specified nutrition content</returns>
 public string GetNutrientDisplayValue(string nutrientId, string type)
 {
     if (Nutrients == null || Nutrients.Count == 0)
     {
         return("");
     }
     else
     {
         Nutrient nutrient = Nutrients.Where(x => x.NId == nutrientId).FirstOrDefault();
         if (nutrient == null)
         {
             return("");
         }
         else
         {
             if (type == "regular")
             {
                 return($"{String.Format("{0:0.##}", (nutrient.Measures.Where(x => (x.Label == SelectedPortionLabel) && (x.Qty == SelectedPortionQty)).FirstOrDefault().Value * NumberOfServings))} {nutrient.Unit}");
             }
             else if (type == "explore")
             {
                 return($"{String.Format("{0:0.##}", nutrient.Value)} {nutrient.Unit}");
             }
             else
             {
                 return("");
             }
         }
     }
 }
示例#2
0
 /// <summary>
 /// Used to determine and retrieve the specified nutrient content in a food based on target nutrient, portion type, and quantity
 /// </summary>
 /// <remarks>
 /// Unlike <see cref="GetNutrientDisplayValue(string, string)"/>, this method is used during the meal logging process
 /// </remarks>
 /// <param name="nutrientId">The string identifier of the target <see cref="Nutrient"/> record</param>
 /// <param name="type">A string representation of the detail expected in <see cref="Nutrient"/> record</param>
 /// <returns>A double value representing total content of specified nutrient</returns>
 public double GetNutrientValue(string nutrientId, string type)
 {
     if (Nutrients == null || Nutrients.Count == 0)
     {
         return(0);
     }
     else
     {
         Nutrient nutrient = Nutrients.Where(x => x.NId == nutrientId).FirstOrDefault();
         if (nutrient == null)
         {
             return(0);
         }
         else
         {
             if (type == "regular")
             {
                 return(Convert.ToDouble(nutrient.Measures.Where(x => (x.Label == SelectedPortionLabel) && (x.Qty == SelectedPortionQty)).FirstOrDefault().Value *NumberOfServings));
             }
             else if (type == "explore" || type == "noMeasure")
             {
                 return(Convert.ToDouble(nutrient.Value));
             }
             else
             {
                 return(0);
             }
         }
     }
 }