예제 #1
0
        //GET:/Meal/Edit/ingestionId
        public IActionResult Edit(int id)
        {
            var ing          = _ingestionRepository.GetIngestionByIdAsync(id).Result;
            var weightOfFood = new List <WeightOfFoodViewModel>();

            if (ing.WeightOfFood != null)
            {
                foreach (var item in ing.WeightOfFood)
                {
                    var food = _foodRepository.GetFoodAsync(item.FoodID).Result;
                    weightOfFood.Add(new WeightOfFoodViewModel {
                        Food = food, FoodID = food.FoodID, IngestionId = item.IngestionID, Weight = item.Weight
                    });
                }
            }
            if (weightOfFood.Count == 0)
            {
                weightOfFood.Add(new WeightOfFoodViewModel {
                    IngestionId = id
                });
            }
            var ingestionViewModel = new IngestionViewModel
            {
                Name         = ing.Name,
                OneDayFoodId = ing.OneDayFoodID,
                WeightOfFood = weightOfFood,
            };

            PopulateFoodDropDownList();
            return(View(ingestionViewModel));
        }
예제 #2
0
        public async Task <Ingestion> CreateIngestionsAsync(IngestionViewModel viewModel)
        {
            var newIng = new Ingestion
            {
                Name         = viewModel.Name,
                OneDayFoodID = viewModel.OneDayFoodId
            };

            _context.Ingestion.Add(newIng);
            _context.SaveChanges();
            return(await
                   _context.Ingestion.SingleOrDefaultAsync(
                       t => t.Name == viewModel.Name& t.OneDayFoodID == viewModel.OneDayFoodId));
        }
예제 #3
0
        public static CountMealPerIngestion Count(IngestionViewModel viewModel)
        {
            var count = new CountMealPerIngestion();

            if (viewModel.WeightOfFood != null)
            {
                foreach (var weightOfFoodViewModel in viewModel.WeightOfFood)
                {
                    if (weightOfFoodViewModel.Food != null)
                    {
                        count.TotalCal     += weightOfFoodViewModel.Calories;
                        count.TotalCarb    += weightOfFoodViewModel.Carbohydrate;
                        count.TotalFat     += weightOfFoodViewModel.Fat;
                        count.TotalProtein += weightOfFoodViewModel.Protein;
                    }
                }
            }
            return(count);
        }
예제 #4
0
        // GET: /<controller>/
        public IActionResult Index(int id)
        {
            ViewData["user"] = id;
            var AllOneDayFoodForUser = _oneDayFoodRepository.OneDayFoodsByUserId(id);
            var AllMealsViewModel    = new List <MealDetailViewModel>();

            foreach (var oneDayFood in AllOneDayFoodForUser)
            {
                var list    = new List <CountMealPerIngestion>();
                var ingList = new List <IngestionViewModel>();
                foreach (var ingestion in oneDayFood.Ingestions)
                {
                    var weightList = new List <WeightOfFoodViewModel>();
                    foreach (var weightOfFood in ingestion.WeightOfFood)
                    {
                        var newWeight = new WeightOfFoodViewModel {
                            Food = weightOfFood.Food, IngestionId = weightOfFood.IngestionID, Weight = weightOfFood.Weight
                        };
                        weightList.Add(newWeight);
                    }
                    var ingViewModel = new IngestionViewModel {
                        WeightOfFood = weightList, Name = ingestion.Name, OneDayFoodId = oneDayFood.OneDayFoodID
                    };
                    ingList.Add(ingViewModel);
                    list.Add(ingViewModel.GetCountMealPerIngestion);
                }
                var newOneDayViewModel = new OneDayFoodViewModel
                {
                    AppUserID  = id,
                    Date       = oneDayFood.Date,
                    Ingestions = ingList,
                    Water      = oneDayFood.Water
                };

                AllMealsViewModel.Add(new MealDetailViewModel {
                    CountMealPerIngestions = list, OneDayFoodViewModel = newOneDayViewModel, OneDayFoodId = oneDayFood.OneDayFoodID
                });
            }
            return(View(AllMealsViewModel));
        }