Ejemplo n.º 1
0
        public void AddProductToDailyDietPlan(int id, int dayNumber, ProductInDietPlan productToAdd, Product product, string user, string username)
        {
            var dailyToAddTo = _dietPlanRepository.GetDailyDietPlan(id, dayNumber);

            var productToDb = new ProductInDietPlanDb
            {
                OrdinalNumber    = _dietPlanRepository.ListProductsInDailyDietPlan(dailyToAddTo).Count + 1,
                ProductId        = product.ProductId,
                PortionSize      = productToAdd.PortionSize,
                NumberOfPortions = productToAdd.NumberOfPortions,
                TotalCalories    = product.Energy * productToAdd.PortionSize * productToAdd.NumberOfPortions / 100,
                DailyDietPlanId  = dailyToAddTo.Id
            };

            _dietPlanRepository.AddProductInPlan(productToDb);


            var client = _httpClientFactory.CreateClient();
            var action = CreateAction(ActionType.AddedProductToExistingDailyPlan, dailyToAddTo.DietPlanId, dailyToAddTo.Id, productToAdd, username);

            client.PostAsync("https://localhost:5001/VirtusFit/plan/productinplan",
                             new StringContent(JsonSerializer.Serialize(action), Encoding.UTF8, "application/json"));

            CalculateDailyDietPlanCaloriesAndMacros(dailyToAddTo);
        }
Ejemplo n.º 2
0
        public List <ProductInDietPlan> ListProductsOnDailyDietPlan(int id, int dayNumber)
        {
            var dailyDietPlan = GetDailyDietPlan(id, dayNumber);
            var productList   = _dietPlanRepository.ListProductsInDailyDietPlan(dailyDietPlan)
                                .OrderBy(x => x.OrdinalNumber).ToList();

            return(productList);
        }