/// <summary>
        /// quaries the database order history
        /// </summary>
        /// <typeparam name="T">type of property to search</typeparam>
        /// <param name="ID">id of person</param>
        /// <param name="get">function that retrieves the quaried item from the order history instance </param>
        /// <returns>list of quaried data</returns>
        private static List <T> SearchPerson <T>(int ID, Func <Orders, OrderData, T> get)
        {
            if (Validation.CustID(ID))
            {
                var output = new List <T>();

                using (var context = new POneContext(POne.dtb.Data.connection))
                {
                    var orders = context.Orders.ToList();
                    var data   = context.OrderData.ToList();
                    foreach (var itemX in orders)
                    {
                        foreach (var itemY in data)
                        {
                            if (itemX.OrdId == itemY.OrdId && itemX.CustId == ID)
                            {
                                output.Add(get(itemX, itemY));
                            }
                        }
                    }
                }

                return(output);
            }

            throw new Exception("Error: Invalid Customer Reference Cought By Server");
        }
Example #2
0
 /// <summary>
 /// retrieve the price of a product
 /// </summary>
 /// <param name="PID">id of product</param>
 /// <returns>price of product</returns>
 public static decimal GetPrice(int PID)
 {
     using (var context = new POneContext(connection))
     {
         return(context.Products.Find(PID).Price);
     }
 }
Example #3
0
 /// <summary>
 /// retrieves customer name from id
 /// </summary>
 /// <param name="ID">customer id</param>
 /// <returns>name of customer</returns>
 public static string GetCustomer(int ID)
 {
     using (var context = new POneContext(connection))
     {
         return(context.Customers.Find(ID).Name);
     }
 }
        /// <summary>
        /// retrieves quantities of orders placed
        /// </summary>
        /// <param name="ID">id of location</param>
        /// <returns>list of quantities</returns>
        public static List <int> GetLocationHistoryQuantity(int ID)
        {
            if (Validation.LocID(ID))
            {
                var output = new List <int>();

                using (var context = new POneContext(POne.dtb.Data.connection))
                {
                    var orders = context.Orders.ToList();
                    var data   = context.OrderData.ToList();
                    foreach (var itemX in orders)
                    {
                        foreach (var itemY in data)
                        {
                            if (itemX.OrdId == itemY.OrdId && context.Products.Find(itemY.PrdId).LocId == ID)
                            {
                                output.Add(itemY.Quantity);
                            }
                        }
                    }
                }

                return(output);
            }

            throw new Exception("Error: Invalid Location Reference Cought By Server");
        }
Example #5
0
 /// <summary>
 /// returns a list of customer names
 /// </summary>
 /// <returns>names</returns>
 public static List <string> GetCustomers()
 {
     using (var context = new POneContext(connection))
     {
         return((from f in context.Customers select f.Name).ToList());
     }
 }
Example #6
0
 /// <summary>
 /// retrieves store name from id
 /// </summary>
 /// <param name="ID">store id</param>
 /// <returns>store name</returns>
 public static string GetStore(int ID)
 {
     using (var context = new POneContext(connection))
     {
         return(context.Locations.Find(ID).Name);
     }
 }
Example #7
0
 /// <summary>
 /// Place an order to the database
 /// </summary>
 /// <param name="customer">id of customer placeing order</param>
 /// <param name="order">object containing the list of order items</param>
 public static void AddOrder(int customer, IOrderList order)
 {
     using (var context = new POneContext(connection))
     {
         decimal price = 0;
         foreach (var orderdata in order.Cart)
         {
             price += orderdata.Price * orderdata.Quantity;
         }
         var ticket = new Orders
         {
             CustId    = customer,
             Total     = price,
             Stamp     = DateTime.Now,
             OrderData = order.Cart
         };
         foreach (var orderdata in order.Cart)
         {
             context.Products.Find(orderdata.PrdId).Stock -= orderdata.Quantity;
             orderdata.OrdId = ticket.OrdId;
         }
         context.Add(ticket);
         context.SaveChanges();
     }
 }
Example #8
0
 /// <summary>
 /// returns a list of store names
 /// </summary>
 /// <returns>store names</returns>
 public static List <string> GetStores()
 {
     using (var context = new POneContext(connection))
     {
         return((from f in context.Locations select f.Name).ToList());
     }
 }
Example #9
0
 /// <summary>
 /// removes a product from the database
 /// </summary>
 /// <param name="ID">id of item</param>
 public static void RemoveProduct(int ID)
 {
     using (var context = new POneContext(connection))
     {
         context.Remove(context.Products.Find(ID));
         context.SaveChanges();
     }
 }
Example #10
0
 /// <summary>
 /// remove a customer from the database
 /// </summary>
 /// <param name="ID">id of customer</param>
 public static void RemoveCustomer(int ID)
 {
     using (var context = new POneContext(connection))
     {
         context.Customers.Remove(context.Customers.Find(ID));
         context.SaveChanges();
     }
 }
Example #11
0
 /// <summary>
 /// remove a store from the database
 /// only works when the store has no products
 /// </summary>
 /// <param name="activeStore">id of store</param>
 public static void RemoveStore(int activeStore)
 {
     using (var context = new POneContext(connection))
     {
         context.Locations.Remove(context.Locations.Find(activeStore));
         context.SaveChanges();
     }
 }
Example #12
0
 /// <summary>
 /// increce the stock of an item
 /// </summary>
 /// <param name="ID">items id</param>
 /// <param name="stock">quantity to9 add</param>
 public static void StockProduct(int ID, int stock)
 {
     using (var context = new POneContext(connection))
     {
         context.Products.Find(ID).Stock += stock;
         context.SaveChanges();
     }
 }
Example #13
0
 /// <summary>
 /// add a customer to the database
 /// </summary>
 /// <param name="name">name of customer</param>
 public static void AddCustomer(string name)
 {
     using (var context = new POneContext(connection))
     {
         var customer = new Customers {
             Name = name
         };
         context.Add(customer);
         context.SaveChanges();
     }
 }
Example #14
0
 /// <summary>
 /// retrieves the id of a product from its name
 /// </summary>
 /// <param name="locationName">name of location</param>
 /// <returns>location id</returns>
 private static int LocIdFromName(string locationName)
 {
     using (var context = new POneContext(connection)) foreach (var item in context.Locations)
         {
             if (item.Name == locationName)
             {
                 return(item.LocId);
             }
         }
     return(-1);
 }
Example #15
0
 /// <summary>
 /// Add a location to the database
 /// </summary>
 /// <param name="name">Name of location</param>
 public static void AddLocation(string name)
 {
     using (var context = new POneContext(connection))
     {
         var location = new Locations {
             Name = name
         };
         context.Add(location);
         context.SaveChanges();
     }
 }
Example #16
0
 /// <summary>
 /// checks if the product is removable
 /// </summary>
 /// <param name="ID">product id</param>
 /// <returns>true if removable</returns>
 public static bool IsRemovableProduct(int ID)
 {
     using (var context = new POneContext(Data.connection))
     {
         bool hasDependencies = false;
         foreach (var item in context.OrderData)
         {
             hasDependencies = hasDependencies || item.PrdId == ID;
         }
         return(!hasDependencies);
     }
 }
Example #17
0
        /// <summary>
        /// retrieve a list of names of products
        /// </summary>
        /// <param name="ID">id of location to search</param>
        /// <returns></returns>
        public static string GetPersonNames(int ID)
        {
            if (Validation.CustID(ID))
            {
                using (var context = new POneContext(dtb.Data.connection))
                {
                    return(context.Customers.Find(ID).Name);
                }
            }

            throw new Exception("Error: Invalid Customer Reference Cought By Server");
        }
Example #18
0
        /// <summary>
        /// retrieves a list of location names
        /// </summary>
        /// <returns>names</returns>
        public static List <string> GetLocationNames()
        {
            var output = new List <string>();

            using (var context = new POneContext(POne.dtb.Data.connection))
            {
                foreach (var item in context.Locations)
                {
                    output.Add(item.Name);
                }
            }

            return(output);
        }
Example #19
0
 /// <summary>
 /// retrieves the stock of an item
 /// </summary>
 /// <param name="ID">id of item</param>
 /// <returns>stock</returns>
 public static int GetItemStock(int ID)
 {
     using (var context = new POneContext(dtb.Data.connection))
     {
         foreach (var item in context.Products)
         {
             if (item.PrdId == ID)
             {
                 return(item.Stock);
             }
         }
     }
     return(0);
 }
Example #20
0
 /// <summary>
 /// retrieves name of product
 /// </summary>
 /// <param name="ID">id of product</param>
 /// <returns>name</returns>
 public static string GetProductName(int ID)
 {
     using (var context = new POneContext(dtb.Data.connection))
     {
         foreach (var item in context.Products)
         {
             if (item.PrdId == ID)
             {
                 return(item.Name);
             }
         }
     }
     return(null);
 }
Example #21
0
 /// <summary>
 /// retrieves the price of a product
 /// </summary>
 /// <param name="ID">product id</param>
 /// <returns>price</returns>
 public static decimal GetProductPrice(int ID)
 {
     using (var context = new POneContext(dtb.Data.connection))
     {
         foreach (var item in context.Products)
         {
             if (item.PrdId == ID)
             {
                 return(item.Price);
             }
         }
     }
     return(0);
 }
 internal static bool ProdID(int ID)
 {
     using (var context = new POneContext(dtb.Data.connection))
     {
         foreach (var item in context.Products)
         {
             if (item.PrdId == ID)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
 internal static bool CustID(int ID)
 {
     using (var context = new POneContext(POne.dtb.Data.connection))
     {
         foreach (var item in context.Customers)
         {
             if (ID == item.CustId)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #24
0
        /// <summary>
        /// retrieves a list of customer ids
        /// </summary>
        /// <returns>ids</returns>
        public static List <int> GetCustomerIDs()
        {
            var output = new List <int>();

            using (var context = new POneContext(POne.dtb.Data.connection))
            {
                foreach (var item in context.Customers)
                {
                    output.Add(item.CustId);
                }
            }

            return(output);
        }
Example #25
0
 /// <summary>
 /// adds a product to the database
 /// </summary>
 /// <param name="name">name of product</param>
 /// <param name="LocID">id of products location</param>
 /// <param name="p">price of item</param>
 /// <param name="s">ctock of item</param>
 public static void AddProduct(string name, int LocID, decimal p, int s)
 {
     using (var context = new POneContext(connection))
     {
         var product = new Products
         {
             Name  = name,
             Loc   = context.Locations.Find(LocID),
             Price = p,
             Stock = s
         };
         context.Add(product);
         context.SaveChanges();
     }
 }
Example #26
0
 /// <summary>
 /// returns a product id from the product name
 /// </summary>
 /// <param name="name">item name</param>
 /// <returns>id of item</returns>
 public static int ProductFromName(string name)
 {
     using (var context = new POneContext(connection))
     {
         int output = 0;
         foreach (var item in context.Products)
         {
             if (item.Name == name)
             {
                 output = item.PrdId;
             }
         }
         return(output);
     }
 }
Example #27
0
        /// <summary>
        /// retrieves the name of a product
        /// </summary>
        /// <param name="ID">id of product</param>
        /// <returns>name</returns>
        public static string GetLocationName(int ID)
        {
            if (Validation.LocID(ID))
            {
                string output = "";

                using (var context = new POneContext(dtb.Data.connection))
                {
                    output = context.Locations.Find(ID).Name;
                }

                return(output);
            }

            throw new Exception("Error: Invalid Location Reference Cought By Server");
        }
Example #28
0
 /// <summary>
 /// returns a list of product quantities
 /// </summary>
 /// <param name="locationName">name of location</param>
 /// <returns>list of quantities</returns>
 public static List <int> GetProductQuantities(string locationName)
 {
     using (var context = new POneContext(connection))
     {
         var output = new List <int>();
         int id     = context.Locations.Find(LocIdFromName(locationName)).LocId;
         foreach (var item in context.Products)
         {
             if (item.LocId == id)
             {
                 output.Add(item.Stock);
             }
         }
         return(output);
     }
 }
Example #29
0
        /// <summary>
        /// retrieves the stock of an item
        /// </summary>
        /// <param name="ID">id of product</param>
        /// <returns>stock</returns>
        public static List <int> GetProductStock(int ID)
        {
            if (Validation.LocID(ID))
            {
                var output = new List <int>();

                using (var context = new POneContext(POne.dtb.Data.connection))
                {
                    foreach (var item in context.Products)
                    {
                        if (ID == item.LocId)
                        {
                            output.Add(item.Stock);
                        }
                    }
                }

                return(output);
            }

            throw new Exception("Error: Invalid Location Reference Cought By Server");
        }