Exemplo n.º 1
0
        /// <summary>
        /// Queries against the database and checks if any complications between the user and the nutrient can be found
        /// </summary>
        /// <param name="userID">UserID</param>
        /// <param name="name">Nutrient name</param>
        /// <returns>Returns object containing inforation whether nutrient can be consumed or not</returns>
        public NutrientCheckResult CheckNutrient(string userID, string name)
        {
            var check = new NutrientCheckResult();

            var user         = Users.Find(c => c.ID == userID.GetObjectId()).FirstOrDefault();
            var intolerances = Intolerances.Find(c => user.Intolerances.Any(r => r == c.ID)).ToList();

            if (intolerances.Any())
            {
                check.IsEvilForYou = true;
                check.Message      = $"{name} should no be consumed because: ";
                foreach (var intolerance in intolerances)
                {
                    check.Message += intolerance.Name + " ";
                }

                check.AlternativeNutrient = "egg, potato";
            }
            else
            {
                check.IsEvilForYou = false;
                check.Message      = "No complications found.";
            }

            return(check);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Queries database and returns any complications with the given nutrient
        /// </summary>
        /// <param name="name">Nutrient name</param>
        /// <returns>Returns object containing any complications about the nutrient</returns>
        public NutrientCheckResult CheckNutrient(string name)
        {
            var check = new NutrientCheckResult();

            var res = Intolerances.Find(c => c.EvilNutrients.Any(g => g.ToLowerInvariant() == name.ToLowerInvariant())).ToList();

            if (res.Any())
            {
                check.IsEvilForYou = true;
                check.Message      = $"{name} should no be consumed because: ";
                foreach (var intolerance in res)
                {
                    check.Message += intolerance.Name + " ";
                }

                check.AlternativeNutrient = "egg, potato";
            }
            else
            {
                check.IsEvilForYou = false;
                check.Message      = "No complications found.";
            }

            check.Message = check.Message.Trim();
            return(check);
        }