private void UpdateProductInExistingPlan(Product productToBeUpdated, string userId)
        {
            var plans     = _dietPlanRepository.ListAllDietPlans(userId);
            var dailyList = new List <DailyDietPlan>();

            foreach (var plan in plans)
            {
                var dailyListInPlan = _dietPlanRepository.ListDailyDietPlans(plan.Id);
                foreach (var daily in dailyListInPlan)
                {
                    dailyList.Add(daily);
                }
            }
            foreach (var daily in dailyList)
            {
                var listOfProductsInDailyPlans = _dietPlanRepository.ListDbProductsInDailyDietPlan(daily);
                foreach (var item in listOfProductsInDailyPlans)
                {
                    if (item.ProductId == productToBeUpdated.ProductId)
                    {
                        var oldProduct = _dietPlanRepository.GetProductFromDailyDietPlan(daily, item.OrdinalNumber);
                        oldProduct.TotalCalories = productToBeUpdated.Energy * oldProduct.PortionSize *
                                                   oldProduct.NumberOfPortions / 100;
                        _dietPlanRepository.UpdateProductInPlan(oldProduct);
                        _productInPlanService.CalculateDailyDietPlanCaloriesAndMacros(daily);
                    }
                }
            }
        }
Пример #2
0
        public List <DailyDietPlan> ListDailyDietPlans(int id)
        {
            var dailyDietPlanList = _dietPlanRepository.ListDailyDietPlans(id).OrderBy(x => x.DayNumber).ToList();

            return(dailyDietPlanList);
        }