Exemplo n.º 1
0
        public void GetStoreHistoryTest()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <StoreAppContext>()
                          .UseInMemoryDatabase(databaseName: "GetStoreHistoryTest")
                          .Options;

            //Act
            using (var db = new StoreAppContext(options))
            {
                Store location = new Store
                {
                    Location = "Maryland"
                };

                db.Add(location);
                db.SaveChanges();

                Customer customer = new Customer
                {
                    FirstName = "Michael",
                    LastName  = "Hall",
                    UserName  = "******",
                    Password  = "******"
                };

                db.Add(customer);
                db.SaveChanges();

                Product product = new Product
                {
                    StoreId     = 1,
                    ProductName = "bar",
                    Inventory   = 5,
                    Price       = 10
                };

                db.Add(product);
                db.SaveChanges();

                Order order = new Order
                {
                    CustomerId = 1,
                    ProductId  = 1,
                    Quantity   = 3,
                };

                db.Add(order);
                db.SaveChanges();
            }

            //Assert
            using (var context = new StoreAppContext(options))
            {
                var repo     = new StoreRepo();
                var products = repo.GetStoreHistory(context, 1);
            }
        }
Exemplo n.º 2
0
        // GET: Stores/History/5
        /// <summary>
        /// Gets all the order history for a particular store and returns
        /// the view displaying said history data
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <IActionResult> History(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            try
            {
                var repo         = new StoreRepo();
                var storeHistory = await repo.GetStoreHistory(_context, (int)id);

                return(View(storeHistory));
            }
            catch (Exception ex)
            {
                _logger.LogInformation(ex, "Wasn't able to obtain the store's order history");
                return(RedirectToAction(nameof(Index)));
            }
        }