Example #1
0
        public void AddProductsToMealsMixed(MealManager mealManager, ItemManager itemManager, ItemService itemService)
        {
            Random rnd = new Random();
            double howManyGramsOfProduct = 0;

            double[] grams = { 20.3, 30.9, 40.3, 50.1, 60.8, 70.9, 80.4, 90.8 };
            foreach (var item in _dayService.Items)
            {
                for (int i = 0; i < item.MealList.Count; i++)
                {
                    var mealHolder = item.MealList[i];
                    var itemHolder = new ItemInMeal(itemService.Items[rnd.Next(1, itemService.Items.Count)], grams[rnd.Next(1, 8)]);

                    mealHolder.ProductsInMeal.Add(itemHolder);
                    howManyGramsOfProduct = grams[rnd.Next(1, 7)];


                    mealHolder.TotalCarbs   += Math.Round(itemHolder.Carb * howManyGramsOfProduct / 100, 2);
                    mealHolder.TotalFat     += Math.Round(itemHolder.Fat * howManyGramsOfProduct / 100, 2);
                    mealHolder.TotalKcal    += Math.Round(itemHolder.Kcal * howManyGramsOfProduct / 100, 2);
                    mealHolder.TotalProtein += Math.Round(itemHolder.Protein * howManyGramsOfProduct / 100, 2);

                    item.TotalCarbs   += Math.Round(mealHolder.TotalCarbs, 2);
                    item.TotalFat     += Math.Round(mealHolder.TotalFat, 2);
                    item.TotalKcal    += Math.Round(mealHolder.TotalKcal, 2);
                    item.TotalProtein += Math.Round(mealHolder.TotalProtein, 2);
                }
            }
        }
 public int AddItemToMeal(ItemInMeal item)
 {
     _context.ItemInMeals.Add(item);
     _context.SaveChanges();
     RecalculateMacroForMeal(item.MealId);
     return(item.Id);
 }
Example #3
0
        public int AddProductToMeal(ItemManager _itemManager)
        {
            double howManyGrmasOfProduct;
            var    dayHolder  = GetDay();
            var    mealHolder = GetMealFromDay(dayHolder);
            var    itemHolder = _itemManager.GetItem();

            do
            {
                Console.Clear();
                Console.WriteLine("Type how many grams of choosen product You want to add...");
            }while (!double.TryParse(Console.ReadLine(), out howManyGrmasOfProduct));

            var itemInMealHolder = new ItemInMeal(itemHolder, howManyGrmasOfProduct);

            mealHolder.ProductsInMeal.Add(itemInMealHolder);
            RecalculateMacrosInMeal(mealHolder);
            RecalculateMacrosInDay(dayHolder);

            Console.WriteLine("Added grams of product: " + itemInMealHolder.Weight);
            Console.WriteLine("Total Carbs: " + mealHolder.TotalCarbs);
            Console.WriteLine("Total fat: " + mealHolder.TotalFat);
            Console.WriteLine("Total kcal: " + mealHolder.TotalKcal);
            Console.WriteLine("Total protein: " + mealHolder.TotalProtein);

            return(itemInMealHolder.Id);
        }
Example #4
0
        public void RemoveProductFromMeal()
        {
            //Arrange
            ItemInMeal  item        = new ItemInMeal(new Item(10, "", 50, 50, 50, 50, 0), 500);
            MealService mealService = new MealService();
            DayService  dayService  = new DayService();
            Meal        meal        = new Meal("Name", 10);

            meal.ProductsInMeal.Add(item);
            Day day = new Day(new DateTime(2020, 10, 10), 10);

            day.mealList    = dayService.AddDomainMealsToDay(mealService);
            day.mealList[0] = meal;
            dayService.RecalculateMacrosInMeal(meal);
            Debug.WriteLine("***************************************************************************");

            Debug.WriteLine($"MEAL Macros: {meal.TotalCarbs}, {meal.TotalFat}, {meal.TotalKcal}, {meal.TotalProtein}.");
            dayService.RecalculateMacrosInDay(day);
            Debug.WriteLine($"DAY Macros: {day.TotalCarbs}, {day.TotalFat}, {day.TotalKcal}, {day.TotalProtein}.");


            //Act
            var output = dayService.RemoveProductFromMeal(item, meal, day);

            Debug.WriteLine("***************************************************************************");

            Debug.WriteLine($"MEAL Macros: {meal.TotalCarbs}, {meal.TotalFat}, {meal.TotalKcal}, {meal.TotalProtein}.");
            Debug.WriteLine($"DAY Macros: {day.TotalCarbs}, {day.TotalFat}, {day.TotalKcal}, {day.TotalProtein}.");
            //Assert
            output.IsSameOrEqualTo(10);
            day.mealList[0].ProductsInMeal.Should().NotContain(item);
        }
Example #5
0
 //public int DeleteMeal(Meal meal, Day day)
 //{
 //    day.mealList.Remove(meal);
 //    return meal.Id;
 //}
 public int AddProductToMeal(ItemInMeal item, Meal meal, Day day)
 {
     meal.ProductsInMeal.Add(item);
     RecalculateMacrosInMeal(meal);
     RecalculateMacrosInDay(day);
     return(item.Id);
 }
Example #6
0
 public int RemoveProductFromMeal(ItemInMeal item, Meal meal, Day day)
 {
     meal.ProductsInMeal.Remove(item);
     RecalculateMacrosInMeal(meal);
     RecalculateMacrosInDay(day);
     return(item.Id);
 }
 public void UpdateItemInMeal(ItemInMeal itemInMeal)
 {
     _context.Attach(itemInMeal);
     _context.Entry(itemInMeal).Property("HowManyGramsCurrentProduct").IsModified = true;
     _context.SaveChanges();
     RecalculateMacroForMeal(itemInMeal.MealId);
     _context.SaveChanges();
 }
        //check if this works actually!
        public void ChangeWeightOfItem(ItemInMeal item, double newWeight)
        {
            var itemInMeal = _context.ItemInMeals.Find(item);

            if (itemInMeal != null)
            {
                itemInMeal.HowManyGramsCurrentProduct = newWeight;
            }
            _context.SaveChanges();
        }
        public int RemoveItemFromMeal(ItemInMeal item)
        {
            var itemInMeal = _context.ItemInMeals.Find(item);

            if (itemInMeal != null)
            {
                _context.ItemInMeals.Remove(item);
                _context.SaveChanges();
                return(item.Id);
            }
            return(-1);
        }
Example #10
0
        public void AddProductToMeal()
        {
            //Arrange
            var itemInMeal  = new ItemInMeal(new Item(10, "name", 100, 100, 100, 100, 0), 50);
            var day         = new Day(new DateTime(2020, 12, 12), 10);
            var dayService  = new DayService();
            var mealService = new MealService();

            day.mealList = dayService.AddDomainMealsToDay(mealService);
            //Act
            var output = dayService.AddProductToMeal(itemInMeal, day.mealList[0], day);

            //Assert
            output.Should().NotBe(null);
            day.mealList[0].Should().NotBe(null);
            day.mealList[0].NameOfMeal.Should().BeSameAs("Breakfast");
            day.mealList[0].ProductsInMeal.Should().NotBeNullOrEmpty();
            day.mealList[0].ProductsInMeal.Should().Contain(itemInMeal);
        }
Example #11
0
        public void HideMeal_Test()
        {
            //Arrange
            var itemInMeal  = new ItemInMeal(new Item(10, "name", 100, 100, 100, 100, 0), 50);
            var day         = new Day(new DateTime(2020, 12, 12), 10);
            var dayService  = new DayService();
            var mealService = new MealService();

            day.mealList = dayService.AddDomainMealsToDay(mealService);
            //Act
            var outputTrue  = dayService.HideMeal(day.mealList[0], day);
            var outputFalse = dayService.HideMeal(day.mealList[0], day);

            dayService.HideMeal(day.mealList[1], day);
            dayService.HideMeal(day.mealList[2], day);
            dayService.HideMeal(day.mealList[3], day);
            dayService.HideMeal(day.mealList[4], day);
            var outputVisibleDaysAreLessThanTwo = dayService.HideMeal(day.mealList[5], day);

            //Assert
            outputTrue.Should().Be(day.mealList[0].Id);
            outputFalse.Should().Be(-1);
            outputVisibleDaysAreLessThanTwo.Should().Be(-2);
        }