public IActionResult Details(int?id)
        {
            if (!Util.IsLoggedIn(_cache))
            {
                return(RedirectToAction("Login", "Customer"));
            }
            if (id == null)
            {
                return(NotFound());
            }

            Inventory inv  = DbManipulation.GetInventoryOfStoreProduct(_db, (int)_cache.Get("StoreId"), id);
            Product   prod = DbManipulation.GetProduct(_db, id);

            if (prod == null)
            {
                return(NotFound());
            }

            ViewModel viewModel = new ViewModel();

            List <ShoppingCart> shoppingCartInvs = DbManipulation.GetInventoryOfShoppingCart(shoppingCartProducts, (int)_cache.Get("StoreId"), id);
            ProductView         productView      = viewModel.CreateProductView(shoppingCartInvs, inv, prod);

            return(View(productView));
        }
예제 #2
0
        public void GetProductReturnsCorrectProduct()
        {
            var options = new DbContextOptionsBuilder <BookopolisDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetProductReturnsCorrectProduct")
                          .Options;

            using (var context = new BookopolisDbContext(options))
            {
                DbManipulation.SeedDb(context);

                Product product = DbManipulation.GetProduct(context, 7);
                Assert.IsType <Product>(product);
                Assert.Equal(7, product.ProductId);
                Assert.NotEqual(3, product.ProductId);
            }
        }
예제 #3
0
        public void CreateProductViewHasCorrectInventoryAmount()
        {
            var options = new DbContextOptionsBuilder <BookopolisDbContext>()
                          .UseInMemoryDatabase(databaseName: "CreateProductViewHasCorrectInventoryAmount")
                          .Options;

            using (var context = new BookopolisDbContext(options))
            {
                DbManipulation.SeedDb(context);

                Inventory inv  = DbManipulation.GetInventoryOfStoreProduct(context, 1, 3);
                Product   prod = DbManipulation.GetProduct(context, 3);

                List <ShoppingCart> shoppingCartProducts = new List <ShoppingCart>()
                {
                    new ShoppingCart()
                    {
                        ShoppingCartId = 1,
                        StoreId        = 1,
                        ProductId      = 3,
                        StockAmount    = 2
                    },
                    new ShoppingCart()
                    {
                        ShoppingCartId = 2,
                        StoreId        = 1,
                        ProductId      = 3,
                        StockAmount    = 1
                    },
                    new ShoppingCart()
                    {
                        ShoppingCartId = 3,
                        StoreId        = 1,
                        ProductId      = 3,
                        StockAmount    = 0
                    },
                };

                List <ShoppingCart> shoppingCartInvs = DbManipulation.GetInventoryOfShoppingCart(shoppingCartProducts, 1, 3);

                ViewModel viewModel = new ViewModel();

                ProductView productView = viewModel.CreateProductView(shoppingCartInvs, inv, prod);

                Assert.Equal(0, productView.Amount);
            }
        }