public void GetProductTypeTest(string productName)
        {
            ProductType result = ProductTypeOperations.GetProductType(productName);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Type, productName);
        }
示例#2
0
        private static void DisplayProductTypes(bool displayAllProducts)
        {
            List <ProductType> productTypes = ProductTypeOperations.GetAllProductTypes();

            const int prodNameWidth  = -12;
            const int prodCostWidth  = -15;
            const int prodLaborWidth = -10;

            //Console.ForegroundColor = EmphasisColor;
            Console.WriteLine("\t\t    CURRENT PRODUCTS");
            Console.WriteLine();
            Console.ResetColor();
            Console.Write("\t{0," + prodNameWidth + "}", "Name");
            Console.WriteLine("{0," + prodCostWidth + "}{1," + prodLaborWidth + "}", "Cost/Sq Ft", "Labor Cost/Sq Ft");

            if (displayAllProducts)
            {
                for (int i = 0; i < productTypes.Count; i++)
                {
                    Console.ForegroundColor = EmphasisColor;
                    Console.Write("\t{0," + prodNameWidth + "}", productTypes[i].Type);
                    Console.ResetColor();
                    Console.WriteLine("  {0," + prodCostWidth + ":C}     {1," + prodLaborWidth + ":C}", productTypes[i].CostPerSquareFoot, productTypes[i].LaborCostPerSquareFoot);
                }
            }
            else //They should only see the first 10, with the option to see the rest
            {
                for (int i = 0; i <= 10 && i < productTypes.Count; i++)
                {
                    Console.ForegroundColor = EmphasisColor;
                    Console.Write("\t{0," + prodNameWidth + "}", productTypes[i].Type);
                    Console.ResetColor();
                    Console.WriteLine("  {0," + (prodCostWidth + 2) + ":C}     {1," + prodLaborWidth + ":C}", productTypes[i].CostPerSquareFoot, productTypes[i].LaborCostPerSquareFoot);
                }

                //now we've displayed up to 10 products. If there are more. . .
                if (productTypes.Count > 10)
                {
                    Console.WriteLine("\tContinued... (Press enter to display all current product types)");
                }
            }
            Console.WriteLine();
        }
        public void GetAllProductTypesTest()
        {
            var result = ProductTypeOperations.GetAllProductTypes();

            Assert.AreEqual(result.Count(), 2);
        }
        public void IsProductTypeTest(string productType)
        {
            var result = ProductTypeOperations.IsProductType(productType);

            Assert.IsTrue(result);
        }
示例#5
0
 public ProductTypesController(WarehouseContext context)
 {
     _context  = context;
     _service  = new ProductTypeOperations();
     _pageSize = 8;
 }
示例#6
0
        private static Order EditOrder(Order orderToEdit)
        {
            bool doneEditing  = false;
            bool hadError     = false;
            int  fieldChanged = 0;

            while (!doneEditing)
            {
                //display order info with edit options, coloring items that have been changed
                OffsetTop();
                int fieldNameFormatter = -18;
                int fieldValueLength   = 0;
                Console.ForegroundColor = EmphasisColor;
                Console.WriteLine("\tEdit Order");
                Console.WriteLine("\t-----------------------------------");
                Console.ResetColor();
                Console.WriteLine("\t" + "   {0," + fieldNameFormatter + "}{1," + fieldValueLength + "}", "Order Date:", orderToEdit.Date.ToString("d"));
                Console.WriteLine("\t" + "   {0," + fieldNameFormatter + "}{1," + fieldValueLength + "}", "Order #:", orderToEdit.Number);
                Console.ForegroundColor = EmphasisColor;
                Console.Write("\t1. ");
                Console.ResetColor();
                if (fieldChanged == 1)
                {
                    Console.ForegroundColor = SuccessColor;
                }
                Console.WriteLine("{0," + fieldNameFormatter + "}{1," + fieldValueLength + "}", "Customer Name:", orderToEdit.CustomerName);
                Console.ForegroundColor = EmphasisColor;
                Console.Write("\t2. ");
                Console.ResetColor();
                if (fieldChanged == 2)
                {
                    Console.ForegroundColor = SuccessColor;
                }
                Console.WriteLine("{0," + fieldNameFormatter + "}{1," + fieldValueLength + "}", "State:", orderToEdit.State);
                Console.WriteLine("\t" + "   {0," + fieldNameFormatter + "}{1," + fieldValueLength + ":P}", "Tax Percent:", orderToEdit.TaxPercent * 0.01M);
                Console.ForegroundColor = EmphasisColor;
                Console.Write("\t3. ");
                Console.ResetColor();
                if (fieldChanged == 3)
                {
                    Console.ForegroundColor = SuccessColor;
                }
                Console.WriteLine("{0," + fieldNameFormatter + "}{1," + fieldValueLength + "}", "Product Type:", orderToEdit.ProductType);
                Console.ForegroundColor = EmphasisColor;
                Console.Write("\t4. ");
                Console.ResetColor();
                if (fieldChanged == 4)
                {
                    Console.ForegroundColor = SuccessColor;
                }
                Console.WriteLine("{0," + fieldNameFormatter + "}{1," + fieldValueLength + ":n0}" + " sq feet", "Area:", orderToEdit.Area);
                Console.ResetColor();
                if (fieldChanged == 3)
                {
                    Console.ForegroundColor = SuccessColor;
                }
                Console.WriteLine("\t" + "   {0," + fieldNameFormatter + "}{1," + fieldValueLength + ":C}", "Cost per sq ft:", orderToEdit.CostPerSquareFoot);
                Console.WriteLine("\t" + "   {0," + fieldNameFormatter + "}{1," + fieldValueLength + ":C}", "Labor cost/sq ft:", orderToEdit.LaborCostPerSquareFoot);
                if (fieldChanged == 4)
                {
                    Console.ForegroundColor = SuccessColor;
                }
                Console.WriteLine("\t" + "   {0," + fieldNameFormatter + "}{1," + fieldValueLength + ":C}", "Material Cost:", orderToEdit.MaterialCost);
                Console.WriteLine("\t" + "   {0," + fieldNameFormatter + "}{1," + fieldValueLength + ":C}", "Labor Cost:", orderToEdit.LaborCost);
                if (fieldChanged == 2)
                {
                    Console.ForegroundColor = SuccessColor;
                }
                Console.WriteLine("\t" + "   {0," + fieldNameFormatter + "}{1," + fieldValueLength + ":C}", "Tax:", orderToEdit.Tax);
                Console.WriteLine("\t" + "   {0," + fieldNameFormatter + "}{1," + fieldValueLength + ":C}", "Total:", orderToEdit.Total);
                Console.ResetColor();
                Console.ForegroundColor = EmphasisColor;
                Console.WriteLine("\t-----------------------------------");

                //display confirm/cancel options
                Console.ForegroundColor = EmphasisColor;
                Console.Write("\t5. ");
                Console.WriteLine("Confirm edit");
                Console.Write("\t6. ");
                Console.WriteLine("Cancel and return to menu");
                Console.ResetColor();
                Console.WriteLine();

                //display error message
                if (hadError)
                {
                    Console.ForegroundColor = ErrorColor;
                    Console.WriteLine("\tInvalid entry.");
                    Console.WriteLine();
                    Console.ResetColor();
                }

                // get user input
                Console.ForegroundColor = PromptColor;
                Console.Write("\tEnter an option: ");
                Console.ForegroundColor = EmphasisColor;
                string userInput = Console.ReadLine().Trim();
                Console.ResetColor();

                switch (userInput)
                {
                case "1":
                case "1.":
                    //enter new name
                    Console.Clear();
                    string newName = "";
                    while (string.IsNullOrEmpty(newName))
                    {
                        Console.WriteLine();
                        Console.WriteLine();
                        Console.ForegroundColor = PromptColor;
                        Console.Write("\tEnter the new customer name: ");
                        Console.ForegroundColor = EmphasisColor;
                        newName = Console.ReadLine();
                        Console.ResetColor();
                        Console.Clear();
                    }
                    orderToEdit.CustomerName = newName;
                    fieldChanged             = 1;
                    hadError = false;
                    break;

                case "2":
                case "2.":
                    //enter new state
                    Console.Clear();
                    orderToEdit.State = PromptForValidState("Enter the new state: ");
                    orderToEdit       = OrderOperations.CalculateRemainingOrderFields(orderToEdit, false);
                    Console.Clear();
                    fieldChanged = 2;
                    hadError     = false;
                    break;

                case "3":
                case "3.":
                    //enter new product type
                    Console.Clear();
                    orderToEdit.ProductType = PromptForValidProductType("Enter the new product type: ").Type;
                    orderToEdit             = OrderOperations.CalculateRemainingOrderFields(orderToEdit, false);
                    Console.Clear();
                    fieldChanged = 3;
                    hadError     = false;
                    break;

                case "4":
                case "4.":
                    //enter new area
                    Console.Clear();
                    ProductType currentProductType = ProductTypeOperations.GetProductType(orderToEdit.ProductType);
                    orderToEdit.Area = PromptForValidArea(currentProductType);
                    orderToEdit      = OrderOperations.CalculateRemainingOrderFields(orderToEdit, false);
                    Console.Clear();
                    fieldChanged = 4;
                    hadError     = false;
                    break;

                case "5":
                case "5.":
                    //confirm order
                    Console.Clear();
                    doneEditing = true;
                    break;

                case "6":
                case "6.":
                    //cancel and return to main menu
                    Console.Clear();
                    return(null);

                default:
                    //invalid input
                    Console.Clear();
                    hadError = true;
                    break;
                }
            }

            return(orderToEdit);
        }
示例#7
0
        private static ProductType PromptForValidProductType(string prompt, bool extraInfo = false)
        {
            ProductType        productType  = null;
            List <ProductType> productTypes = ProductTypeOperations.GetAllProductTypes();
            string             userInput    = "";
            bool validProduct         = false;
            bool error                = false;
            bool displayedAllProducts = false;

            while (!validProduct)
            {
                if (!displayedAllProducts && (!extraInfo || error))
                {
                    OffsetTop();
                }

                //display 10 current products and give them the chance to see all of them
                if (!displayedAllProducts)
                {
                    DisplayProductTypes(false);
                }

                //if there was an error in the last time through the loop
                if (error)
                {
                    Console.ForegroundColor = ErrorColor;
                    Console.WriteLine("\tInvalid Product.");
                    Console.WriteLine();
                }

                //get the user input
                Console.ForegroundColor = PromptColor;
                Console.Write("\t" + prompt);
                Console.ForegroundColor = EmphasisColor;
                userInput = Console.ReadLine().Trim();
                Console.ResetColor();
                Console.Clear();

                if (userInput == "") //they want to display all product types
                {
                    OffsetTop();
                    DisplayProductTypes(true);
                    displayedAllProducts = true;
                }
                else if (ProductTypeOperations.IsProductType(userInput))
                {
                    productType = ProductTypeOperations.GetProductType(userInput);
                    Console.Clear();

                    if (extraInfo)
                    {
                        OffsetTop();
                        Console.WriteLine("\t{0} cost per square foot: {1:C}", productType.Type, productType.CostPerSquareFoot);
                        Console.WriteLine("\t{0} labor cost per square foot: {1:C}", productType.Type, productType.LaborCostPerSquareFoot);
                        Console.WriteLine("\t----------------------------------------");
                        Console.WriteLine();
                    }

                    validProduct = true;
                }
                else
                {
                    error = true;
                    if (displayedAllProducts) //the console was just cleared, so we don't want the error list to go away
                    {
                        OffsetTop();
                        DisplayProductTypes(true);
                    }
                }
            }
            return(productType);
        }