Exemplo n.º 1
0
        static void ShowOrderHistory(Customer customer)
        {
            using var context = new DbRestaurantContext();

            var listOfOrders = context.Orders.Where(x => x.CustomerId == customer.CustomerId).Include("Orderlines"); // grab an type x where ==)

            var listOfProducts = from orderl in context.Orderlines
                                 join prd in context.Products on orderl.ProductId equals prd.ProductId
                                 where orderl.ProductId == prd.ProductId
                                 select prd;

            listOfOrders.ToList();
            listOfProducts.ToList();

            Console.WriteLine($"{customer.FullName} ordered");
            foreach (var order in listOfOrders)
            {
                Console.Write($"Order ID: {order.OrderId}\t");

                /*foreach (var product in listOfProducts)
                 * {
                 *  Console.WriteLine($"{product.ProductName}/tcost per item: {product.Cost}");
                 * }*/
                foreach (var orderline in order.Orderlines)
                {
                    Console.WriteLine($"Product code/id: {orderline.ProductId}\tQuantity purchased: {orderline.Quantity}");
                }
                Console.WriteLine($"Order Total = {order.Total}");
            }
        }
Exemplo n.º 2
0
        public Domain.Model.Store GetDomainStore(int storeId)
        {
            var _context   = new DbRestaurantContext();
            var data_store = _context.Stores.Include("Inventorys").Include("Orders.Orderlines.Product").Include("Orders.Customer").SingleOrDefault(s => s.StoreId == storeId);



            return(Mapper.MapStoreWithDetails(data_store));
        }
Exemplo n.º 3
0
        /* public List<string> LoadProductNamesFromStoreInStock(IDataStore store)
         * {
         *   using DbRestaurantContext context = new DbRestaurantContext();
         *
         *
         *   // inventory links to both products and store(s)
         *   // filter by the store id
         *   // select all products where storeid = store.storeID
         *
         *   var storeId = store.StoreId;
         *
         *   var productIDsInStock = from inventorys in context.Inventorys
         *                           where inventorys.StoreId == storeId
         *                           select inventorys.ProductId;
         *   // these are the product ids, but we need the names as well for most uses
         *
         *   /* IQueryable<string> productNamesInStock;
         *    foreach (var productID in productIDsInStock)
         *    {
         *        productNamesInStock = from products in context.Products where products.ProductId == productID select products.ProductName;
         *    }
         *
         *
         *     Error: list of strings stays empty*/

        /* throw new NotImplementedException();
         *
         *
         * }*/

        public Products LoadProductByID(int productID)
        {
            using DbRestaurantContext context = new DbRestaurantContext();

            var productMatched = from product in context.Products
                                 where product.ProductId == productID
                                 select product;

            return(productMatched.First());
        }
Exemplo n.º 4
0
 public void InitializeStore(Stores S_Stores, IDataStore store)
 {
     using DbRestaurantContext context = new DbRestaurantContext();
     store.StoreName     = S_Stores.StoreName;
     store.StreetAddress = S_Stores.StreetAddress;
     store.City          = S_Stores.City;
     store.State         = S_Stores.State;
     store.Zipcode       = S_Stores.Zipcode;
     store.StoreId       = S_Stores.StoreId;
 }
Exemplo n.º 5
0
        public Stores LoadStoreByID(int storeID)
        {
            using DbRestaurantContext context = new DbRestaurantContext();

            var storeMatched = from store in context.Stores
                               where store.StoreId == storeID
                               select store;

            return(storeMatched.First());
        }
Exemplo n.º 6
0
        public List <Customers> LoadCustomersByName(string fullName)
        {
            using DbRestaurantContext context = new DbRestaurantContext();

            var customersMatched = from customer in context.Customers
                                   where customer.FullName == fullName
                                   select customer;

            return(customersMatched.ToList());
        }
Exemplo n.º 7
0
        public Customers LoadCustomerByID(int customerID)
        {
            using DbRestaurantContext context = new DbRestaurantContext();

            var customersMatched = from customer in context.Customers
                                   where customer.CustomerId == customerID
                                   select customer;

            return(customersMatched.First());
        }
Exemplo n.º 8
0
        static HashSet <Customers> GetCustomers(Stores store)
        {
            using var context2 = new DbRestaurantContext();
            var listOfCustomers = from order in context2.Orders join customer in context2.Customers
                                  on order.CustomerId equals customer.CustomerId
                                  where order.StoreId == store.StoreId
                                  select customer;
            HashSet <Customers> setOfCustomers = new HashSet <Customers> (listOfCustomers);

            return(setOfCustomers);
        }
Exemplo n.º 9
0
        public int GetCustomerID(string username, string password)
        {
            using DbRestaurantContext context = new DbRestaurantContext();
            var customerIDList = from customer in context.Customers
                                 where username == customer.Username &&
                                 password == customer.Password
                                 select customer.CustomerId;
            var customerID = customerIDList.FirstOrDefault(); // unique combination so can return single, no duplicates possible from db

            return(customerID);
        }
Exemplo n.º 10
0
        public List <Domain.Model.Store> GetAllDomainStores()
        {
            var _context     = new DbRestaurantContext();
            var listOfStores = _context.Stores.Include("Inventorys").Include("Orders.Orderlines.Product").Include("Orders.Customer");

            List <Domain.Model.Store> domain_listOfStores = new List <Domain.Model.Store>();

            foreach (var store in listOfStores)
            {
                domain_listOfStores.Add(Mapper.MapStoreWithDetails(store));
            }
            return(domain_listOfStores);
        }
Exemplo n.º 11
0
        public void SaveProduct(IDataProduct product)
        {
            using DbRestaurantContext context = new DbRestaurantContext();
            var P_Products = new Products();

            // add BusinessLogic Customer to DbCustomer
            P_Products.ProductName = product.ProductName;
            P_Products.Cost        = product.Cost;


            context.Add(P_Products);
            context.SaveChanges();
        }
Exemplo n.º 12
0
        public void SaveCustomer(ICustomer customer)
        {
            using DbRestaurantContext context = new DbRestaurantContext();
            var C_Customer = new Customers();

            // add BusinessLogic Customer to DbCustomer
            C_Customer.FullName = customer.FullName;
            C_Customer.Password = customer.Password;
            C_Customer.Username = customer.Username;


            context.Add(C_Customer);
            context.SaveChanges();
        }
Exemplo n.º 13
0
        public void SaveInventory(IDataInventory inventory, IDataProduct product, IDataStore store)
        {
            using DbRestaurantContext context = new DbRestaurantContext();
            var I_Inventory = new Inventorys();

            // add BusinessLogic Inventory to DbInventory
            I_Inventory.ProductId = product.ProductId;
            I_Inventory.StoreId   = store.StoreId;

            I_Inventory.Quantity = inventory.Quantity;


            context.Add(I_Inventory);
            context.SaveChanges();
        }
Exemplo n.º 14
0
        public void SaveOrder(Orders order, ICustomer customer, IDataStore store)
        {
            using DbRestaurantContext context = new DbRestaurantContext();
            var O_Orders = new Orders();

            // add BusinessLogic Order to DBOrders
            O_Orders.CustomerId = customer.CustomerId;
            O_Orders.StoreId    = store.StoreId;
            O_Orders.Total      = order.Total;

            O_Orders.TimeOrdered = DateTime.Now; // local time


            context.Add(O_Orders);
            context.SaveChanges();
        }
Exemplo n.º 15
0
        public void SaveStore(IDataStore store)
        {
            using DbRestaurantContext context = new DbRestaurantContext();
            var S_Stores = new Stores();

            // add BusinessLogic Store to DbStores
            S_Stores.StoreName     = store.StoreName;
            S_Stores.StreetAddress = store.StreetAddress;
            S_Stores.City          = store.City;
            S_Stores.State         = store.State;
            S_Stores.Zipcode       = store.Zipcode;


            context.Add(S_Stores);
            context.SaveChanges();
        }
Exemplo n.º 16
0
        public List <int> LoadProductIDsFromStoreInStock(Stores store)
        {
            using DbRestaurantContext context = new DbRestaurantContext();


            // inventory links to both products and store(s)
            // filter by the store id
            // select all products where storeid = store.storeID

            var storeId = store.StoreId;

            var productIDsInStock = from inventorys in context.Inventorys
                                    where inventorys.StoreId == storeId
                                    select inventorys.ProductId;

            return(new List <int>(productIDsInStock));
        }
Exemplo n.º 17
0
        public IEnumerable <Products> GetProductsInStock(int storeId)
        {
            /* using var _context = new DbRestaurantContext();
             *
             * var listOfStoresAndProducts = _context.Stores.Include(s => s.StoreId == storeId)
             *                                   .Include(i => i.Inventorys)
             *                                   .ThenInclude(p => p.Product);
             * // cannot return an iqueryable without a string so need to convert to dictionary
             * Dictionary<Inventorys, Products> storesInvAndProducts = new Dictionary<Inventorys, Products>();
             * foreach (var store in listOfStoresAndProducts)
             * {
             *   storesInvAndProducts.Add(store.Inventorys, store.Inventorys.)
             * }
             *
             * return listOfProducts;*/


            // need inventorys and then need products matching those inventory.products

            using var context = new DbRestaurantContext();

            /*var storeIncludingInventorys = context.Stores.Include(s => s.StoreId == storeId)
             *                                   .Include(i => i.Inventorys).FirstOrDefault();*/

            var inventorys = context.Inventorys.Where(i => i.StoreId == storeId).Include(p => p.Product);

            // convert to list
            var productslist = new List <Products>();

            foreach (var inventory in inventorys)
            {
                productslist.Add(inventory.Product);
            }

            return(productslist);
        }
Exemplo n.º 18
0
 public List <Inventorys> LoadInventorys()
 {
     using DbRestaurantContext context = new DbRestaurantContext();
     return(context.Inventorys.ToList());
 }
Exemplo n.º 19
0
        /*static void ShowOrderHistory(Store store)
         * {
         *
         * }*/

        static void AddOrder(Customer customer, Stores store)
        {
            // NOTE: REJECT ORDERLINE IF QUANTITY ORDERED IS MORE THAN QUANTITY IN INVENTORY
            // do a while loop to keep asking for customer to buy product
            Console.WriteLine("Add an order");
            Console.WriteLine("Your store has the following to choose from");



            var PDAL = new ProductDAL();
            var productIDsInStock = PDAL.LoadProductIDsFromStoreInStock(store); // need to load product ids for the specific store here

            // select products where productid matches one of the items(ids) in the list
            foreach (var productID in productIDsInStock)
            {
                var Product_products = PDAL.LoadProductByID(productID);

                //output list of products
                Console.WriteLine(Product_products.ProductId + " " + Product_products.ProductName + " " + Product_products.Cost);
            }
            var newOrder = new Orders();

            newOrder.Total      = 0;                   // need a value to do =+
            newOrder.StoreId    = store.StoreId;       // order has to be at a specific store. Store was selected above
            newOrder.CustomerId = customer.CustomerId; // order has to be placed by a customer. customer passed above

            using var ctx = new DbRestaurantContext();
            var ListOfallOrderIDs = from order in ctx.Orders select order.OrderId;
            var newOrderID        = ListOfallOrderIDs.Max() + 1;

            bool doneOrdering = false;

            using var context = new DbRestaurantContext();

            context.Orders.Add(newOrder);
            newOrder.TimeOrdered = DateTime.Now;
            context.SaveChanges();

            while (doneOrdering == false) // buy several products
            {
                Console.Write("Select from the above...");
                Console.WriteLine("For example: 7");
                var productIDChosen = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine("How many would you like to buy?");
                int pQuantity = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Stop ordering? (y/n)");
                var yN = Console.ReadLine();
                if (yN == "y")
                {
                    doneOrdering = true;
                }
                // if input matches a product id TO BE IMPLEMENTED

                // get product details and add/pass that to the order
                var productToBeOrdered = PDAL.LoadProductByID(productIDChosen);



                var newOrderline = new Orderlines()
                {
                    ProductId = productIDChosen,
                    Quantity  = pQuantity,
                    OrderId   = newOrderID
                };

                newOrder.Total += productToBeOrdered.Cost * pQuantity;
                context.Orderlines.Add(newOrderline);
            }



            // Display total cost
            Console.WriteLine("Your order total is " + newOrder.Total);
            Console.WriteLine("Do you confirm the purchase? (y/n)");
            var input = Console.ReadLine();

            if (input == "y" || input == "Y")
            {
                //save order in db

                /*var oDAL = new OrderDAL();
                 * oDAL.SaveOrder(newOrder, customer, store);*/
                // put the order time

                context.SaveChanges();
            }
            else
            {
                Console.WriteLine("Order cancelled.");
                Console.WriteLine("You will not be charged");
                return;
            }
        }
Exemplo n.º 20
0
 public List <Stores> LoadAllStores()
 {
     using DbRestaurantContext context = new DbRestaurantContext();
     return(context.Stores.ToList());
 }
Exemplo n.º 21
0
 public List <Customers> LoadAllCustomers()
 {
     using DbRestaurantContext context = new DbRestaurantContext();
     return(context.Customers.ToList());
 }
Exemplo n.º 22
0
 public List <Orders> LoadOrders()
 {
     using DbRestaurantContext context = new DbRestaurantContext();
     return(context.Orders.Include("Orderlines").Include("Customers").ToList());
 }
Exemplo n.º 23
0
 public List <Products> LoadAllProducts()
 {
     using DbRestaurantContext context = new DbRestaurantContext();
     return(context.Products.ToList());
 }