예제 #1
0
        /// <summary>
        /// Search Customer By Username
        ///</summary>
        ///<param name="string name"></param>
        public async Task <Logic.Customer> GetCustomerInformationByUserName(string username)
        {
            try
            {
                var entityCustomer = await _context.Customer.FirstAsync(c => c.Username == username);

                var customer = new Logic.Customer
                {
                    firstName       = entityCustomer.FirstName,
                    lastName        = entityCustomer.LastName,
                    customerId      = entityCustomer.CustomerId,
                    userName        = entityCustomer.Username,
                    customerAddress = new Address
                    {
                        street = entityCustomer.Street,
                        city   = entityCustomer.City,
                        state  = entityCustomer.State,
                        zip    = entityCustomer.Zip
                    }
                };
                return(customer);
            }
            catch (InvalidOperationException ex)
            {
                throw new Exception("Failed to retrieve customer information " + ex.Message);
            }
        }
        // GET: Customer/CustomerOrders/5
        public async Task <ActionResult> CustomerOrders()
        {
            try
            {
                string username = null;
                if (TempData["Username"] != null)
                {
                    username = TempData["Username"].ToString();
                }

                Logic.Customer customer = await _repository.GetCustomerInformationByUserName(username);

                List <Logic.Order> orders = await _repository.GetAllOrdersFromCustomer(customer.customerId);

                var viewModel = new CustomerOrdersViewModel
                {
                    Username       = customer.userName,
                    FirstName      = customer.firstName,
                    LastName       = customer.lastName,
                    CustomerOrders = orders
                };
                return(View(viewModel));
            }
            catch (InvalidOperationException)
            {
                Log.Information("Invalid Customer Order");
                return(RedirectToAction(nameof(InvalidCustomer)));
            }
        }
예제 #3
0
        /// <summary>
        /// Search Customer By Name
        ///</summary>
        ///<param name="string name"></param>
        public async Task <List <Logic.Customer> > GetCustomerInformationByName(string name)
        {
            try
            {
                var entityCustomer = await _context.Customer.Where(c => c.LastName == name || c.FirstName == name).ToListAsync();

                List <Logic.Customer> CustomerList = new List <Logic.Customer>();
                for (int i = 0; i < entityCustomer.Count; i++)
                {
                    Logic.Customer customer = new Logic.Customer()
                    {
                        firstName       = entityCustomer[i].FirstName,
                        lastName        = entityCustomer[i].LastName,
                        customerId      = entityCustomer[i].CustomerId,
                        userName        = entityCustomer[i].Username,
                        customerAddress = new Address
                        {
                            street = entityCustomer[i].Street,
                            city   = entityCustomer[i].City,
                            state  = entityCustomer[i].State,
                            zip    = entityCustomer[i].Zip
                        }
                    };
                    CustomerList.Add(customer);
                }
                return(CustomerList);
            }
            catch (InvalidOperationException ex)
            {
                throw new Exception("Failed to retrieve customer information for customer : " + name + "\nException thrown: " + ex.Message);
            }
        }
        public async Task RepoUpdateCustomerTest()
        {
            DbContextOptions <SWTDbContext> options = new DbContextOptionsBuilder <SWTDbContext>()
                                                      .UseInMemoryDatabase("UpdateCustomer")
                                                      .Options;

            using SWTDbContext testContext = new SWTDbContext(options);
            Repo repo = new Repo(testContext);

            Logic.Customer newCustomer = new Logic.Customer
            {
                CustomerID = 1,
                FirstName  = "Wesley",
                LastName   = "Tang",
                Email      = "321@123",
                Password   = "******"
            };

            string create = await repo.CreateCustomer(customer);

            string update = await repo.UpdateCustomer(newCustomer);

            string firstName = testContext.Customer.Select(c => c.FirstName).First();
            string lastName  = testContext.Customer.Select(c => c.LastName).First();
            string email     = testContext.Customer.Select(c => c.Email).First();
            string password  = testContext.Customer.Select(c => c.Password).First();

            Assert.Equal(newCustomer.FirstName, firstName);
            Assert.Equal(newCustomer.LastName, lastName);
            Assert.Equal(newCustomer.Email, email);
            Assert.Equal(newCustomer.Password, password);
        }
        public async Task <ActionResult> Create(Models.Customer viewModel)
        {
            try
            {
                //Add a new customer
                var customer = new Logic.Customer
                {
                    userName        = viewModel.Username,
                    firstName       = viewModel.FirstName,
                    lastName        = viewModel.LastName,
                    customerAddress = new Address
                    {
                        city   = viewModel.customerAddress.city,
                        street = viewModel.customerAddress.street,
                        state  = viewModel.customerAddress.state,
                        zip    = viewModel.customerAddress.zip
                    }
                };


                await _repository.AddNewCustomerAsync(customer);

                return(RedirectToAction(nameof(Login)));
            }
            catch (InvalidOperationException ex)
            {
                Log.Warning("Username is Existing");
                ModelState.AddModelError("Username", ex.Message);
                var cust = await _repository.GetAllCustomers();

                return(View(viewModel));
            }
        }
 //Map Business --> Entity
 public static Customer MapCustomerToE(Logic.Customer BCustomer)
 {
     return(new Customer
     {
         CustomerID = BCustomer.CustomerID,
         FirstName = BCustomer.FirstName,
         LastName = BCustomer.LastName,
         Email = BCustomer.Email,
         Password = BCustomer.Password
     });
 }
 public void IsCustomerInfoCorrect(string username, string firstName, string lastName, string city, string state, string street, string zip)
 {
     Logic.Customer customer = new Logic.Customer();
     customer.customerAddress.city   = city;
     customer.customerAddress.state  = state;
     customer.customerAddress.street = street;
     customer.customerAddress.zip    = zip;
     customer.userName  = username;
     customer.firstName = firstName;
     customer.lastName  = lastName;
     Assert.True(customer.IsCustomerNotNull());
 }
        public void AddNewCustomer(Logic.Customer LogicCustomer, StoreAppContext context)
        {
            //Some code to input customer data to the DB

            try
            {
                //SaveChanges is needed to persist the data
                context.Customer.Add(parser.LogicCustomerToContextCustomer(LogicCustomer));
                context.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to put the customer into the database: " + e.Message);
            }
        }
예제 #9
0
        public void CustomerTest()
        {
            Logic.Customer customer1 = new Logic.Customer
            {
                CustomerID = 1,
                FirstName  = "aaa",
                LastName   = "bbb",
                Email      = "123@123",
                Password   = "******"
            };
            Logic.Customer customer2 = new Logic.Customer(1, "aaa", "bbb", "123@123", "1234");

            Assert.Equal(customer1.CustomerID, customer2.CustomerID);
            Assert.Equal(customer1.FirstName, customer2.FirstName);
            Assert.Equal(customer1.LastName, customer2.LastName);
            Assert.Equal(customer1.Email, customer2.Email);
            Assert.Equal(customer1.Password, customer2.Password);
        }
예제 #10
0
        public Entities.Customer LogicCustomerToContextCustomer(Logic.Customer cust)
        {
            Entities.Customer ContextCustomer = new Entities.Customer();

            ContextCustomer.Username   = cust.userName;
            ContextCustomer.CustomerId = cust.customerId;
            ContextCustomer.FirstName  = cust.firstName;
            ContextCustomer.LastName   = cust.lastName;

            ContextCustomer.Street = cust.customerAddress.street;
            ContextCustomer.City   = cust.customerAddress.city;
            ContextCustomer.State  = cust.customerAddress.state;
            ContextCustomer.Zip    = cust.customerAddress.zip;



            return(ContextCustomer);
        }
        public async Task RepoReadCustomerTestAsync()
        {
            DbContextOptions <SWTDbContext> options = new DbContextOptionsBuilder <SWTDbContext>()
                                                      .UseInMemoryDatabase("ReadCustomer")
                                                      .Options;

            using SWTDbContext testContext = new SWTDbContext(options);
            Repo   repo   = new Repo(testContext);
            string create = await repo.CreateCustomer(customer);

            List <Logic.Customer> customerFind = await repo.ReadCustomerList(customer);

            Logic.Customer first = customerFind.First();

            Assert.Equal(customer.FirstName, first.FirstName);
            Assert.Equal(customer.LastName, first.LastName);
            Assert.Equal(customer.Email, first.Email);
            Assert.Equal(customer.Password, first.Password);
        }
예제 #12
0
        public Logic.Customer GetCustomerDataFromUsername(string username, StoreAppContext context)
        {
            //return information of customer data matched with input userpane

            try
            {
                foreach (StoreApp.Library.Entities.Customer cust in context.Customer)
                {
                    if (cust.Username == username)
                    {
                        Logic.Customer matched = parser.ContextCustomerToLogicCustomer(cust);
                        return(matched);
                    }
                }
                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Operation failed: " + e.Message);
                return(null);
            }
        }
예제 #13
0
        /// <summary>
        /// Add New Customers
        ///</summary>
        ///<param name="Logic.Customer customer"></param>

        public async Task AddNewCustomerAsync(Logic.Customer cust)
        {
            var entityCustomer = new Entities.Customer
            {
                FirstName = cust.firstName,
                LastName  = cust.lastName,
                Username  = cust.userName,
                Street    = cust.customerAddress.street,
                State     = cust.customerAddress.state,
                City      = cust.customerAddress.city,
                Zip       = cust.customerAddress.zip
            };

            //if username is existing
            if (await _context.Customer.AnyAsync(c => c.Username == cust.userName))
            {
                throw new InvalidOperationException("Use Name Already Exists. Please Choose Another");
            }

            _context.Add(entityCustomer);
            await _context.SaveChangesAsync();
        }
예제 #14
0
        public static void ManagerMenu(StoreAppContext context, int manager)
        {
            Logic.Customer newCust      = new Logic.Customer();
            GetDataHandler getDBHandler = new GetDataHandler();
            InputDBHandler Inputhandler = new InputDBHandler();

            Logic.Customer getCustomer = new Logic.Customer();
            Logic.Store    getStore    = new Logic.Store();
            Logic.Order    order       = new Logic.Order();
            Logic.Product  items       = new Logic.Product();
            List <Order>   orderList   = new List <Order>();

            bool managerMenu = true;
            bool nextMenu    = false;

            while (managerMenu)
            {
                switch (manager)
                {
                /// <summary>
                /// View Orders History of A Store
                /// </summary>

                case 1:
                    Console.WriteLine("Please Choose A Store:");
                    Console.WriteLine("1. Arlington,TX\n5. Houston,TX\n3. Exit");
                    int storeId = Int32.Parse(Console.ReadLine());

                    if (storeId == 3)
                    {
                        Console.WriteLine("Manager's Options:");
                        Console.WriteLine("1. View Order History Of A Store\n2. Add New Items To Stores\n3. Switch To Customer Menu \n4. Stop");
                        manager = Int32.Parse(Console.ReadLine());
                    }

                    nextMenu = true;
                    while (nextMenu)
                    {
                        try
                        {
                            getStore = getDBHandler.GetStoreFromStoreId(storeId, context);
                            Console.WriteLine("Store Address {0}, {1}, {2}, {3}", getStore.address.street, getStore.address.city, getStore.address.state, getStore.address.zip);
                            Console.WriteLine("Ariel: {0}, Downie: {1}, Suavitel: {2}", getStore.storeInventory.items.NumberofAriel, getStore.storeInventory.items.NumberofDownie, getStore.storeInventory.items.NumberofSuavitel);
                            var enityOrder = context.Orders.Where(order => order.StoreId == storeId).ToList();
                            foreach (var row in enityOrder)
                            {
                                var cust = getDBHandler.GetCustomerDataFromID(row.CustomerId, context);

                                Console.WriteLine("------------------------------------------------------------");
                                Console.WriteLine("Order Id: {0} \nCustomer Id: {1}", row.OrderId, row.CustomerId);
                                Console.WriteLine("Customer Name: " + cust.firstName + " " + cust.lastName);
                                Console.WriteLine("Ariel: {0}, \nDownie: {1} \nSuavitel: {2}", row.Ariel, row.Downie, row.Suavitel);
                                Console.WriteLine();
                            }

                            nextMenu = false;
                            Console.WriteLine("Manager's Options:");
                            Console.WriteLine("1. View Order History Of A Store\n2. Add New Items To Stores\n3. Search User Information By Name \n4. Exit Main Menu \n5.Stop");
                            manager = Int32.Parse(Console.ReadLine());
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error finding store with input store");
                            //error handling
                            Log.Warning("Invalid Store ID");
                            break;
                        }
                    }
                    break;

                /// <summary>
                /// Add new Items
                /// </summary>

                case 2:
                    Console.WriteLine("Please Choose A Store:");
                    Console.WriteLine("1. Arlington,TX\n5. Houston,TX\n3. Exit");
                    storeId = Int32.Parse(Console.ReadLine());
                    if (storeId == 3)
                    {
                        Console.WriteLine("Manager's Options:");
                        Console.WriteLine("1. View Order History Of A Store\n2. Add New Items To Stores\n3. Search User Information By Name \n4. Switch To Customer \n5.Stop");
                        manager = Int32.Parse(Console.ReadLine());
                    }

                    try
                    {
                        getStore = getDBHandler.GetStoreFromStoreId(storeId, context);
                        Console.WriteLine("Store Address {0}, {1}, {2}, {3}", getStore.address.street, getStore.address.city, getStore.address.state, getStore.address.zip);
                        Console.WriteLine("Inventory:\nAriel: {0}, Downie: {1}, Suavitel: {2}", getStore.storeInventory.items.NumberofAriel, getStore.storeInventory.items.NumberofDownie, getStore.storeInventory.items.NumberofSuavitel);

                        bool decided = false;
                        int  ariel;
                        int  downie;
                        int  suavitel;

                        while (!decided)
                        {
                            try
                            {
                                Console.WriteLine("Ariel:");
                                string input = Console.ReadLine();
                                ariel = Int32.Parse(input);
                                Console.WriteLine("Downie:");
                                input  = Console.ReadLine();
                                downie = Int32.Parse(input);
                                Console.WriteLine("Suavitels");
                                input    = Console.ReadLine();
                                suavitel = Int32.Parse(input);


                                Console.WriteLine("You added number of Ariel: {0} || Downie: {1} || Suavitel: {2}",
                                                  ariel, downie, suavitel);
                                Console.WriteLine("Ready To Add New Item? \n1.Yes 2.No");
                                string userInput = UserChoiceHandler.UserOptionHandler(Int32.Parse(Console.ReadLine()), 2);

                                if (userInput == "1")
                                {
                                    decided = true;
                                    Console.WriteLine(". . .\n");


                                    {
                                        order = new Logic.Order();
                                        //uses input handler to input order into DB
                                        var entityStore = context.Store.FirstOrDefault(i => i.StoreId == storeId);



                                        entityStore.Ariel    += ariel;
                                        entityStore.Downie   += downie;
                                        entityStore.Suavitel += suavitel;


                                        context.Store.Update(entityStore);
                                        context.SaveChanges();
                                        try
                                        {
                                            nextMenu = false;
                                            Console.WriteLine("Added New Items Successfully!!!");
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine("Unable to perform the operation: \n" + e);
                                            //error handling
                                            Log.Error("Unknown Error");
                                        }
                                    }
                                }
                                else if (userInput == "2")
                                {
                                    Console.WriteLine("Please Enter The Amount of Items Again!!!");
                                }
                                else
                                {
                                    Console.WriteLine("Invalid input, please type one of the following options.");
                                    //error handling
                                    Log.Debug("Invalid Input");
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Error! Please Try It Again");
                            }
                        }
                        nextMenu = true;
                        break;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error finding store with input ID" + e.Message);
                        break;
                    }

                /// <summary>
                /// Search Customer By Name
                /// </summary>
                case 3:
                    Console.WriteLine("Enter First Name or Last Name To Search Information: ");
                    string name = Console.ReadLine();

                    nextMenu = true;
                    while (nextMenu)
                    {
                        try
                        {
                            getCustomer = getDBHandler.GetCustomerDataByName(name, context);

                            var entityCustomer = context.Customer.FirstOrDefault(cust => cust.LastName == name || cust.FirstName == name);
                            if (getCustomer != null)
                            {
                                Console.WriteLine("------------------------------------------------------------");
                                Console.WriteLine("Customer Id: {0} \nCustomer username: {1}", getCustomer.customerId, getCustomer.userName);
                                Console.WriteLine("Name: {0} {1}", getCustomer.firstName, getCustomer.lastName);
                                Console.WriteLine("Address");
                                Console.WriteLine("{0}, {1}, {2}, {3}", getCustomer.customerAddress.street, getCustomer.customerAddress.city, getCustomer.customerAddress.state.ToUpper(), getCustomer.customerAddress.zip);
                                Console.WriteLine();
                            }
                            if (getCustomer is null)
                            {
                                Console.WriteLine("No Customer Information");
                            }

                            nextMenu = false;
                            Console.WriteLine("Manager's Options:");
                            Console.WriteLine("1. View Order History Of A Store\n2. Add New Items To Stores\n3. Search User Information By Name \n4. Switch To Customer Menu \n5.Stop");
                            manager = Int32.Parse(Console.ReadLine());
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error! Invalid Input. Please enter name of customer only" + e.Message);
                            break;
                        }
                    }
                    break;

                case 4:
                    Console.Clear();
                    //Move To Customer's Menu
                    Console.WriteLine("1. Sign Up  \n2. Login \n3. Stop");
                    string userChoice     = Console.ReadLine();
                    string customerChoice = UserChoiceHandler.UserOptionHandler(Int32.Parse(userChoice), 4);

                    if (userChoice == "3")
                    {
                        Console.Clear();
                        Console.WriteLine("See You Later");
                        Environment.Exit(0);
                    }
                    else if (userChoice == "1" || userChoice == "2")
                    {
                        Menu.CustomerMenu(context, Int32.Parse(userChoice));
                    }
                    else     //Invalid input
                    {
                        Console.WriteLine("Invalid input, please type one of the following options");
                        //error handling
                        Log.Error("Invalid Input");
                    }
                    break;

                case 5:
                    Console.WriteLine("Bye");
                    Environment.Exit(0);
                    break;

                default:
                    //error handling
                    Log.Error("Invalid Input");
                    break;
                }
            }
        }
        public void TestBusinessCustomerLastNameNotEmpty()
        {
            Logic.Customer customer = new Logic.Customer();

            Assert.Throws <CustomerException>(() => customer.lastName = "");
        }
예제 #16
0
        public static void CustomerMenu(StoreAppContext context, int cust)
        {
            Logic.Customer newCust      = new Logic.Customer();
            GetDataHandler getDBHandler = new GetDataHandler();
            InputDBHandler Inputhandler = new InputDBHandler();

            Logic.Customer getCustomer = new Logic.Customer();
            Logic.Store    getStore    = new Logic.Store();
            Logic.Order    order       = new Logic.Order();
            Logic.Product  items       = new Logic.Product();
            List <Order>   orderList   = new List <Order>();
            string         username    = null;


            string userInput;
            bool   customerMenu = true;
            bool   nextMenu     = false;

            switch (cust)
            {
            /// <summary>
            /// Sign Up New Account
            /// </summary>

            case 1:
                while (customerMenu)
                {
                    if (newCust.IsCustomerNotNull() == false)
                    {
                        if (newCust.userName == null)
                        {
                            Console.WriteLine("What is your username");
                            newCust.userName = Console.ReadLine();

                            /// <summary>
                            /// Check Username To Make Sure It's not Existing
                            /// </summary>

                            var check = getDBHandler.GetCustomerDataFromUsername(newCust.userName, context);
                            if (check != null)
                            {
                                Console.WriteLine("Username Existing. Choose another one");
                                newCust.userName = Console.ReadLine();
                            }
                        }
                        else if (newCust.firstName == null)
                        {
                            Console.WriteLine("What is your first name?");
                            newCust.firstName = Console.ReadLine();
                        }
                        else if (newCust.lastName == null)
                        {
                            Console.WriteLine("What is your last name?");
                            newCust.lastName = Console.ReadLine();
                        }
                        else if (newCust.customerAddress.IsAddressNotNull() == false)
                        {
                            Console.WriteLine("What is your address?");
                            newCust.customerAddress.street = Console.ReadLine();

                            Console.WriteLine("Please enter a city");
                            newCust.customerAddress.city = Console.ReadLine();

                            Console.WriteLine("Please enter a state");
                            newCust.customerAddress.state = Console.ReadLine();

                            Console.WriteLine("Please enter a zip");
                            newCust.customerAddress.zip = Console.ReadLine();
                        }
                    }
                    else
                    {
                        /// <summary>
                        /// Insert New Account Into DB
                        /// </summary>

                        try
                        {
                            Console.WriteLine("1.Yes 2.No");
                            userInput = UserChoiceHandler.UserOptionHandler(Int32.Parse(Console.ReadLine()), 2);
                            Console.WriteLine("Added New Customer Successfully! Welcome, " + newCust.firstName + " " + newCust.lastName);
                            Inputhandler.AddNewCustomer(newCust, context);
                            Console.WriteLine("Please Login With Your Username To Continue");
                            CustomerMenu(context, 2);
                            break;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Unknown exception thrown: " + e);
                        }
                    }
                }
                nextMenu = true;     //resets menu true to go into next menu
                cust     = 2;
                break;

            /// <summary>
            /// Logging Int User Account
            /// </summary>
            case 2:
                while (customerMenu)
                {
                    Console.WriteLine("What is your username?");
                    username = Console.ReadLine();

                    if (getDBHandler.UsernameParser(username, context) == false)
                    {
                        Console.WriteLine("Your UserName is Incorrect. Please Try It Again");
                        break;
                    }
                    else
                    {
                        try
                        {
                            /// <summary>
                            /// Get Customer Information From Logic.Customer
                            /// </summary>
                            getCustomer = getDBHandler.GetCustomerDataFromUsername(username, context);
                            Console.WriteLine("Welcome " + getCustomer.firstName + " " + getCustomer.lastName);
                            nextMenu = true;
                        }
                        catch (NullReferenceException e)
                        {
                            Console.WriteLine("NULL Error " + username + ": " + e.Message + "\n");
                            Log.Error("Null Value");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Unknown exeption " + e);
                            Log.Error("Unknown Error");
                        }
                    }
                    customerMenu = false;     //resets menu true to go into next menu
                }
                break;
            }


            while (nextMenu)
            {
                Console.WriteLine("1. Place order\n2. View your order history\n3. Stop");
                userInput = UserChoiceHandler.UserOptionHandler(Int32.Parse(Console.ReadLine()), 3);
                switch (userInput)
                {
                /// <summary>
                /// Place An Order
                /// </summary>
                case "1":
                    Console.WriteLine("What is your favorite store?\n1.Arlington \n5.Houston");
                    string store = Console.ReadLine();
                    if (getDBHandler.CheckIDParsable(Int32.Parse(store)) == false)
                    {
                        Console.WriteLine("Please Choice Either 1 or 2");
                        break;
                    }
                    else     //if the input only has numbers in it
                    {
                        int storeId = Int32.Parse(store);
                        /// <summary>
                        /// Display Store Information Retrieved From DB
                        /// </summary>
                        try
                        {
                            getStore = getDBHandler.GetStoreFromStoreId(storeId, context);
                            Console.WriteLine("Store Address {0}, {1}, {2}, {3}", getStore.address.street, getStore.address.city, getStore.address.state, getStore.address.zip);
                            Console.WriteLine("Ariel: {0}, Downie: {1}, Suavitel: {2}", getStore.storeInventory.items.NumberofAriel, getStore.storeInventory.items.NumberofDownie, getStore.storeInventory.items.NumberofSuavitel);

                            bool decided = false;
                            int  ariel;
                            int  downie;
                            int  suavitel;

                            while (!decided)
                            {
                                try
                                {
                                    Console.WriteLine("Ariel:");
                                    string input = Console.ReadLine();
                                    ariel = Int32.Parse(input);
                                    Console.WriteLine("Downie:");
                                    input  = Console.ReadLine();
                                    downie = Int32.Parse(input);
                                    Console.WriteLine("Suavitels");
                                    input    = Console.ReadLine();
                                    suavitel = Int32.Parse(input);


                                    Console.WriteLine("You have an order of Ariel: {0} || Downie: {1} || Suavitel: {2}",
                                                      ariel, downie, suavitel);
                                    Console.WriteLine("1.Yes 2.No");
                                    userInput = UserChoiceHandler.UserOptionHandler(Int32.Parse(Console.ReadLine()), 2);

                                    if (userInput == "1")
                                    {
                                        decided = true;
                                        Console.WriteLine(". . .\n");

                                        if (ariel > getStore.storeInventory.items.NumberofAriel || downie > getStore.storeInventory.items.NumberofDownie || suavitel > getStore.storeInventory.items.NumberofSuavitel)
                                        {
                                            Console.WriteLine("Not Enough--Available: ");
                                            Console.WriteLine("Ariel: {0} || Downie: {1} || Suavitel: {2}",
                                                              getStore.storeInventory.items.NumberofAriel.ToString(),
                                                              getStore.storeInventory.items.NumberofDownie.ToString(),
                                                              getStore.storeInventory.items.NumberofSuavitel.ToString());
                                            decided = false;
                                        }
                                        else
                                        {
                                            order = new Logic.Order();
                                            //uses input handler to input order into DB
                                            var entityStore = context.Store.FirstOrDefault(i => i.StoreId == Int32.Parse(store));
                                            if (entityStore != null)
                                            {
                                                order.customer = getCustomer;
                                                order.cartItems.NumberofAriel    = ariel;
                                                order.cartItems.NumberofDownie   = downie;
                                                order.cartItems.NumberofSuavitel = suavitel;
                                                order.ordererAddress             = getCustomer.customerAddress;
                                                order.PlaceOrderTime();
                                                /// <summary>
                                                /// Update Products' Quantities
                                                /// </summary>
                                                entityStore.Ariel    -= ariel;
                                                entityStore.Downie   -= downie;
                                                entityStore.Suavitel -= suavitel;

                                                order.storeLocation.address        = getStore.address;
                                                order.storeLocation.storeInventory = getStore.storeInventory;
                                                order.storeLocation.storeId        = getStore.storeId;
                                            }
                                            context.Store.Update(entityStore);
                                            context.SaveChanges();
                                            try
                                            {
                                                /// <summary>
                                                /// Placed Order Successfully
                                                /// </summary>
                                                Inputhandler.PlaceOrder(order, context);
                                                nextMenu = false;
                                                Console.WriteLine("Order successfully created! Thank you for your business!\nReturning back to customer menue");
                                            }
                                            catch (Exception e)
                                            {
                                                Console.WriteLine("Unable to perform the operation: \n" + e);
                                                Log.Error("Exception Error");
                                            }
                                        }
                                    }
                                    else if (userInput == "2")
                                    {
                                        Console.WriteLine("Please make a new order again");
                                    }
                                    else
                                    {
                                        Console.WriteLine("Invalid input, please type one of the following options.");
                                        Log.Error("Null Value");
                                    }
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine("Please Enter NUMBER ONLY.");
                                    Log.Error("Non Numerical Error");
                                }
                            }
                            nextMenu = true;
                            break;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error finding store with input ID: \n");
                        }
                    }
                    break;

                /// <summary>
                /// Display Order History of The customer
                /// </summary>
                case "2":

                    var    enityOrder = context.Orders.Where(user => user.CustomerId == getCustomer.customerId).ToList();
                    string storeInfo;
                    foreach (var row in enityOrder)
                    {
                        if (row.StoreId == 1)
                        {
                            storeInfo = "Arlington,TX";
                        }
                        else
                        {
                            storeInfo = "Houston, TX";
                        }
                        Console.WriteLine("Your Order Id: {0} Store Location:  {1}", row.OrderId, storeInfo);
                        Console.WriteLine("Ariel: {0}, \nDownie: {1} \nSuavitel: {2}", row.Ariel, row.Downie, row.Suavitel);
                        Console.WriteLine();
                    }
                    break;

                case "3":
                    Console.Clear();
                    Console.WriteLine("See You Later");
                    Environment.Exit(0);
                    break;

                default:
                    //error handling
                    Log.Error("Invalid Input");
                    break;
                }
            }
        }
        public async Task <ActionResult> MakeAnOrder(Models.CustomerMakeAnOrder order)
        {
            try
            {
                int    StoreId  = order.StoreId;
                string username = null;
                if (TempData["Username"] != null)
                {
                    username = TempData["Username"].ToString();
                }

                if (StoreId != 1 && StoreId != 5)
                {
                    TempData.Keep("Username");
                    throw new NullReferenceException();
                }
                Logic.Customer cust = await _repository.GetCustomerInformationByUserName(username);

                Logic.Store store = await _repository.GetStoreInformation(StoreId);

                Logic.Order ord = new Logic.Order()
                {
                    customer = new Logic.Customer
                    {
                        customerId = cust.customerId
                    },
                    storeLocation = new Logic.Store
                    {
                        storeId = store.storeId
                    },
                    cartItems = new Product
                    {
                        NumberofAriel    = order.NumberofAriel,
                        NumberofDownie   = order.NumberofDownie,
                        NumberofSuavitel = order.NumberofSuavitel,
                    }
                };

                await _repository.MakeAnOrder(StoreId, ord);

                return(RedirectToAction(nameof(Thankyou)));
            }
            catch (InvalidOperationException ex)
            {
                TempData.Keep("Username");
                ModelState.AddModelError("", ex.Message);
                return(View());
            }
            catch (NullReferenceException)
            {
                Log.Error("Store Id is Invalid");
                ModelState.AddModelError("StoreId", "Invalid Location");
                return(View(nameof(MakeAnOrder)));
            }
            catch (Exception ex)
            {
                TempData.Keep("Username");
                ModelState.AddModelError("", ex.Message);
                return(View());
            }
        }
예제 #18
0
 public void UpdateCustomer(Logic.Customer customer)
 {
     throw new NotImplementedException();
 }
예제 #19
0
        static void Main(string[] args)
        {
            /// <summary>
            /// Entity Framework Logger
            /// Used To store any runtime error of the app
            /// </summary>
            Log.Logger = new LoggerConfiguration().WriteTo.File(@"C:\revature\phat-project0\Project0-Log\Log.txt").CreateLogger();
            Log.Information("Begin Program");

            bool menu = true; //flag = true;

            StoreApp.Logic.Customer getCustomer = new Logic.Customer();
            StoreApp.Logic.Store    getStore    = new Logic.Store();
            StoreApp.Logic.Order    inputOrder  = new Logic.Order();

            using var context = new StoreAppContext();

            Console.WriteLine("Hello Welcome To The ABC's Grocery Store");
            string userInput;
            string userChoice;

            Console.WriteLine("Are you:\n1. Manager\n2. Customer");
            userInput = Console.ReadLine();

            /// <summary>
            /// Try catch handle
            /// Used to catch non number error inputs
            /// </summary>
            try
            {
                userChoice = UserChoiceHandler.UserOptionHandler(Int32.Parse(userInput), 2);
            }
            catch (FormatException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Are you:\n1. Manager\n2. Customer");
                userChoice = Console.ReadLine();
            }
            if (userChoice == null)
            {
                Console.WriteLine("Are you:\n1. Manager\n2. Customer");
                userChoice = Console.ReadLine();
            }


            while (menu == true)
            {
                if (userChoice == "1") //Manager
                {
                    string managerID;
                    Console.WriteLine("Enter Your Password (Number Only): ");
                    managerID = Console.ReadLine();
                    StoreApp.Logic.Manager getManagerInfo = new Logic.Manager();
                    try
                    {
                        getManagerInfo = getDB.GetManagerDataFromId(Int32.Parse(managerID), context);
                    }
                    catch (FormatException e)
                    {
                        Console.WriteLine(e.Message + " Number ONLY");
                        menu = false;
                    }

                    if (getManagerInfo is null)
                    {
                        Console.WriteLine("Incorrect Password. Please Try It Again\n");
                        userChoice = "1";
                    }

                    else
                    {
                        if (getDB.CheckIDParsable(getManagerInfo.managerID))
                        {
                            try
                            {
                                Console.WriteLine("Welcome back, " + getManagerInfo.firstName + " " + getManagerInfo.lastName);
                                Console.WriteLine("Manager's Options:");
                                Console.WriteLine("1. View Order History Of A Store\n2. Add New Items To Stores\n3. Search User Information By Name \n4. Switch To Customer Menu\n5.Stop");
                                int    manOpt        = Int32.Parse(Console.ReadLine());
                                string managerChoice = UserChoiceHandler.UserOptionHandler(manOpt, 5);
                                if (managerChoice == null)
                                {
                                    Console.WriteLine("1. View Order History Of A Store\n2. Add New Items To Stores\n3. Search User Information By Name \n4. Switch To Customer Menu \n5.Stop");
                                    manOpt        = Int32.Parse(Console.ReadLine());
                                    managerChoice = UserChoiceHandler.UserOptionHandler(manOpt, 5);
                                }
                                if (manOpt == 1 || manOpt == 2 || manOpt == 3)
                                {
                                    Menu.ManagerMenu(context, manOpt);
                                }
                                else if (manOpt == 4)
                                {
                                    Console.WriteLine("Are you:\n1. Manager\n2. Customer");
                                    userInput  = Console.ReadLine();
                                    userChoice = UserChoiceHandler.UserOptionHandler(Int32.Parse(userInput), 2);
                                }
                                else if (manOpt == 5)
                                {
                                    Console.Clear();
                                    Console.WriteLine("See You Later. Please Press Any Key To Stop");
                                    menu = false;
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("There Is An Error. Please Try It Again " + e.Message);
                            }
                        }
                    }
                }
                else if (userChoice == "2") //Customer
                {
                    //Will run code to make new customer, list of customer info, and place orders
                    Console.WriteLine("1. Sign Up  \n2. Login \n3. Exit to start menu \n4. Stop");
                    userChoice = Console.ReadLine();
                    try
                    {
                        userInput = UserChoiceHandler.UserOptionHandler(Int32.Parse(userChoice), 4);
                    }
                    catch (FormatException e)
                    {
                        Console.WriteLine(e.Message);
                        Console.WriteLine("1. Sign Up  \n2. Login \n3. Exit to start menu \n4. Stop");
                        userChoice = Console.ReadLine();
                    }
                    if (userInput == null)
                    {
                        Console.WriteLine("1. Sign Up  \n2. Login \n3. Exit to start menu \n4. Stop");
                        userChoice = Console.ReadLine();
                    }


                    if (userChoice == "3")
                    {
                        Console.WriteLine("Are you:\n1. Manager\n2. Customer");
                        userInput  = Console.ReadLine();
                        userChoice = UserChoiceHandler.UserOptionHandler(Int32.Parse(userInput), 2);
                    }
                    else if (userChoice == "4")
                    {
                        Console.Clear();
                        Console.WriteLine("See You Later. Please Press Any Key To Stop");
                        menu = false;
                    }
                    else if (userChoice == "1" || userChoice == "2")
                    {
                        Menu.CustomerMenu(context, Int32.Parse(userChoice));
                    }
                }
            }
        }