Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 public ActionResult AddOrder(IFormCollection collection)
 {
     try
     {
         int          stoID  = Convert.ToInt32(TempData["StoID"]);
         int          custID = Convert.ToInt32(TempData["CustID"]);
         lib.Store    sto    = irepOrigSto.GetStores(stoID).First();
         lib.Customer cust   = irepOrigCust.GetCustomers(cusid: custID).First();
         lib.Order    ord    = new lib.Order(cust, sto, 0);
         irepOrig.Order(ord);
         irepOrig.EndMe();
         ord = irepOrig.GetOrdersByCust(custID).Last();
         foreach (var item in collection)
         {
             foreach (var iven in sto.iven)
             {
                 if (iven.Key.MerchID == Convert.ToInt32(item.Key))
                 {
                     var a = irepOrigMerch.GetMerch(iven.Key.MerchID).First();
                     ord.details.Add(a, Convert.ToInt32(item.Value));
                     break;
                 }
             }
         }
         foreach (var item in ord.details)
         {
             sto.ChangeStock(item.Key, -1 * item.Value);
         }
         irepOrig.AddOrder(ord);
         TempData.Keep();
         irepOrigSto.UpdateStore(sto);
         irepOrigSto.help();
         irepOrig.EndMe();
         return(RedirectToAction(nameof(EndOrder)));
     }
     catch
     {
         return(View());
     }
 }
Ejemplo n.º 3
0
        public ActionResult Create(IFormCollection collection)
        {
            try
            {
                if (Convert.ToInt32(collection["CustID"]) > 0)
                {
                    int custID = Convert.ToInt32(collection["CustID"]);
                    TempData["CustID"] = custID;
                    int stoID = Convert.ToInt32(collection["StoID"]);
                    TempData["StoID"] = stoID;

                    lib.Customer Cust     = irepOrigCust.GetCustomers(cusid: custID).First();
                    string       custName = Cust.FullName;
                    TempData["CustName"] = custName;
                }
                return(RedirectToAction(nameof(Edit)));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 4
0
        public static void Run(Project0Context dbContext)
        {
            //establish contexts with domains
            var CusCon = new ef.CustomerRep(dbContext);
            var MerCon = new ef.MerchRep(dbContext);
            var StoCon = new ef.StoreRep(dbContext);
            var OrdCon = new ef.OrderRep(dbContext);

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Manager\n");
                Console.WriteLine();

                Console.WriteLine("1:\tAdd a body");
                Console.WriteLine("2:\tStart a Search");
                Console.WriteLine("3:\tWant to Order Something?");
                Console.WriteLine("4:\tFare Thee Well");
                Console.WriteLine();
                Console.WriteLine("What do you want to do?");
                var input = Console.ReadLine();
                if (input == "1")
                {
                    string fname = null;
                    string lname = null;

                    Console.Clear();
                    Console.WriteLine("Adding a Customer\n");

                    while (fname == null)
                    {
                        Console.Write("Enter First name: ");
                        fname = Console.ReadLine();
                        if (fname == "")
                        {
                            fname = null;
                        }
                    }
                    while (lname == null)
                    {
                        Console.Write("Enter Last name: ");
                        lname = Console.ReadLine();
                        if (lname == "")
                        {
                            lname = null;
                        }
                    }
                    Console.WriteLine($"\nCreating a new Customer with \nFirst Name: {fname}\nLast Name: {lname}");

                    try
                    {
                        var newCus = new lib.Customer(fname, lname);
                        CusCon.AddCust(newCus);
                        CusCon.why();
                        var dbCusId = CusCon.GetCustomers(fname, lname).Last().CustomerID;
                        Console.WriteLine($"Customer has been added.\nID: {dbCusId}");

                        Console.WriteLine("Press a key to keep going");
                        Console.ReadKey();
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else if (input == "2")
                {
                    while (true)
                    {
                        Console.Clear();
                        Console.WriteLine("Search for something Screen");

                        Console.WriteLine("1:\tSearch for Customer");
                        Console.WriteLine("2:\tSearch for Store");
                        Console.WriteLine("3:\tSearch for Orders for Customer");
                        Console.WriteLine("4:\tSearch for Orders for Store");
                        Console.WriteLine("5:\tSearch for Order Details");
                        Console.WriteLine("6:\tLet Me Out");
                        Console.WriteLine();

                        Console.WriteLine("What do you want to do?");
                        var input2 = Console.ReadLine();
                        if (input2 == "1")
                        {
                            string fnamesearch = null;
                            string lnamesearch = null;
                            Console.Clear();
                            Console.WriteLine("Searching for Customers\n");
                            Console.WriteLine("Give me a First Name to search for ");
                            Console.WriteLine("\tor you could give me no name: ");
                            fnamesearch = Console.ReadLine();
                            if (fnamesearch == null)
                            {
                                fnamesearch = null;
                            }

                            Console.WriteLine("Now give me a Last Name to search for ");
                            Console.WriteLine("\tor you can leave nothing here also: ");
                            lnamesearch = Console.ReadLine();
                            if (lnamesearch == null)
                            {
                                lnamesearch = null;
                            }
                            Console.WriteLine($"So, I am searching for {fnamesearch} {lnamesearch} right? Give me a second.");
                            Console.WriteLine();
                            var cusSearch = CusCon.GetCustomers(fnamesearch, lnamesearch).ToList();
                            foreach (lib.Customer item in cusSearch)
                            {
                                Console.WriteLine(item.ToString() + "\n");
                            }
                            Console.WriteLine("\nPress something to continue");
                            Console.ReadKey();
                        }
                        else if (input2 == "2")
                        {
                            Console.Clear();
                            Console.WriteLine("Store: \n");
                            var sto = StoCon.GetStores().ToList();
                            foreach (lib.Store item in sto)
                            {
                                Console.WriteLine(item.ToString() + "\n");
                            }
                            Console.WriteLine("\nPunch a key to keep moving");
                            Console.ReadKey();
                        }
                        else if (input2 == "3")
                        {
                            string input2key;
                            int    custId = 0;
                            bool   isInt  = false;
                            do
                            {
                                Console.Clear();
                                Console.WriteLine("Display All Orders for a Customer\n");

                                Console.Write("Enter a Customer ID: ");
                                input2key = Console.ReadLine();
                                isInt     = Int32.TryParse(input2key, out custId);
                            }while (!isInt);

                            var results = OrdCon.GetOrdersByCust(id: custId).ToList();
                            if (results.Count > 0)
                            {
                                foreach (lib.Order ord in results)
                                {
                                    Console.WriteLine(ord.ToString() + "\n");
                                }
                            }
                            else
                            {
                                Console.WriteLine($"No results matching CustomerID {custId}");
                            }
                            Console.WriteLine("Press any key to continue.");
                            Console.ReadKey();
                        }
                        else if (input2 == "4")
                        {
                            string input2key;
                            int    stoId = 0;
                            bool   isInt = false;
                            do
                            {
                                Console.Clear();
                                Console.WriteLine("Display All Orders for a Location\n");

                                Console.Write("Enter a Location ID: ");
                                input2key = Console.ReadLine();
                                isInt     = Int32.TryParse(input2key, out stoId);
                            }while (!isInt);

                            var results = OrdCon.GetOrdersByStore(stoId).ToList();
                            if (results.Count > 0)
                            {
                                foreach (lib.Order ord in results)
                                {
                                    Console.WriteLine(ord.ToString() + "\n");
                                }
                            }
                            else
                            {
                                Console.WriteLine($"No results matching LocationID {stoId}");
                            }
                            Console.WriteLine("Press any key to continue.");
                            Console.ReadKey();
                        }
                        else if (input2 == "5")
                        {
                            string input2key;
                            int    ordId = 0;
                            bool   isInt = false;
                            do
                            {
                                Console.Clear();
                                Console.WriteLine("Display Details of an Order:\n");

                                Console.Write("Enter a Order ID: ");
                                input2key = Console.ReadLine();
                                isInt     = Int32.TryParse(input2key, out ordId);
                            }while (!isInt);

                            var result = OrdCon.GetOrdersByID(ordId).ToList().FirstOrDefault();
                            if (result == null)
                            {
                                Console.WriteLine($"No results matching OrderID {ordId}");
                            }
                            else
                            {
                                Console.WriteLine(result.ToString());
                                Console.WriteLine(result.OrderToString());
                            }
                            Console.WriteLine("Press any key to continue.");
                            Console.ReadKey();
                        }
                        else if (input2 == "6")
                        {
                            break;
                        }
                    }
                }
                else if (input == "3")
                {
                    string inputStr;
                    int    custId = 0;
                    int    stoId  = 0;
                    bool   isInt  = false;


                    do
                    {
                        Console.Clear();
                        Console.WriteLine("Place an Order Menu\n");

                        Console.Write("Enter a Customer ID: ");
                        inputStr = Console.ReadLine();
                        isInt    = Int32.TryParse(inputStr, out custId);
                    }while (!isInt);

                    var cust = CusCon.GetCustomers(cusid: custId).FirstOrDefault();
                    if (cust == null)
                    {
                        Console.WriteLine($"Customer {custId} does not exist.");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Customer found:\n");
                        Console.WriteLine(cust.ToString());
                    }

                    isInt = false;
                    do
                    {
                        Console.Clear();
                        Console.WriteLine("Place an Order Menu\n");

                        Console.WriteLine($"Enter a Customer ID: {custId}");
                        Console.WriteLine("Customer found:\n");
                        Console.WriteLine(cust.ToString());

                        Console.Write("Enter a Location ID: ");
                        inputStr = Console.ReadLine();
                        isInt    = Int32.TryParse(inputStr, out stoId);
                    }while (!isInt);

                    var loc = StoCon.GetStores(stoId).FirstOrDefault();
                    if (loc == null)
                    {
                        Console.WriteLine($"Store {stoId} does not exist.");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Store found:\n");
                        Console.WriteLine(loc.ToString());
                    }
                    bool abort = false;
                    do
                    {
                        Console.Write("Would you like to continue? (YES/NO): ");
                        string answer = Console.ReadLine();
                        if (answer.ToUpper() == "YES")
                        {
                            break;
                        }
                        else if (answer.ToUpper() == "NO")
                        {
                            abort = true;
                        }
                    }while (!abort);

                    if (!abort)
                    {
                        try
                        {
                            var ord = new lib.Order(cust, loc, 0);
                            OrdCon.Order(ord);
                            OrdCon.EndMe();
                            ord = OrdCon.GetOrdersByCust(cust.CustomerID).Last();


                            int prodId = 0;

                            bool done = false;
                            do
                            {
                                do
                                {
                                    prodId = 0;

                                    Console.Clear();
                                    Console.WriteLine("Place an Order Menu\n");
                                    Console.WriteLine($"Customer:\n{cust.ToString()}");
                                    Console.WriteLine($"Store:\n{loc.ToString()}");
                                    Console.WriteLine();
                                    Console.WriteLine("Store inventory:");
                                    Console.WriteLine(loc.InventoryToString());
                                    Console.WriteLine();
                                    Console.WriteLine("Your basket:");
                                    Console.WriteLine(ord.OrderToString());

                                    Console.Write("Enter a Product Id, or DONE if finished: ");
                                    inputStr = Console.ReadLine();
                                    if (inputStr.ToUpper() == "DONE")
                                    {
                                        done  = true;
                                        isInt = true;
                                    }
                                    else
                                    {
                                        isInt = Int32.TryParse(inputStr, out prodId);
                                    }
                                }while (!isInt);
                                if (!done)
                                {
                                    var prod = MerCon.GetMerch().FirstOrDefault();
                                    if (prod == null)
                                    {
                                        Console.WriteLine($"Merch {prodId} does not exist");
                                        Console.WriteLine("\nPress any key to continue.");
                                        Console.ReadKey();
                                    }

                                    /*else if (!loc.FindItemById(prodId))
                                     * {
                                     *  Console.WriteLine($"Merch {prodId} is not in this location's inventory");
                                     *  Console.WriteLine("\nPress any key to continue.");
                                     *  Console.ReadKey();
                                     * }*/
                                    else
                                    {
                                        bool isIntQuantity = false;
                                        int  quantity      = 0;
                                        do
                                        {
                                            Console.Write("Enter a quanity: ");
                                            inputStr      = Console.ReadLine();
                                            isIntQuantity = Int32.TryParse(inputStr, out quantity);
                                        }while (!isIntQuantity);
                                        if (loc.ChangeStock(prod, -1 * quantity))
                                        {
                                            //ord.details.Add(prod, quantity);
                                            Console.WriteLine($"Added {quantity} {prod.MerchName}s to Order.");
                                            Console.WriteLine("\nPress any key to continue.");
                                            Console.ReadKey();
                                        }
                                    }
                                }
                            }while (!done);
                            OrdCon.AddOrder(ord);
                            OrdCon.EndMe();

                            Console.Clear();
                            Console.WriteLine($"Order Complete.\n");
                            Console.WriteLine(ord.ToString());
                            Console.WriteLine(ord.OrderToString());
                        }
                        catch (ArgumentNullException ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    Console.WriteLine("\nPress any key to continue.");
                    Console.ReadKey();
                }
                else if (input == "4")
                {
                    Console.WriteLine("Alright, See you next time");
                    Console.WriteLine("\n Press any key to leave");
                    Console.ReadKey();
                    break;
                }
            }
        }