示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("StoreId,StoreName,Date")] Store store)
        {
            if (id != store.StoreId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(store);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StoreExists(store.StoreId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(store));
        }
示例#2
0
        public Store GetStoreById(int storeId)
        {
            using var context = new project0Context(_context);
            var dbLocation = context.Stores
                             .Where(l => l.StoreId == storeId)
                             .FirstOrDefault();

            if (dbLocation == null)
            {
                return(null);
            }
            else
            {
                var result = new Store()
                {
                    StoreId   = dbLocation.StoreId,
                    StoreName = dbLocation.StoreName
                };
                var resultInv = GetInventoryByStore(result);
                foreach (var thing in resultInv)
                {
                    result.Inventory.Add(thing);
                }
                return(result);
            }
        }
示例#3
0
        public List <Order> GetOrdersByStore(Store store)
        {
            using var context = new project0Context(_contextOptions);
            var custRepo = new CustomerRepo(_contextOptions);
            var dbOrders = context.Orders
                           .Where(o => o.StoreId == store.StoreId)
                           .Include(o => o.Store)
                           .Include(o => o.Customer)
                           .ToList();
            var result = new List <Order>();

            foreach (var order in dbOrders)
            {
                var newLocation = _storeRepo.GetStoreById(order.StoreId);
                var newCust     = _customerRepo.GetCustomerById(order.CustomerId);
                var newOrder    = new Order()
                {
                    OrderId         = order.OrderId,
                    Store           = newLocation,
                    Customer        = newCust,
                    OrderTotalPrice = order.OrderTotal
                };
                newOrder.OrderId = order.OrderId;
                newOrder.Date    = order.Date;
                var newOrderItems = GetOrderItemsByOrder(newOrder);
                foreach (var orderItem in newOrderItems)
                {
                    newOrder.OrderItems.Add(orderItem);
                }
                result.Add(newOrder);
            }
            return(result);
        }
示例#4
0
        public Store GetLocationByName(string storeName)
        {
            using var context = new project0Context(_context);
            var dbLocation = context.Stores
                             .FirstOrDefault(l => l.StoreName == storeName);

            if (dbLocation != null)
            {
                var result = new Store()
                {
                    StoreId   = dbLocation.StoreId,
                    StoreName = dbLocation.StoreName
                };
                var resultInv = GetInventoryByStore(result);
                foreach (var thing in resultInv)
                {
                    result.Inventory.Add(thing);
                }
                return(result);
            }
            else
            {
                return(null);
            }
        }
示例#5
0
        public void DeleteStore(Store store)
        {
            using var context = new project0Context(_context);
            var dbLocation = context.Stores
                             .Where(i => i.StoreId == store.StoreId)
                             .FirstOrDefault();

            context.Remove(dbLocation);
            context.SaveChanges();
        }
示例#6
0
        public void UpdateStore(Store store)
        {
            using var context = new project0Context(_context);
            var dbLocation = context.Stores
                             .Where(i => i.StoreId == store.StoreId)
                             .FirstOrDefault();

            dbLocation.StoreName = store.StoreName;
            context.SaveChanges();
        }
示例#7
0
        public void CreateStore(Store location)
        {
            using var context = new project0Context(_context);
            var newEntry = new Models.Store()
            {
                StoreName = location.StoreName
            };

            context.Stores.Add(newEntry);
            context.SaveChanges();
        }
示例#8
0
        public void CreateInventory(Store store, Product product, int stock)
        {
            using var context = new project0Context(_context);
            var currentLocation = store;
            var currentProduct  = product;
            var newEntry        = new Models.Inventory()
            {
                StoreId   = currentLocation.StoreId,
                ProductId = currentProduct.ProductId,
                Stock     = stock
            };

            context.Inventories.Add(newEntry);
            context.SaveChanges();
        }
示例#9
0
        public List <Store> GetAllStore()
        {
            using var context = new project0Context(_context);
            var dbLocations = context.Stores.Distinct().ToList();
            var result      = new List <Store>();

            foreach (var location in dbLocations)
            {
                var newLocation = new Store()
                {
                    StoreId   = location.StoreId,
                    StoreName = location.StoreName
                };
                result.Add(newLocation);
            }
            ;
            return(result);
        }
示例#10
0
        public List <Inventory> GetInventoryByStore(Store store)
        {
            using var context = new project0Context(_context);
            var dbInventory = context.Inventories
                              .Where(i => i.StoreId == store.StoreId)
                              .Include(i => i.Product)
                              .ToList();
            var result = new List <Inventory>();

            foreach (var item in dbInventory)
            {
                var newItem = new Inventory(item.StoreId, item.Product.ProductName, item.Stock)
                {
                    InventoryId = item.InventoryId
                };
                result.Add(newItem);
            }
            return(result);
        }
示例#11
0
 public IActionResult Create(Store store)
 {
     try
     {
         if (StoreExists(store.StoreName))
         {
             TempData["StoreExistError"] = $"Store '{store.StoreName}' already exists.";
             return(RedirectToAction(nameof(Create)));
         }
         else
         {
             _storeRepo.CreateStore(store);
             return(RedirectToAction(nameof(Index)));
         }
     }
     catch
     {
         return(View());
     }
 }