Exemplo n.º 1
0
        public FoodLogViewModel(SQLiteAsyncConnection sqlite)
        {
            this.sqlite  = sqlite;
            SelectedDate = DateTime.Now;

            FindIt = ReactiveCommand.CreateAsyncTask(FindItImpl);
            FindIt.Subscribe(async foodId =>
            {
                if (foodId == 0)
                {
                    return;
                }

                var newFoodLog = new FoodLog
                {
                    // ReSharper disable once PossibleInvalidOperationException
                    Date = SelectedDate.Value,
                    Food = foodId
                };

                await sqlite.InsertAsync(newFoodLog);

                // todo instead of resetting the text to empty, it would be nice to give the
                // user some other type of feedback, like maybe a subtle created indicator that fades or something.
                Food = string.Empty;
            });

            var canLogIt = this.WhenAny(
                x => x.Food,
                food => !string.IsNullOrEmpty(food.Value));

            LogIt = ReactiveCommand.CreateAsyncTask(canLogIt, _ => LogItImpl());
        }
Exemplo n.º 2
0
        public void Can_Deserialize_Food()
        {
            string content      = File.ReadAllText(SampleData.PathFor("Food.txt"));
            var    deserializer = new RestSharp.Deserializers.XmlDeserializer();

            Food result = deserializer.Deserialize <Food>(new RestResponse()
            {
                Content = content
            });

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Foods);
            Assert.IsNotNull(result.Goals);
            Assert.IsNotNull(result.Summary);

            Assert.IsTrue(result.Foods.Count == 1);
            FoodLog food = result.Foods[0];

            Assert.IsTrue(food.IsFavorite);
            Assert.AreEqual(food.LogDate, new DateTime(2011, 06, 29));
            Assert.AreEqual(food.LogId, 1924);

            Assert.IsNotNull(food.LoggedFood);
            LoggedFood logged = food.LoggedFood;

            Assert.AreEqual(logged.AccessLevel, "PUBLIC");
            Assert.AreEqual(logged.Amount, 132.57f);
            Assert.IsNull(logged.Brand);
            Assert.AreEqual(logged.Calories, 752);
            Assert.AreEqual(logged.FoodId, 18828);
            Assert.AreEqual(logged.MealTypeId, 4);
            Assert.AreEqual(logged.Locale, "en_US");
            Assert.AreEqual(logged.Name, "Chocolate, Milk");

            Assert.IsNotNull(food.NutritionalValues);
            NutritionalValues values = food.NutritionalValues;

            Assert.AreEqual(values.Calories, 752);
            Assert.AreEqual(values.Carbs, 66.5);
            Assert.AreEqual(values.Fat, 49);
            Assert.AreEqual(values.Fiber, .5);
            Assert.AreEqual(values.Protein, 12.5);
            Assert.AreEqual(values.Sodium, 186);

            FoodSummary summary = result.Summary;

            Assert.AreEqual(summary.Calories, 752);
            Assert.AreEqual(summary.Carbs, 66.5);
            Assert.AreEqual(summary.Fat, 49);
            Assert.AreEqual(summary.Fiber, .5);
            Assert.AreEqual(summary.Protein, 12.5);
            Assert.AreEqual(summary.Sodium, 186);
            Assert.AreEqual(summary.Water, 0);

            FoodGoals goals = result.Goals;

            Assert.AreEqual(goals.Calories, 2286);
        }
Exemplo n.º 3
0
        public void Retrieve_Food_Yesterday()
        {
            Food food = client.GetFood(DateTime.Today);

            Assert.IsNotNull(food);
            Assert.IsNotNull(food.Foods);
            Assert.IsNotNull(food.Goals);
            Assert.IsNotNull(food.Summary);

            Assert.IsTrue(food.Foods.Count > 0);
            FoodLog foodLog = food.Foods[0];

            Assert.AreEqual(foodLog.LogDate, DateTime.Today.Date);
            Assert.IsNotNull(foodLog.LoggedFood);
            Assert.IsNotNull(foodLog.NutritionalValues);
        }
Exemplo n.º 4
0
        public async Task Add([FromBody] FoodLogUpdateBindingModel model)
        {
            var user = await _userManager.GetUserAsync(User);

            var food = _dbContext.Foods.Find(model.FoodId);

            var foodLog = new FoodLog()
            {
                FoodId   = model.FoodId,
                Calories = food.CaloriesPer100Gr * model.Quantity / 100,
                Grams    = model.Quantity,
                LoggedOn = DateTime.UtcNow,
                UserId   = user.Id,
                FoodType = model.Type
            };

            _dbContext.FoodLogs.Add(foodLog);
            await _dbContext.SaveChangesAsync();
        }
Exemplo n.º 5
0
 public static void CopyFoodlog(INutrionalModel context, FoodLog foodLog, byte mealId, DateTime consumedDate)
 {
     context.FoodLogs.Add(new FoodLog {
         ConsumedCarbohydrates = foodLog.ConsumedCarbohydrates,
         Amount         = foodLog.Amount,
         ConsumedEnergy = foodLog.ConsumedEnergy,
         ConsumedFats   = foodLog.ConsumedFats,
         ConsumedMonoUnsaturatedFats = foodLog.ConsumedMonoUnsaturatedFats,
         ConsumedPolyUnsaturatedFats = foodLog.ConsumedPolyUnsaturatedFats,
         ConsumedProteins            = foodLog.ConsumedProteins,
         ConsumedSalt          = foodLog.ConsumedSalt,
         ConsumedSaturatedFats = foodLog.ConsumedSaturatedFats,
         ConsumedSugar         = foodLog.ConsumedSugar,
         ProductId             = foodLog.ProductId,
         Date   = consumedDate,
         UnitId = foodLog.UnitId,
         MealId = mealId
     });
 }
Exemplo n.º 6
0
        private void ValidateFoodData(Food food)
        {
            Assert.IsNotNull(food);

            Assert.IsNotNull(food.Foods);
            Assert.IsNotNull(food.Summary);
            Assert.IsNotNull(food.Goals);

            // goals
            Assert.AreEqual(2286, food.Goals.Calories);

            // summary
            Assert.AreEqual(752, food.Summary.Calories);
            Assert.AreEqual(66.5, food.Summary.Carbs);
            Assert.AreEqual(49, food.Summary.Fat);
            Assert.AreEqual(0.5, food.Summary.Fiber);
            Assert.AreEqual(12.5, food.Summary.Protein);
            Assert.AreEqual(186, food.Summary.Sodium);
            Assert.AreEqual(0, food.Summary.Water);

            // foods
            Assert.AreEqual(1, food.Foods.Count);
            FoodLog f = food.Foods.First();

            Assert.IsTrue(f.IsFavorite);
            Assert.AreEqual(new DateTime(2011, 6, 29), f.LogDate);
            Assert.AreEqual(1820, f.LogId);
            Assert.IsNotNull(f.LoggedFood);
            Assert.IsNotNull(f.NutritionalValues);

            // todo: further parsing of child objects
            Assert.IsNotNull(f.LoggedFood.Unit);
            Assert.AreEqual(147, f.LoggedFood.Unit.Id);
            Assert.AreEqual("gram", f.LoggedFood.Unit.Name);
            Assert.AreEqual("grams", f.LoggedFood.Unit.Plural);
        }
Exemplo n.º 7
0
        public ActionResult LogFood(int?routeId)  //find a way to break this up
        {
            List <string> editedAllergens = new List <string>();
            string        mealName        = "";

            //goes this route if logging a beer
            if (routeId > 0)
            {
                BeerClass1[] beers        = TempData["BeerIngredients"] as BeerClass1[];
                BeerClass1   selectedBeer = beers.Where(a => a.id == routeId).FirstOrDefault();
                string       ingredients  = "";
                if (selectedBeer.ingredients.hops != null)
                {
                    ingredients += "hops, ";
                }
                if (selectedBeer.ingredients.malt != null)
                {
                    ingredients += "malt, ";
                }
                if (selectedBeer.ingredients.yeast != null)
                {
                    ingredients += "yeast, ";
                }
                editedAllergens = FindAllergens(ingredients, true);
            }
            //goes this route if logging a non-restaurant item
            else if (routeId == 0 || routeId == null)
            {
                List <string> allergensToLog = TempData["foundAllergies"] as List <string>;
                editedAllergens = allergensToLog.Distinct().ToList();
                mealName        = TempData["MealName"] as string;
            }
            //goes this way if logging a restaurant meal or LogByAllergen
            else
            {
                editedAllergens = TempData["foundAllergens"] as List <string>;
                //goes this way if coming from LogByAllergen
                if (routeId == -2)
                {
                    mealName = TempData["MealName"] as string;
                }
            }

            var           customer    = GetCustomer();
            FoodLog       logger      = new FoodLog();
            AllergenTotal logAllergen = new AllergenTotal();

            if (editedAllergens == null)
            {
                TempData["foods"] = null;
                return(RedirectToAction("Index"));
            }

            for (int i = 0, j = 1; i < editedAllergens.Count; i += 2, j += 2)
            {
                logger.Allergens += editedAllergens[i] + ",";
                int tempId = int.Parse(editedAllergens[j]);
                var temp   = db.AllergenTotals.Where(a => a.CustomerId == customer.id && a.AllergenId == tempId).FirstOrDefault();
                if (temp == null)
                {
                    logAllergen.CustomerId = customer.id;
                    logAllergen.AllergenId = tempId;
                    logAllergen.Total      = 1;
                    db.AllergenTotals.Add(logAllergen);
                    db.SaveChanges();
                }
                else
                {
                    temp.Total += 1;
                }
            }
            logger.Reactions  = null;
            logger.CustomerId = customer.id;
            logger.MealName   = mealName;
            logger.MealId     = db.FoodLogs.Where(f => f.CustomerId == customer.id).Max(m => m.MealId);
            if (logger.MealId == null)
            {
                logger.MealId = 1;
            }
            else
            {
                logger.MealId++;
            }

            db.FoodLogs.Add(logger);
            db.SaveChanges();
            TempData["foods"] = null;
            return(RedirectToAction("Index"));
        }