示例#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);
        }
        public void DeleteFromExistingPlan()
        {
            var testProduct = new Product()
            {
                ProductName = "Product1", Energy = 50, ProductId = 1
            };
            var dietPlan = new DietPlan()
            {
                Id = 1
            };
            var productInDietPlan = new ProductInDietPlan()
            {
                Product = testProduct, Id = testProduct.ProductId
            };
            var productListForDay = new List <ProductInDietPlan>();

            productListForDay.Add(productInDietPlan);
            var dailyDietPlan = new DailyDietPlan()
            {
                ProductListForDay = productListForDay
            };
            var dailyDietPlanList = new List <DailyDietPlan>()
            {
                dailyDietPlan
            };

            dietPlan.DailyDietPlanList = dailyDietPlanList;
            var listOfDietPlans = new List <DietPlan>()
            {
                dietPlan
            };
            var productFromDB = new ProductInDietPlanDb()
            {
                DailyDietPlanId = dietPlan.Id, ProductId = testProduct.ProductId
            };
            var productRepositoryMock = new Mock <IProductRepository>();

            productRepositoryMock.Setup(repository => repository.GetProductById(1)).Returns(testProduct);
            var productInPlanServiceMock = new Mock <IProductInPlanService>();
            var dietPlanRepositoryMock   = new Mock <IDietPlanRepository>();

            dietPlanRepositoryMock.Setup(repository => repository.ListAllDietPlans("DummyId"))
            .Returns(listOfDietPlans);
            dietPlanRepositoryMock.Setup(repository => repository.ListDailyDietPlans(1)).Returns(dailyDietPlanList);
            dietPlanRepositoryMock.Setup(repository => repository.ListDbProductsInDailyDietPlan(dailyDietPlan)).Returns(new List <ProductInDietPlanDb>()
            {
                productFromDB
            });

            var sut = new ProductService(productRepositoryMock.Object, dietPlanRepositoryMock.Object, productInPlanServiceMock.Object);

            sut.DeleteById(testProduct.ProductId, "DummyId");

            dietPlanRepositoryMock.Verify(repository => repository.DeleteProductInPlan(productFromDB));
        }
示例#3
0
 public void UpdateProductInPlan(ProductInDietPlanDb productInDietPlanDb)
 {
     _context.ProductsInDietPlans.Update(productInDietPlanDb).Context.SaveChanges();
 }
示例#4
0
 public void DeleteProductInPlan(ProductInDietPlanDb productInDietPlanDb)
 {
     _context.ProductsInDietPlans.Remove(productInDietPlanDb).Context.SaveChanges();
 }
示例#5
0
 public void AddProductInPlan(ProductInDietPlanDb product)
 {
     _context.ProductsInDietPlans.Add(product).Context.SaveChanges();
 }