コード例 #1
0
        public static void AddDetail(string firstName, string lastName)
        {
            using (var context = new FinalExamEntities())
            {
                var query = from user in context.Customers
                            where user.CustFirstName == firstName
                            select user.CustNum;

                int id = query.FirstOrDefault();

                string username = lastName;

                string password = CreatePassword(firstName, lastName);



                Customer_Detail newDet = new Customer_Detail()
                {
                    CustNum      = id,
                    CustUserName = username,
                    CustPassword = password
                };

                context.Customer_Detail.Add(newDet);
                context.SaveChanges();

                Console.WriteLine($"Your username is {username}");
                Console.WriteLine($"Your password is {password}");
            }
        }
コード例 #2
0
        public static void ValidateQuantity(int quantity, string itemChoice, int id)
        {
            if (quantity > 0)
            {
                using (var context = new FinalExamEntities())
                {
                    var result = context.Products.Where(item => item.Descr == itemChoice).Select(item => item.Onhand).FirstOrDefault();

                    if (result >= quantity)
                    {
                        //insert record in Sales
                        Sale.NewSale(id);

                        //insert record in SalesInvoice
                        SalesInvoice.NewSaleInvoice(id, quantity, itemChoice);

                        //reduce onhand by quantity purchased
                        var prod = context.Products.Where(item => item.Descr == itemChoice).FirstOrDefault <Product>();
                        prod.Onhand = prod.Onhand - quantity;
                        context.SaveChanges();
                        Console.WriteLine("Thank you for your purchase!");
                    }
                    else
                    {
                        Console.WriteLine("Sorry, not enough stock.");
                    }
                }
            }
            else
            {
                Console.WriteLine("Sorry, quantity must be greater than 0.");
            }
        }
コード例 #3
0
        public static void DisplayPrice(string productSelection)
        {
            using (var context = new FinalExamEntities())
            {
                var result = context.Products.Where(item => item.Descr == productSelection).Select(item => item.MSRP).Distinct();

                foreach (var item in result)
                {
                    Console.WriteLine($"{productSelection}: {item}");
                }
            }
        }
コード例 #4
0
        public static int GetId(string username)
        {
            using (var context = new FinalExamEntities())
            {
                var query = from user in context.Customer_Detail
                            where user.CustUserName == username
                            select user.CustNum;

                int id = query.FirstOrDefault();

                return(id);
            }
        }
コード例 #5
0
        public static void ProductsAvailable(string prodType)
        {
            using (var context = new FinalExamEntities())
            {
                var result = context.Products.Where(item => item.ProductType == prodType).Select(item => item.Descr).Distinct();

                int i = 1;
                foreach (var item in result)
                {
                    Console.WriteLine($"{i}: {item}");
                    i++;
                }
            }
        }
コード例 #6
0
        public static void GetProductTypes()
        {
            using (var context = new FinalExamEntities())
            {
                var result = context.Products.Select(item => item.ProductType).Distinct();

                int i = 1;
                foreach (var item in result)
                {
                    Console.WriteLine($"{i}: {item}");
                    i++;
                }
            }
        }
コード例 #7
0
        public static Boolean IsCheckCredentials(string username, string password)
        {
            using (var context = new FinalExamEntities())
            {
                var query = context.Customer_Detail.Where(user => user.CustUserName == username).FirstOrDefault <Customer_Detail>();

                var query2 = context.Customer_Detail.Where(user => user.CustPassword == password).FirstOrDefault <Customer_Detail>();

                if (query != null && query2 != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
コード例 #8
0
        public static void NewSaleInvoice(int id, int quantity, string desc)
        {
            using (var context = new FinalExamEntities())
            {
                var salesNum = context.Sales.Where(user => user.CustNum == id).Select(user => user.SalesNum).FirstOrDefault();
                var prodNum  = context.Products.Where(user => user.Descr == desc).Select(user => user.ProductNum).FirstOrDefault();
                var price    = context.Products.Where(user => user.Descr == desc).Select(user => user.MSRP).FirstOrDefault();


                SalesInvoice invoice = new SalesInvoice()
                {
                    SalesNum   = salesNum,
                    ProductNum = prodNum,
                    Quantity   = quantity,
                    SalesPrice = price * quantity
                };

                context.SalesInvoices.Add(invoice);
                context.SaveChanges();
            }
        }