public void DispalyOrderlist(project0Context context, int orderId) { ///Displaying the list of an order by the orderId by querrying the orderlist table ///Input: Dbcontext and int ///Output: None /// if (orderId <= 0) { Console.WriteLine("Please input an order id: "); string o = Console.ReadLine(); int.TryParse(o, out orderId); } var orders = from orderlist in context.Orderlist where orderlist.OrderId == orderId select orderlist; if (orders == null) { Console.WriteLine("No such order was found:"); } else { foreach (Orderlist orders1 in orders) { var inventory = context.Inventory.FirstOrDefault(i => i.InventoryId == orders1.ProductId); double itemPrice = inventory.ListPrice; string name = inventory.Name; Console.WriteLine($"productId: {orders1.ProductId}\tqty: {orders1.Quantity}\tproduct name: {name}\t price: {itemPrice}\torder Date: {orders1.OrderDate}"); } } }
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 bool AddStoreInventory(Store store, Product product, int stock) { // set up context using var context = new project0Context(_dbContext); // make the new inventory Inventory inventory = new Inventory() { StoreId = store.Id, Stock = stock, ProductId = product.Id }; context.Inventories.Add(inventory); // ensure that the save works successfully try { context.SaveChanges(); } catch (DbUpdateException) { return(false); } return(true); }
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); } }
private static Library.Customer AddCustomer() { //get first and last name using var context = new project0Context(options); var custRepo = new CustomerRepository(context); Console.Write("\nPlease enter the given name of the new customer: "); string firstName = Console.ReadLine(); Console.Write("\nPlease enter the surname of the new customer: "); string lastName = Console.ReadLine(); Project0.Library.Customer newCustomer = new Project0.Library.Customer(firstName, lastName); try { custRepo.Insert(newCustomer); Console.Write("New customer successfully added."); Console.WriteLine($"\nWe welcome you as a valued customer {newCustomer.FirstName} {newCustomer.LastName}"); } catch (InvalidOperationException e) { Console.WriteLine(e); Console.WriteLine("There was an error processing your request."); } return(newCustomer); }
/// <summary> /// Get the price of the product by query the inventory table with productId /// </summary> /// <param name="context"></param> /// <param name="productId"></param> /// <returns name="ListPrice"></returns> public double GetPriceOfProduct(project0Context context, int productId) { double listPrice; if (productId <= 0) { Console.WriteLine("No such item here"); return(-1); } try { var product = context.Inventory .Where(i => i.ProductId == productId) .FirstOrDefault(); listPrice = product.ListPrice; } catch (ArgumentNullException e) { Console.WriteLine("No such item here", e); return(0); } return(listPrice); }
public Customer SearchCustomer(int id) { using var context = new project0Context(_dbContext); var dbCustomer = context.Customers.First(c => c.Id == id); return(new Customer(dbCustomer.FirstName, dbCustomer.LastName, dbCustomer.Id, dbCustomer.Order) ?? null); }
public List <Order> GetAllOrders() { using var context = new project0Context(_contextOptions); var dbOrders = context.Orders .Include(o => o.Store) .Include(o => o.Customer) .ToList(); var result = new List <Order>(); foreach (var order in dbOrders) { var newStore = _storeRepo.GetStoreById(order.StoreId); var newCust = _customerRepo.GetCustomerById(order.CustomerId); var newOrder = new Order() { OrderId = order.OrderId, Store = newStore, Customer = newCust, OrderTotalPrice = order.OrderTotal, Date = order.Date }; result.Add(newOrder); } ; return(result); }
/// <summary> /// checking if the stock will be enough to fullfill the order size /// </summary> /// <param name="context"></param> /// <param name="storeId"></param> /// <param name="productId"></param> /// <param name="request"></param> /// <returns name="boolean"></returns> public bool IsQuantityInStockEnough(project0Context context, int storeId, int productId, int request) { bool available = false; int qty = GetQuantityOfProduct(context, productId, storeId); if (qty < 1) //checking if the product is in stock { Console.WriteLine("Run Out of Stock"); // return(false); } else { var product = context.Inventory .Where(p => p.ProductId == productId && p.StoreId == storeId) .FirstOrDefault(); if (product is Inventory) //checking that product is inventory object and if so check the quantity in stock { if (product.Quantity <= request) //making if what in stock can service the order { available = false; } else { available = true; } } } return(available); }
public Orderlist AddProductToOrder(project0Context context, int customerId, int orderId) { Orderlist orderlist = new Orderlist(); Console.WriteLine("Enter Product name:"); string productName = Console.ReadLine(); Console.WriteLine("Enter Quantity:"); string qty = Console.ReadLine(); int quantity; while (!int.TryParse(qty, out quantity)) { Console.WriteLine("Wrong value was entered:"); } int productId = products.GetProductIdByName(context, productName); int storeId = ds.GetCustomerDefaultStore(context, customerId); ProductPrice = products.GetPriceOfProduct(context, productId); if (!products.IsQuantityInStockEnough(context, storeId, productId, quantity)) { Console.WriteLine("Quantity in stock can service this order please change the quantity:"); int quantityInStock = products.GetQuantityOfProduct(context, productId, storeId); Console.WriteLine($"The quantity in stock is: {quantityInStock}"); } else { orderlist = orderitem.MakeOrder(productId, orderId, quantity); sumTotal += ProductPrice; } return(orderlist); }
/// <summary> /// This method is use to add new product to stock of a given store location /// </summary> /// <param name="context"></param> public void AddNewProduct(project0Context context) { Inventory product = new Inventory(); //get the product name Console.WriteLine("Enter the product name"); product.Name = Console.ReadLine(); //get the product storeId Console.WriteLine("Enter the storeId "); string iD = Console.ReadLine(); if (!int.TryParse(iD, out int qty)) { // Parsing failed, handle the error however you like } product.Quantity = qty; //get the descrition of the product Console.WriteLine("Enter the product description"); product.Description = Console.ReadLine(); //get the product list price Console.WriteLine("Enter the price "); string pricestr = Console.ReadLine(); if (!int.TryParse(iD, out int price)) { // Parsing failed, handle the error however you like } product.ListPrice = price; context.Inventory.Add(product); context.SaveChanges(); }
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 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 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 Order GetOrderById(int id) { using var context = new project0Context(_contextOptions); var dbOrder = context.Orders .Where(l => l.OrderId == id) .FirstOrDefault(); if (dbOrder == null) { return(null); } var result = new Order() { OrderId = dbOrder.OrderId, Store = _storeRepo.GetStoreById(dbOrder.StoreId), Customer = _customerRepo.GetCustomerById(dbOrder.CustomerId), OrderTotalPrice = dbOrder.OrderTotal, Date = dbOrder.Date }; var orderItems = GetOrderItemsByOrder(result); foreach (var thing in orderItems) { result.OrderItems.Add(thing); } return(result); }
public void addToExistProduct(int productId, int storeId, int quantity) { int qty = getQuantityOfProduct(productId, storeId); if (qty == -1) { addNewProduct(); } else { var product = _context.Inventory .Where(p => p.ProductId == productId && p.StoreId == storeId) .FirstOrDefault(); if (product is Inventory) { product.Quantity = quantity; _context.Inventory.Add(product); _context.SaveChanges(); using project0Context context = new project0Context(); _context = context; } } }
public ICollection <Store> GetAllStore() { using var context = new project0Context(_dbContext); var dbStore = context.Stores.ToList(); return(dbStore.Select(s => new Store(s.StoreName, s.Id, s.Location, s.Inventories, s.Products)).ToList()); }
public Product GetProduct(int id) { // get the context of the db using var context = new project0Context(_dbContext); var dbProduct = context.Products.First(p => p.Id == id); return(new Product(dbProduct.Name, dbProduct.Id, dbProduct.Price, dbProduct.Status)); }
public Library.Customer GetCustomerById(int customerId) { using var context = new project0Context(_dbContext); var dbCustomer = context.Customers.FirstOrDefault(o => o.CustomerId == customerId); var appCustomer = new Library.Customer(dbCustomer.CustomerId, dbCustomer.FirstName, dbCustomer.LastName, dbCustomer.Email); return(appCustomer); }
/// <summary> /// This Method display the order of the day when given the date /// </summary> /// <param name="context"></param> /// <param name="orderDate"></param> /// <returns></returns> public ICollection <Orders> GetDayOrders(project0Context context, DateTime orderDate) { var order = context.Orders .Where(o => o.OrderDate == orderDate) .ToList(); return(order); }
public StoresController(ILogger <StoresController> logger, IStore storeRepo, IProduct productRepo, IOrder orderRepo, project0Context context) { _logger = logger; _storeRepo = storeRepo; _productRepo = productRepo; _orderRepo = orderRepo; _context = context; }
public List <Order> GetAllOrdersByStore(int storeID) { using var context = new project0Context(_dbContext); var dbStoreOrders = context.Orders.Where(o => o.StoreId == storeID).ToList(); return(dbStoreOrders.Select(o => new Order(o.CustomerId, o.StoreId, o.Date, o.OrderNumber, o.OrderTotal)).ToList()); }
public List <Order> GetAllOrders() { // get the context of the db using var context = new project0Context(_dbContext); var dbOrders = context.Orders.ToList(); return(dbOrders.Select(o => new Order(o.CustomerId, o.StoreId, o.Date, o.OrderNumber, o.OrderTotal)).ToList()); }
/// <summary> /// Gets Customer By Name /// </summary> /// <returns>Customer</returns> public Library.Customer GetCustomerByName(string firstName, string lastName) { using var context = new project0Context(_dbContext); var dbCustomers = context.Customers.First(c => c.FirstName == firstName && c.LastName == lastName); var customer = new StoreApp.Library.Customer(dbCustomers.CustomerId, dbCustomers.FirstName, dbCustomers.LastName, dbCustomers.Email); return(customer); }
public void DisplayMenu() { Console.WriteLine("Welcome to World Electronics Where Technology Meets Creativity"); Console.WriteLine("How May I Help Today. Enter 'B' for Shoping; 'C' to get Customer's Information"); Console.WriteLine("Or 'S' for Store Locationss and 'V' to view Orders History:"); string str = Console.ReadLine(); //check if the user input the right variable while (str.Length > 1) { Console.WriteLine("Welcome to World Electronics Where Technology Meets Creativity"); Console.WriteLine("How May I Help Today. Enter 'B' for Shoping; 'C' to get Customer's Information"); Console.WriteLine("Or 'S' for Store Locationss and 'V' to view Orders History:"); str = Console.ReadLine(); } char choice; //this allows the usee to enter input in lower case string ch = str.ToUpper(); choice = ch[0]; using project0Context context = new project0Context(); Cart cart = new Cart(); switch (choice) { case 'B': cart.Buying(context); BackToMenu(); break; case 'C': CustomerDal customer = new CustomerDal(); customer.CustomersHome(context); BackToMenu(); break; case 'V': OrderDal order = new OrderDal(); order.DisplayCustomerHist(context, 1); BackToMenu(); break; case 'S': StoreDal store = new StoreDal(); Console.WriteLine("showing store 1:"); store.ShowStoreAddress(context, 1); BackToMenu(); break; default: BackToMenu(); break; } }
public void DeleteCustomer(Customer customer) { using var context = new project0Context(_context); var dbCustomer = context.Customers .Where(i => i.CustomerId == customer.CustomerId) .FirstOrDefault(); context.Remove(dbCustomer); context.SaveChanges(); }
public void UpdateOrder(Order order) { using var context = new project0Context(_contextOptions); var dbOrder = context.Orders .Where(o => o.OrderId == order.OrderId) .FirstOrDefault(); dbOrder.OrderTotal = order.OrderTotalPrice; context.SaveChanges(); }
/// <summary> /// /// </summary> /// <param name="storeId"></param> /// <returns></returns> public void DisplayOrderHistoryofStore(project0Context context, int storeId) { List <int> customerId = defaultStore.GetCustomersByStoreId(context, storeId); foreach (int cus in customerId) { var inOrder = context.Orders.FirstOrDefault(c => c.UserId == cus); Console.WriteLine($"OrderId: {inOrder.OrderId}\tCustomerId: {inOrder.UserId}\tTotal Amount: {inOrder.Total}\tDate: {inOrder.OrderDate}"); } }
public void DeleteOrder(Order order) { using var context = new project0Context(_contextOptions); var dbOrder = context.Orders .Where(i => i.OrderId == order.OrderId) .FirstOrDefault(); context.Remove(dbOrder); context.SaveChanges(); }
public project0Context getContext() { string constring = File.ReadAllText("/Revature/Sql/connectionstring.txt"); DbContextOptions <project0Context> options = new DbContextOptionsBuilder <project0Context>().UseSqlServer(constring).Options; var context = new project0Context(options); return(context); }