public List <Product> GetProducts() { using var context = new Project0DBContext(_contextOptions); var dbProducts = context.Products.ToList(); var appProducts = dbProducts.Select(p => new Product() { ProductId = p.ProductId, Name = p.Name, Price = p.Price, OrderLimit = p.OrderLimit }).ToList(); //var products = new List<ClassLibrary.Models.Product>(); //foreach(var product in appProducts) //{ // var addProduct = new ClassLibrary.Models.Product() // { // ProductId = product.ProductId, // Name = product.Name, // Price = product.Price, // OrderLimit = product.OrderLimit // }; // products.Add(addProduct); //} return(appProducts); }
public Order GetOrderById(int orderId) { using var context = new Project0DBContext(_contextOptions); var dbOrder = context.Orders.Where(o => o.OrderId == orderId).First(); return(dbOrder); }
public void UpdateOrder(Order order) { using var context = new Project0DBContext(_contextOptions); var dbOrder = context.Orders.Where(o => o.OrderId == order.OrderId).FirstOrDefault(); dbOrder.Total = order.Total; context.SaveChanges(); }
public void DeleteOrder(ClassLibrary.Models.Order order) { using var context = new Project0DBContext(_contextOptions); var dbOrder = context.Orders.Where(i => i.OrderId == order.OrderId).First(); context.Remove(dbOrder); context.SaveChanges(); }
public ActionResult Create(ClassLibrary.Models.Order order) { using var context = new Project0DBContext(_contextOptions); if (ModelState.IsValid) { var createOrder = _orderRepo.CreateAndReturnOrder(order); return(RedirectToAction(nameof(Detail), new { id = createOrder.OrderId })); } return(View("Index")); }
public ActionResult DeleteSuccess(int orderId) { using var context = new Project0DBContext(_contextOptions); if (ModelState.IsValid) { var orderToDelete = _orderRepo.GetOrderById(orderId); return(RedirectToAction("Index")); } return(View("Index")); }
/// <summary> /// Gets all Locations that match a specific Location name /// </summary> /// <param name="name"></param> /// <returns></returns> public ClassLibrary.StoreApplication.Design.Location GetLocationByName(string name) { using var context = new Project0DBContext(_contextOptions); var dbLocations = context.Locations.ToList(); var appLocations = dbLocations.Select(l => new ClassLibrary.StoreApplication.Design.Location() { LocationId = l.LocationId, Name = l.Name }).Where(l => l.Name == name).First(); return(appLocations); }
public Location GetLocationByID(int locationId) { using var context = new Project0DBContext(_contextOptions); var dbLocations = context.Locations.ToList(); var appLocations = dbLocations.Select(l => new Location() { LocationId = l.LocationId, Name = l.Name }).Where(l => l.LocationId == locationId).First(); return(appLocations); }
/// <summary> /// Gets all Locations from the Location table in the database /// </summary> /// <returns></returns> public List <ClassLibrary.StoreApplication.Design.Location> GetLocations() { using var context = new Project0DBContext(_contextOptions); var dbLocations = context.Locations.ToList(); var appLocations = dbLocations.Select(l => new ClassLibrary.StoreApplication.Design.Location() { LocationId = l.LocationId, Name = l.Name }).ToList(); return(appLocations); }
public List <Location> GetLocations() { using var context = new Project0DBContext(_contextOptions); var dbLocations = context.Locations.ToList(); var appLocations = dbLocations.Select(l => new Location() { LocationId = l.LocationId, Name = l.Name }).ToList(); return(appLocations); }
//public List<ClassLibrary.Order> GetCustomerOrders(int customerId) //{ // using var context = new Project0DBContext(_contextOptions); // var dbCustomerOrders = context.Orders.Where(o => o.CustomerId == customerId).ToList(); // var appCustomerOrders = dbCustomerOrders.Select(o => new ClassLibrary.Order() // { // OrderId = o.OrderId, // CustomerId = o.CustomerId, // LocationId = o.LocationId, // OrderTime = o.OrderTime, // Quantity = o.Quantity // } // ).ToList(); // return appCustomerOrders; //} public void InsertCustomer(ClassLibrary.Models.Customer customer) { using var context = new Project0DBContext(_contextOptions); var dbCustomer = new Customer() { FirstName = customer.FirstName, LastName = customer.LastName, Email = customer.Email }; context.Customers.Add(dbCustomer); context.SaveChanges(); }
/// <summary> /// Gets all Products from the Product table in the database /// </summary> /// <returns></returns> public List <ClassLibrary.StoreApplication.Design.Product> GetProducts() { using var context = new Project0DBContext(_contextOptions); var dbProducts = context.Products.ToList(); var appProducts = dbProducts.Select(p => new ClassLibrary.StoreApplication.Design.Product() { ProductId = p.ProductId, Title = p.Name, Price = p.Price }).ToList(); return(appProducts); }
public List <OrderSale> GetOrderDetail(int orderId) { using var context = new Project0DBContext(_contextOptions); var dbOrder = context.OrderSales.Include(o => o.Order).Include(o => o.Product).Where(o => o.OrderId == orderId); var allProducts = new List <OrderSale>(); foreach (var product in dbOrder) { allProducts.Add(product); } return(allProducts); }
public Order CreateAndReturnOrder(ClassLibrary.Models.Order order) { using var context = new Project0DBContext(_contextOptions); var dbOrder = new Order() { CustomerId = order.CustomerId, LocationId = order.LocationId, OrderDate = order.OrderDate, Total = order.Total }; context.Orders.Add(dbOrder); context.SaveChanges(); return(GetOrderById(dbOrder.OrderId)); }
/// <summary> /// Creates a new Order record in the Order database table /// </summary> /// <param name="order"></param> public void InsertOrder(ClassLibrary.StoreApplication.Design.Order order) { using var context = new Project0DBContext(_contextOptions); var dbOrder = new Order() { LocationId = order.LocationId, CustomerId = order.CustomerId, ProductId = order.ProductId, Quantity = order.Quantity }; context.Orders.Add(dbOrder); context.SaveChanges(); }
public Customer GetCustomerByID(int customerId) { using var context = new Project0DBContext(_contextOptions); var dbCustomers = context.Customers.ToList(); var appCustomers = dbCustomers.Select(c => new Customer() { CustomerId = c.CustomerId, FirstName = c.FirstName, LastName = c.LastName, Email = c.Email }).Where(c => c.CustomerId == customerId).First(); return(appCustomers); }
/// <summary> /// Gets all Products that match a specific Product name /// </summary> /// <param name="name"></param> /// <returns></returns> public ClassLibrary.StoreApplication.Design.Product GetProductByName(string name) { using var context = new Project0DBContext(_contextOptions); var dbProducts = context.Products.ToList(); var appProducts = dbProducts.Select(p => new ClassLibrary.StoreApplication.Design.Product() { ProductId = p.ProductId, Title = p.Name, Price = p.Price } ).Where(p => p.Title == name).First(); return(appProducts); }
public ClassLibrary.Models.Customer GetCustomerByName(string firstName, string lastName) { using var context = new Project0DBContext(_contextOptions); var dbCustomers = context.Customers.ToList(); var appCustomers = dbCustomers.Select(c => new ClassLibrary.Models.Customer() { CustomerId = c.CustomerId, FirstName = c.FirstName, LastName = c.LastName, Email = c.Email }).Where(c => c.FirstName == firstName && c.LastName == lastName).First(); return(appCustomers); }
public DataModel.Product GetProductById(int productId) { using var context = new Project0DBContext(_contextOptions); var dbOrder = context.Products.ToList(); var appOrder = dbOrder.Select(p => new Product() { ProductId = p.ProductId, Name = p.Name, Price = p.Price, OrderLimit = p.OrderLimit }).Where(p => p.ProductId == productId).FirstOrDefault(); return(appOrder); }
public List <Customer> GetCustomers() { using var context = new Project0DBContext(_contextOptions); var dbCustomers = context.Customers.ToList(); var appCustomers = dbCustomers.Select(c => new Customer() { CustomerId = c.CustomerId, FirstName = c.FirstName, LastName = c.LastName, Email = c.Email }).ToList(); return(appCustomers); }
/// <summary> /// Gets all Orders from the Order table in the database /// </summary> /// <returns></returns> public List <ClassLibrary.StoreApplication.Design.Order> GetOrders() { using var context = new Project0DBContext(_contextOptions); var dbOrders = context.Orders.ToList(); var appOrders = dbOrders.Select(o => new ClassLibrary.StoreApplication.Design.Order() { OrderId = o.OrderId, CustomerId = o.CustomerId, LocationId = o.LocationId, Quantity = o.Quantity } ).ToList(); return(appOrders); }
public OrderSale GetOrderSaleById(int id) { using var context = new Project0DBContext(_contextOptions); var dbOrderSale = context.OrderSales.ToList(); var appOrderSale = dbOrderSale.Select(o => new OrderSale() { OrderId = o.OrderId, ProductId = o.ProductId, ProductName = o.ProductName, Quantity = o.Quantity, SalePrice = o.SalePrice }).Where(p => p.ProductId == id).FirstOrDefault(); return(appOrderSale); }
public List <Order> GetOrders() { using var context = new Project0DBContext(_contextOptions); var dbOrders = context.Orders.ToList(); var appOrders = dbOrders.Select(o => new Order() { OrderId = o.OrderId, CustomerId = o.CustomerId, LocationId = o.LocationId, Total = o.Total, OrderDate = o.OrderDate, }).ToList(); return(appOrders); }
public void AddProductToOrder(ClassLibrary.Models.OrderSale orderSale) { using var context = new Project0DBContext(_contextOptions); var newOrderSale = new OrderSale() { ProductId = orderSale.ProductId, ProductName = orderSale.ProductName, Quantity = orderSale.Quantity, SalePrice = orderSale.SalePrice }; context.OrderSales.Add(newOrderSale); context.SaveChanges(); }
public List <StoreInventory> GetInventory(int locationId) { using var context = new Project0DBContext(_contextOptions); var dbInventory = context.StoreInventories .Include(l => l.Location) .Include(p => p.Product) .Where(i => i.LocationId == locationId); List <StoreInventory> inventories = new List <StoreInventory>(); foreach (var inventory in dbInventory) { inventories.Add(inventory); } return(inventories); }
/// <summary> /// Gets an Order based off of a specific OrderId /// </summary> /// <param name="id"></param> /// <returns></returns> public ClassLibrary.StoreApplication.Design.Order GetOrderById(int id) { using var context = new Project0DBContext(_contextOptions); var dbOrders = context.Orders .Include(o => o.Location) .Include(o => o.Customer) .Include(o => o.Product) .First(o => o.OrderId == id); var location = new ClassLibrary.StoreApplication.Design.Location(dbOrders.LocationId, dbOrders.Location.Name) { LocationId = dbOrders.LocationId, Name = dbOrders.Location.Name, }; var customer = new ClassLibrary.StoreApplication.Design.Customer() { CustomerId = dbOrders.CustomerId, FirstName = dbOrders.Customer.FirstName, LastName = dbOrders.Customer.LastName, Email = dbOrders.Customer.Email }; var product = new ClassLibrary.StoreApplication.Design.Product() { ProductId = dbOrders.ProductId, Title = dbOrders.Product.Name, Price = dbOrders.Product.Price, }; ClassLibrary.StoreApplication.Design.Order testorder = new ClassLibrary.StoreApplication.Design.Order() { OrderId = dbOrders.OrderId, CustomerId = customer.CustomerId, LocationId = location.LocationId, ProductId = product.ProductId, OrderTime = dbOrders.OrderTime, Quantity = dbOrders.Quantity }; return(testorder); }
public List <ClassLibrary.Models.StoreInventory> GetStoreInventories(ClassLibrary.Location location) { using var context = new Project0DBContext(_contextOptions); var dbInventory = context.StoreInventories.Where(i => i.LocationId == location.LocationId).Include(p => p.Product).ToList(); var appInventory = new List <ClassLibrary.Models.StoreInventory>(); foreach (var product in dbInventory) { var newProduct = new ClassLibrary.Models.StoreInventory(product.LocationId, product.ProductId, product.Quantity) { ProductId = product.ProductId }; appInventory.Add(newProduct); } return(appInventory); }
/// <summary> /// Gets all orders that relate to a Location /// </summary> /// <param name="locationId"></param> /// <returns></returns> public List <ClassLibrary.StoreApplication.Design.Order> GetLocationOrders(int locationId) { using var context = new Project0DBContext(_contextOptions); var dbCustomerOrders = context.Orders.Where(o => o.LocationId == locationId).ToList(); var appLocationOrders = dbCustomerOrders.Select(co => new ClassLibrary.StoreApplication.Design.Order() { OrderId = co.OrderId, CustomerId = co.CustomerId, LocationId = co.LocationId, ProductId = co.ProductId, OrderTime = co.OrderTime, Quantity = co.Quantity, } ).ToList(); return(appLocationOrders); }
public List <ClassLibrary.Models.OrderSale> GetOrderProducts(ClassLibrary.Models.Order order) { using var context = new Project0DBContext(_contextOptions); var dbOrderSales = context.OrderSales.Where(o => o.OrderId == order.OrderId).Include(o => o.Product).ToList(); var appOrderSales = new List <ClassLibrary.Models.OrderSale>(); foreach (var item in dbOrderSales) { var orderSale = new Product() { ProductId = item.Product.ProductId, Name = item.Product.Name, Price = item.Product.Price, }; var newOrderSale = new ClassLibrary.Models.OrderSale(item.OrderId, item.ProductName, item.SalePrice, item.Quantity); newOrderSale.ProductId = orderSale.ProductId; appOrderSales.Add(newOrderSale); } return(appOrderSales); }
public void InsertOrder(ClassLibrary.Models.Order order) { using var context = new Project0DBContext(_contextOptions); var dbOrder = new Order() { CustomerId = order.CustomerId, LocationId = order.LocationId, OrderDate = order.OrderDate, Total = order.Total, }; context.Orders.Add(dbOrder); context.SaveChanges(); foreach (var orderSale in dbOrder.OrderSales) { orderSale.OrderId = dbOrder.OrderId; } context.SaveChanges(); }