public List <OrderItem> GetOrderItemsByOrder(Order order) { using var context = new project0Context(_contextOptions); var dbOrderItems = context.OrderItems .Where(o => o.OrderId == order.OrderId) .Include(o => o.Product) .ToList(); var result = new List <OrderItem>(); foreach (var orderItem in dbOrderItems) { var newProduct = new Product() { ProductId = orderItem.Product.ProductId, ProductName = orderItem.Product.ProductName, Price = orderItem.Product.Price }; var newOrderItem = new OrderItem(orderItem.OrderId, newProduct, orderItem.Quantity, orderItem.Total) { ItemId = orderItem.ItemId }; result.Add(newOrderItem); } return(result); }
public OrderItem GetOrderItemById(int id) { using var context = new project0Context(_contextOptions); var dbOrderItem = context.OrderItems .Where(o => o.ItemId == id) .Include(o => o.Product) .FirstOrDefault(); if (dbOrderItem == null) { return(null); } var newAnimal = new Product() { ProductId = dbOrderItem.Product.ProductId, ProductName = dbOrderItem.Product.ProductName, Price = dbOrderItem.Product.Price }; var result = new OrderItem(dbOrderItem.OrderId, newAnimal, dbOrderItem.Quantity, (decimal)dbOrderItem.Total) { ItemId = dbOrderItem.ItemId }; return(result); }
public void UpdateProduct(Product product) { using var context = new project0Context(_contextOptions); var dbProduct = context.Products .Where(a => a.ProductId == product.ProductId) .FirstOrDefault(); dbProduct.ProductName = product.ProductName; dbProduct.Price = product.Price; context.SaveChanges(); }
public void CreateProduct(Product product) { using var context = new project0Context(_contextOptions); var newEntry = new Models.Product() { ProductName = product.ProductName, Price = product.Price }; context.Products.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 <Product> GetAllProducts() { using var context = new project0Context(_contextOptions); var dbProducts = context.Products.Distinct().ToList(); var result = new List <Product>(); foreach (var product in dbProducts) { var newProduct = new Product() { ProductId = product.ProductId, ProductName = product.ProductName, Price = product.Price }; result.Add(newProduct); } ; return(result); }
public Product GetProductByName(string name) { using var context = new project0Context(_contextOptions); var dbProduct = context.Products .Where(a => a.ProductName == name) .FirstOrDefault(); if (dbProduct == null) { return(null); } else { var newProduct = new Product() { ProductId = dbProduct.ProductId, ProductName = dbProduct.ProductName, Price = dbProduct.Price }; return(newProduct); } }
//Inventories // GET: Location/CreateInventory public IActionResult ImportProduct(int id) { if (!ModelState.IsValid) { throw new Exception("Controller Error!"); } var result = new InventoryViewModel(); var productList = _productRepo.GetAllProducts(); result.StoreId = id; result.Stock = 1; foreach (var product in productList) { var newProduct = new Product() { ProductId = product.ProductId, ProductName = product.ProductName, Price = product.Price }; result.Products.Add(newProduct); } return(View(result)); }