Пример #1
0
        /// <summary>
        /// POST adds the shoe
        /// </summary>
        /// <returns>Returns a page</returns>
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Shoes.Add(Inventory);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Пример #2
0
        /// <summary>
        /// POST Deletes a single Shoe on post
        /// </summary>
        /// <param name="id">id of shoe to delete</param>
        /// <returns>Returns a page</returns>
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Inventory = await _context.Shoes.FindAsync(id);

            if (Inventory != null)
            {
                _context.Shoes.Remove(Inventory);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Пример #3
0
        public async void CartInDb()
        {
            DbContextOptions <ShoeDesignzDbContext> options = new DbContextOptionsBuilder <ShoeDesignzDbContext>()
                                                              .UseInMemoryDatabase("CartFromDB")
                                                              .Options;

            using (ShoeDesignzDbContext context = new ShoeDesignzDbContext(options))
            {
                //CRUD
                //CREATE
                Cart cart = new Cart();
                cart.ID     = 1;
                cart.UserID = "UserOne";
                context.Cart.Add(cart);
                await context.SaveChangesAsync();

                //READ
                var cartID = await context.Cart.FirstOrDefaultAsync(c => c.ID == cart.ID);

                var cartName = await context.Cart.FirstOrDefaultAsync(n => n.UserID == cart.UserID);

                Assert.Equal(1, cart.ID);
                Assert.Equal("UserOne", cart.UserID);

                //UPDATE
                //cartName.ID = 2;
                //cartName.UserID = "UserTwo";
                //context.Update(cartName);
                //context.SaveChanges();
                //var updateCart = await context.Cart.FirstOrDefaultAsync(c => c.ID == cartName.ID);
                //updateCart = await context.Cart.FirstOrDefaultAsync(c => c.UserID == cartName.UserID);
                //Assert.Equal(2, updateCart.ID);
                //Assert.Equal("UserTwo", updateCart.UserID);

                //DELETE
                //context.Remove(updateCart);
                //context.SaveChanges();
                //var deleteCart = await context.Cart.FirstOrDefaultAsync(n => n.Inventory.Name == updateCart.Inventory.Name);
                //Assert.True(deleteCart == null);
                //var updateCartCount = await context.Cart.CountAsync();
                //Assert.Equal(0, updateCartCount);
            }
        }
Пример #4
0
        public async void OrderInDb()
        {
            DbContextOptions <ShoeDesignzDbContext> options = new DbContextOptionsBuilder <ShoeDesignzDbContext>()
                                                              .UseInMemoryDatabase("CartFromDB")
                                                              .Options;

            using (ShoeDesignzDbContext context = new ShoeDesignzDbContext(options))
            {
                //CRUD
                //CREATE
                Order order = new Order();
                order.ID     = 7;
                order.UserID = "CATS";
                context.Add(order);
                await context.SaveChangesAsync();

                //READ
                var orderID = await context.Order.FirstOrDefaultAsync(c => c.ID == order.ID);

                var orderUserID = await context.Order.FirstOrDefaultAsync(n => n.UserID == order.UserID);

                Assert.Equal(7, order.ID);
                Assert.Equal("CATS", order.UserID);

                //UPDATE

                /*
                 * orderID.ID = 22;
                 * orderUserID.UserID = "MoreCATS";
                 * context.Update(orderID);
                 * context.SaveChanges();
                 * var updateOrderID = await context.Order.FirstOrDefaultAsync(c => c.ID == orderID.ID);
                 * Assert.Equal(22, updateOrderID.ID);
                 */
            }
        }
Пример #5
0
        public async void InventoryInDb()
        {
            DbContextOptions <ShoeDesignzDbContext> options = new DbContextOptionsBuilder <ShoeDesignzDbContext>()
                                                              .UseInMemoryDatabase("InventoryFromDB")
                                                              .Options;

            using (ShoeDesignzDbContext context = new ShoeDesignzDbContext(options))
            {
                //CRUD
                //CREATE
                Inventory inventory = new Inventory();
                inventory.ID            = 4;
                inventory.Name          = "TestShoeOne";
                inventory.Sku           = 4732432;
                inventory.Price         = 32.55m;
                inventory.DiscountPrice = 12.25m;
                inventory.Gender        = Inventory.Genders.Neutral;
                inventory.Description   = "Awesome Shoes to TEST";
                inventory.Image         = "/somepath.jpg";
                context.Add(inventory);;
                await context.SaveChangesAsync();

                //READ
                var inventoryTest = await context.Shoes.FirstOrDefaultAsync(c => c.ID == inventory.ID);

                inventoryTest = await context.Shoes.FirstOrDefaultAsync(n => n.Name == inventory.Name);

                inventoryTest = await context.Shoes.FirstOrDefaultAsync(s => s.Sku == inventory.Sku);

                inventoryTest = await context.Shoes.FirstOrDefaultAsync(p => p.Price == inventory.Price);

                inventoryTest = await context.Shoes.FirstOrDefaultAsync(d => d.DiscountPrice == inventory.DiscountPrice);

                inventoryTest = await context.Shoes.FirstOrDefaultAsync(desc => desc.Description == inventory.Description);

                inventoryTest = await context.Shoes.FirstOrDefaultAsync(i => i.Image == inventory.Image);

                //var inventorySku =
                Assert.Equal(4, inventoryTest.ID);
                Assert.Equal("TestShoeOne", inventoryTest.Name);
                Assert.Equal(4732432, inventoryTest.Sku);
                Assert.Equal(32.55m, inventoryTest.Price);
                Assert.Equal(12.25m, inventoryTest.DiscountPrice);
                Assert.Equal("Awesome Shoes to TEST", inventoryTest.Description);
                Assert.Equal("/somepath.jpg", inventoryTest.Image);

                //UPDATE

                /*
                 * inventoryTest.ID = 5;
                 * inventoryTest.Name = "ShoeUPDATE";
                 * inventoryTest.Sku = 100101011;
                 * inventoryTest.Price = 44.44m;
                 * inventoryTest.DiscountPrice = 12.00m;
                 * inventoryTest.Description = "Cool cool cool";
                 * inventoryTest.Image = "/newUpdatePath.png";
                 * context.Update(inventoryTest);
                 * context.SaveChanges();
                 * var updateInventory = await context.Shoes.FirstOrDefaultAsync(c => c.ID == inventoryTest.ID);
                 * updateInventory = await context.Shoes.FirstOrDefaultAsync(n => n.Name == inventory.Name);
                 * updateInventory = await context.Shoes.FirstOrDefaultAsync(s => s.Sku == inventory.Sku);
                 * updateInventory = await context.Shoes.FirstOrDefaultAsync(p => p.Price == inventory.Price);
                 * updateInventory = await context.Shoes.FirstOrDefaultAsync(d => d.DiscountPrice == inventory.DiscountPrice);
                 * updateInventory = await context.Shoes.FirstOrDefaultAsync(desc => desc.Description == inventory.Description);
                 * updateInventory = await context.Shoes.FirstOrDefaultAsync(i => i.Image == inventory.Image);
                 * Assert.Equal(5, inventoryTest.ID);
                 * Assert.Equal("ShoeUPDATE", inventoryTest.Name);
                 * Assert.Equal(100101011, inventoryTest.Sku);
                 * Assert.Equal(44.44m, inventoryTest.Price);
                 * Assert.Equal(12.00m, inventoryTest.DiscountPrice);
                 * Assert.Equal("Cool cool cool", inventoryTest.Description);
                 * Assert.Equal("/newUpdatePath.png", inventoryTest.Image);
                 */
                //DELETE
                //context.Remove(updateCart);
                //context.SaveChanges();
                //var deleteCart = await context.Cart.FirstOrDefaultAsync(n => n.Inventory.Name == updateCart.Inventory.Name);
                //Assert.True(deleteCart == null);
                //var updateCartCount = await context.Cart.CountAsync();
                //Assert.Equal(0, updateCartCount);
            }
        }