Ejemplo n.º 1
0
 internal static List <Product> GetAllProducts()
 {
     using (CashRegistryModel db = new CashRegistryModel())
     {
         return(db.Product.ToList());
     }
 }
        private static void FinalizeTransaction(Transaction transaction)
        {
            Console.WriteLine("Select payment method: \n" +
                              "\t1 - Cash\n" +
                              "\t2 - Card");
            while (transaction.PaymentMethod == null)
            {
                string userInput = Console.ReadLine();

                if (userInput == "1")
                {
                    transaction.PaymentMethod = "Cash";
                }
                else if (userInput == "2")
                {
                    transaction.PaymentMethod = "Card";
                }
                else
                {
                    Menu.PrintInvalidChoice();
                }
            }


            using (CashRegistryModel db = new CashRegistryModel())
            {
                transaction.Staff = db.Staff.Find(transaction.Staff.Id); // fetching the staff "again" to avoid conflicts
                db.Transaction.Add(transaction);
                db.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        internal static void Create()
        {
            bool   successful = false;
            string name, category;
            double price = 0.00;

            while (!successful)
            {
                Console.WriteLine("** Create Product");

                Console.Write("Name: ");
                name = Console.ReadLine();

                Console.Write("Category: ");
                category = Console.ReadLine();

                price = GetPrice(false, null);

                using (CashRegistryModel db = new CashRegistryModel())
                {
                    Product product = new Product {
                        Name = name, Category = category, Price = price
                    };

                    db.Product.Add(product);
                    db.SaveChanges();

                    Console.WriteLine("Created product:");
                    Console.WriteLine(PrintInfo(product));
                    successful = true;
                }
            }
        }
 private static List <Transaction> GetAllTransactionsWithTransactionComponents()
 {
     using (CashRegistryModel db = new CashRegistryModel())
     {
         return(db.Transaction.Include("Staff").Include("TransactionComponent").ToList());
     }
 }
Ejemplo n.º 5
0
 internal static List <Staff> GetAllStaff()
 {
     using (CashRegistryModel db = new CashRegistryModel())
     {
         return(db.Staff.ToList());
     }
 }
Ejemplo n.º 6
0
 internal static void ListAll()
 {
     using (CashRegistryModel db = new CashRegistryModel())
     {
         var products = db.Product.ToList();
         products.ForEach(x => Console.WriteLine(PrintInfo(x)));
     }
 }
Ejemplo n.º 7
0
 internal static void ListAll()
 {
     using (CashRegistryModel db = new CashRegistryModel())
     {
         var staff = db.Staff.ToList();
         staff.ForEach(x => Console.WriteLine(PrintInfo(x)));
     }
 }
 private static void PrintPossibleLactoseIntolerant()
 {
     using (CashRegistryModel db = new CashRegistryModel())
     {
         db.Transaction
         .Where(t => t.TransactionComponent.All(tc => tc.ProductCategory != "Dairy"))     // Get the people that could be lactose intolerant
         .ToList()
         .ForEach(t => Console.WriteLine(GetShortSummary(t)));
     }
 }
 private static void PrintHealthyPeople()
 {
     using (CashRegistryModel db = new CashRegistryModel())
     {
         db.Transaction
         .Where(t => t.TransactionComponent.All(tc => tc.ProductCategory == "Fruit"))     // Only get the people that ONLY buys fruits
         .ToList()
         .ForEach(t => Console.WriteLine(t.PaymentMethod + " - " + GetShortSummary(t)));
     }
 }
 private static void PrintBigSpenders()
 {
     using (CashRegistryModel db = new CashRegistryModel())
     {
         db.Transaction
         .ToList()     // Need to convert to list to be able to use GetTotalSum
         .Where(t => GetTotalSum(t) >= 100)
         .ToList()
         .ForEach(t => Console.WriteLine(GetShortSummary(t)));
     }
 }
 private static void PrintByTotalSum()
 {
     using (CashRegistryModel db = new CashRegistryModel())
     {
         db.Transaction
         .ToList()
         .OrderByDescending(t => GetTotalSum(t)) // Get highest sum first
         .ToList()                               // Needs to do this twice to get Linq to cooperate
         .ForEach(t => Console.WriteLine(GetShortSummary(t)));
     }
 }
Ejemplo n.º 12
0
        private static bool RemoveProduct(int productId)
        {
            using (CashRegistryModel db = new CashRegistryModel())
            {
                Product productToRemove = db.Product.Find(productId);

                if (productToRemove != null)
                {
                    db.Product.Remove(productToRemove);
                    db.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 13
0
        private static bool RemoveStaffMember(int userId)
        {
            using (CashRegistryModel db = new CashRegistryModel())
            {
                Staff staffToRemove = db.Staff.Find(userId);

                if (staffToRemove != null)
                {
                    db.Staff.Remove(staffToRemove);
                    db.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
        private static void PrintByStaffMember()
        {
            using (CashRegistryModel db = new CashRegistryModel())
            {
                List <Staff> staff = db.Staff
                                     .Where(s => s.Transaction.Count > 0) // Only get the staff that has any transactions
                                     .ToList();

                foreach (Staff s in staff)
                {
                    Console.WriteLine("\n\n" + StaffHandler.PrintInfo(s));

                    foreach (Transaction t in s.Transaction.OrderByDescending(t => GetTotalSum(t))) // Order by transaction sum
                    {
                        Console.WriteLine(GetShortSummary(t));
                    }
                }
            }
        }
        internal static void PrintSummary() // Method to get summary of all transacxtions
        {
            using (CashRegistryModel db = new CashRegistryModel())
            {
                Console.Clear();

                // Get all of the transactions:
                List <Transaction> allTransactions = db.Transaction.ToList();

                // Print out the summary:
                allTransactions.ForEach(transaction => Console.WriteLine(GetShortSummary(transaction)));

                // Print data about the collection:
                double totalSum = GetTotalSum(allTransactions); // Assign the total to a variable to not run the loop twice
                Console.WriteLine(String.Format("\nTotal number of transactions: {0}\n" +
                                                "Total sum: {1}\n" +
                                                "Average sum: {2}", allTransactions.Count, totalSum, totalSum / allTransactions.Count));
            }
        }
Ejemplo n.º 16
0
        internal static void Create()
        {
            bool   socialSecurityNumberValid = false;
            string socSec = null;

            Console.WriteLine("** Create Staff member");

            Console.Write("First name: ");
            string firstName = Console.ReadLine();

            Console.Write("Last name: ");
            string lastName = Console.ReadLine();

            while (!socialSecurityNumberValid)
            {
                Console.Write("Social Security Number: ");
                string tempSocSec = Console.ReadLine();

                if (ValidateSocialSecurityNumber(tempSocSec))
                {
                    socSec = tempSocSec;
                    socialSecurityNumberValid = true;
                }
            }

            using (CashRegistryModel db = new CashRegistryModel())
            {
                Staff staff = new Staff();

                staff.FirstName            = firstName;
                staff.LastName             = lastName;
                staff.SocialSecurityNumber = socSec;

                db.Staff.Add(staff);
                db.SaveChanges();
            }
        }
Ejemplo n.º 17
0
        internal static void Edit()
        {
            bool editComplete = false;

            Console.Clear();
            Console.WriteLine("** Edit Product");
            ListAll();
            Console.WriteLine("\nEnter ID of the product you want to edit. 0 (zero) for exit");

            while (!editComplete)
            {
                Console.Write("Id: ");
                string userInput = Console.ReadLine();
                if (userInput == "0")
                {
                    break;                   // Exit early if 0 is entered
                }
                try
                {
                    int productId = int.Parse(userInput);
                    using (CashRegistryModel db = new CashRegistryModel())
                    {
                        Product productToEdit = db.Product.Find(productId);

                        if (productToEdit != null)
                        {
                            bool isModified = false;

                            Console.WriteLine("If you want to change the value enter the new. If you don't want to change the value leave the row empty.\n");
                            Console.Write("Name: ");
                            string name = Console.ReadLine();

                            Console.Write("Category: ");
                            string category = Console.ReadLine();

                            double price = GetPrice(true, productToEdit.Price);

                            if (name != "")
                            {
                                isModified         = true;
                                productToEdit.Name = name;
                            }
                            if (category != "")
                            {
                                isModified             = true;
                                productToEdit.Category = category;
                            }
                            if (price > 0)
                            {
                                isModified          = true;
                                productToEdit.Price = price;
                            }

                            editComplete = true;
                            if (isModified)
                            {
                                db.SaveChanges();
                            }
                            Console.WriteLine("Edit complete:");
                            Console.WriteLine(PrintInfo(productToEdit));
                        }
                        else
                        {
                            Console.WriteLine(String.Format("No product with id {0} was found.", productId));
                        }
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine("Invalid formatted ID.");
                }
            }
        }
Ejemplo n.º 18
0
        internal static void Edit()
        {
            bool editComplete = false;

            Console.Clear();
            Console.WriteLine("** Edit Staff member");
            ListAll();
            Console.WriteLine("\nEnter ID of the staff member you want to edit. 0 (zero) for exit");

            while (!editComplete)
            {
                Console.Write("Id: ");
                string userInput = Console.ReadLine();
                if (userInput == "0")
                {
                    break;                   // Exit early if 0 is entered.
                }
                try
                {
                    int userId = int.Parse(userInput);
                    using (CashRegistryModel db = new CashRegistryModel())
                    {
                        Staff staffToEdit = db.Staff.Find(userId);

                        if (staffToEdit != null)
                        {
                            bool   socialSecurityNumberValid = false;
                            bool   isModified = false;
                            string socSec     = "";

                            Console.WriteLine("If you want to change the value enter the new. If you don't want to change the value leave the row empty.\n");
                            Console.Write("First name: ");
                            string firstName = Console.ReadLine();

                            Console.Write("Last name: ");
                            string lastName = Console.ReadLine();

                            while (!socialSecurityNumberValid)
                            {
                                Console.Write("Social Security Number: ");
                                string tempSocSec = Console.ReadLine();

                                if (ValidateSocialSecurityNumber(tempSocSec))
                                {
                                    socSec = tempSocSec;
                                    socialSecurityNumberValid = true;
                                }
                            }

                            if (firstName != "")
                            {
                                isModified            = true;
                                staffToEdit.FirstName = firstName;
                            }
                            if (lastName != "")
                            {
                                isModified           = true;
                                staffToEdit.LastName = lastName;
                            }
                            if (socSec != "")
                            {
                                isModified = true;
                                staffToEdit.SocialSecurityNumber = socSec;
                            }

                            editComplete = true;
                            if (isModified)
                            {
                                db.SaveChanges();
                            }
                            Console.WriteLine("Edit complete:");
                            Console.WriteLine(PrintInfo(staffToEdit));
                        }
                        else
                        {
                            Console.WriteLine(String.Format("No staff member with id {0} was found.", userId));
                        }
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine("Invalid formatted ID.");
                }
            }
        }