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); } } } }
public List <DietPlan> ListAllDietPlans(string userId) { return(_dietPlanRepository.ListAllDietPlans(userId)); }