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)); }
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); } }
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); }
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); } }
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(); }
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(); }
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(); }
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(); }
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); }
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); }
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()); } }