Exemple #1
0
        private void AskToEditState()
        {
            StateManager     stateManager = StateManagerFactory.Create(); //calls state repo
            AddOrderResponse response     = new AddOrderResponse();

            Console.Clear();
            ConsoleIO.DisplaySingleOrder(_originalOrder);

            while (true)
            {
                Console.Write("Enter new state or just press enter to continue: ");
                string state = Console.ReadLine();

                if (state == "" || state == null)
                {
                    _taxState = stateManager.GetStateInfo(_originalOrder.State);
                    break;
                }
                else
                {
                    response = stateManager.ValidateState(state.ToLower());
                    if (response.Success == false)
                    {
                        Console.WriteLine("The state entered is not valid. Press any key to continue.");
                        continue;
                    }
                    else
                    {
                        _taxState = stateManager.GetStateInfo(state.ToLower());
                        break;
                    }
                }
            }
        }
Exemple #2
0
        public void StateFileListLookupTest()
        {
            StateManager manager = StateManagerFactory.Create();

            StateFileLookup response = manager.ListAllStates();

            Assert.IsNotNull(response.StateList);
            Assert.IsTrue(response.Success);
        }
Exemple #3
0
        public ActionResult Purchase(PurchaseListingVM model)
        {
            _purchaseManager = PurchaseManagerFactory.Create();
            _stateManager    = StateManagerFactory.Create();
            _listingManager  = ListingManagerFactory.Create();

            try
            {
                var listingResponse = _listingManager.GetListingById(model.ListingToPurchase.ListingId);

                model.ListingToPurchase = listingResponse.Payload;

                if (ModelState.IsValid)
                {
                    //set sold listing in db


                    //set user name
                    model.PurchaseForm.UserName = User.Identity.Name;

                    //set listing id
                    model.PurchaseForm.ListingId = model.ListingToPurchase.ListingId;

                    //set date
                    model.PurchaseForm.DateAdded = DateTime.Now;



                    //send to manager
                    var response = _purchaseManager.SavePurchase(model.PurchaseForm);

                    if (!response.Success)
                    {
                        return(new HttpStatusCodeResult(500, $"Error in cloud. Message:{response.Message}"));
                    }
                }
                else
                {
                    var stateResponse = _stateManager.GetAllStates();

                    model.States = stateResponse.Payload.Select(m => new SelectListItem
                    {
                        Text  = m.StateAbbreviation,
                        Value = m.StateId.ToString()
                    });


                    return(View(model));
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Something wrong happened while loading a purchase:", ex);
            }
        }
Exemple #4
0
        public void StateFileChoseTest()
        {
            StateManager manager = StateManagerFactory.Create();

            StateLookupResponse response = manager.LookupState("OH");

            Assert.IsNotNull(response.StateTax.State);
            Assert.IsTrue(response.Success);
            Assert.AreEqual("OH", response.StateTax.State);
        }
Exemple #5
0
        public ActionResult Purchase(int id)
        {
            try
            {
                _listingManager = ListingManagerFactory.Create();
                _stateManager   = StateManagerFactory.Create();

                var listingResponse = _listingManager.GetListingById(id);

                if (!listingResponse.Success)
                {
                    return(new HttpStatusCodeResult(500, $"Error in cloud. Message:{listingResponse.Message}"));
                }
                else
                {
                    var model = new PurchaseListingVM
                    {
                        ListingToPurchase = listingResponse.Payload,
                        PurchaseForm      = new Purchase()
                    };

                    var stateResponse = _stateManager.GetAllStates();

                    model.States = stateResponse.Payload.Select(m => new SelectListItem
                    {
                        Text  = m.StateAbbreviation,
                        Value = m.StateId.ToString()
                    });

                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Something wrong happened while loading a purchase:", ex);
            }
        }
        public void Execute()
        {
            Console.Clear();
            StateManager   stateManager   = StateManagerFactory.Create();
            ProductManager productManager = ProductManagerFactory.Create();
            OrderManager   orderManager   = OrderManagerFactory.Create();
            Orders         newOrder       = new Orders();


            ConsoleIO.OrderHeader("Add an Order");
            Console.WriteLine("Please enter a future date for the order.");
            newOrder.orderDate = ConsoleIO.GetFutureDateFromUser();
            var numberResponse = orderManager.GetOrderNumber(ConsoleIO.OrderDate);

            newOrder.OrderNumber = numberResponse.OrderNumber;
            newOrder.Name        = ConsoleIO.GetCustomerNameFromUserForAdd();
            Console.Clear();
            var response = stateManager.ListAllStates();

            if (response.Success)
            {
                ConsoleIO.OrderHeader("Add an Order");
                ConsoleIO.DisplayAllStates(response.StateList);
                while (true)
                {
                    string state    = ConsoleIO.GetStateFromUserForAdd();
                    var    StateTax = stateManager.LookupState(state);
                    if (StateTax.Success)
                    {
                        newOrder.State   = StateTax.StateTax.State;
                        newOrder.TaxRate = StateTax.StateTax.TaxRate;
                        break;
                    }
                    else
                    {
                        Console.WriteLine(StateTax.Message);
                        ConsoleIO.EnterKeyToContinue();
                    }
                }
                ConsoleIO.OrderHeader("Add an Order");
                var productresponse = productManager.ProductList();
                if (productresponse.Success)
                {
                    ConsoleIO.DisplayAllProducts(productresponse.Products);

                    while (true)
                    {
                        string product         = ConsoleIO.GetProductTypeFromUser();
                        var    customerProduct = productManager.ChooseProduct(product);
                        if (customerProduct.Success)
                        {
                            newOrder.PrductType             = customerProduct.Product.ProductType;
                            newOrder.CostPerSqureFoot       = customerProduct.Product.CostPerSquareFoot;
                            newOrder.LaborCostPerSquareFoot = customerProduct.Product.LaborCostPerSquareFoot;
                            break;
                        }

                        else
                        {
                            Console.WriteLine(customerProduct.Message);
                            ConsoleIO.EnterKeyToContinue();
                        }
                    }
                    ConsoleIO.OrderHeader("Add an Order");
                    Console.WriteLine(ConsoleIO.SeparatorBar);
                    newOrder.Area = ConsoleIO.GetAreaFromUser();



                    newOrder.MaterialCost = newOrder.Area * newOrder.CostPerSqureFoot;
                    newOrder.LaborCost    = newOrder.Area * newOrder.LaborCostPerSquareFoot;
                    newOrder.Tax          = (newOrder.MaterialCost + newOrder.LaborCost) * (newOrder.TaxRate / 100);
                    newOrder.Total        = newOrder.MaterialCost + newOrder.LaborCost + newOrder.Tax;

                    ConsoleIO.OrderHeader("Add an Order");
                    ConsoleIO.DisplayOrders(newOrder);
                    Console.WriteLine(ConsoleIO.SeparatorBar);
                    string answer = ConsoleIO.GetYesNoAnswerFromUser("Would you like to place this order?: ");
                    if (answer == "Y")
                    {
                        var createresponse = orderManager.CreateOrder(newOrder, ConsoleIO.OrderDate);
                        if (createresponse.Success)
                        {
                            Console.WriteLine("The order was placed!");
                            ConsoleIO.EnterKeyToContinue();
                        }
                        else
                        {
                            Console.WriteLine(createresponse.Message);
                            ConsoleIO.EnterKeyToContinue();
                        }
                    }
                    else
                    {
                        Console.WriteLine("The order was cancelled.");
                        ConsoleIO.EnterKeyToContinue();
                    }
                }
                else
                {
                    Console.WriteLine(productresponse.Message);
                    ConsoleIO.EnterKeyToContinue();
                }
            }

            else
            {
                Console.WriteLine(response.Message);
                ConsoleIO.EnterKeyToContinue();
            }
        }
Exemple #7
0
        public void Execute()
        {
            OrderManager   manager        = OrderManagerFactory.Create();
            StateManager   stateManager   = StateManagerFactory.Create();
            ProductManager productManager = ProductManagerFactory.Create();


            ConsoleIO.OrderHeader("Edit an Order:");
            Console.WriteLine("Please enter the date of the order you would like to edit.");

            var repo = manager.GetAllOrders(ConsoleIO.GetDateFromUser());

            if (repo.Success)
            {
                ConsoleIO.OrderHeader("Edit an Order:");
                ConsoleIO.DisplayAllOdersForDate(repo.Orders);
                Console.WriteLine(ConsoleIO.SeparatorBar);
                Console.WriteLine();

                int orderNumber = ConsoleIO.GetOrderNumberFromUser("Which order number would you like to edit?: ");
                var ordertoedit = manager.LookupOrder(ConsoleIO.OrderDate, orderNumber);
                if (ordertoedit.Success)
                {
                    ConsoleIO.OrderHeader("Edit an Order:");
                    Console.WriteLine("Type the information to edit in the following prompts.\n If you wish to keep the information in parenthesis simply press enter.");
                    string name = ConsoleIO.GetCustomerNameEdit(ordertoedit.Order.Name);
                    if (!string.IsNullOrEmpty(name))
                    {
                        ordertoedit.Order.Name = name;
                    }
                    var response = stateManager.ListAllStates();
                    if (response.Success)
                    {
                        ConsoleIO.OrderHeader("Edit an Order:Type the information to edit in the following prompts.\n If you wish to keep the information in parenthesis simply press enter.");
                        ConsoleIO.DisplayAllStates(response.StateList);
                        Console.WriteLine();
                        while (true)
                        {
                            string state = ConsoleIO.GetStateForEdit(ordertoedit.Order.State);
                            if (!string.IsNullOrEmpty(state))
                            {
                                var StateTax = stateManager.LookupState(state);
                                if (StateTax.Success)
                                {
                                    ordertoedit.Order.State   = StateTax.StateTax.State;
                                    ordertoedit.Order.TaxRate = StateTax.StateTax.TaxRate;
                                    break;
                                }
                                else
                                {
                                    Console.WriteLine(StateTax.Message);
                                    ConsoleIO.EnterKeyToContinue();
                                }
                            }
                            break;
                        }
                    }
                    ConsoleIO.OrderHeader("Edit an Order:Type the information to edit in the following prompts.\n If you wish to keep the information in parenthesis simply press enter.");
                    var productresponse = productManager.ProductList();
                    if (productresponse.Success)
                    {
                        ConsoleIO.DisplayAllProducts(productresponse.Products);
                        Console.WriteLine();

                        while (true)
                        {
                            string product = ConsoleIO.GetProductTypeForEdit(ordertoedit.Order.PrductType);
                            if (!string.IsNullOrEmpty(product))
                            {
                                var customerProduct = productManager.ChooseProduct(product);
                                if (customerProduct.Success)
                                {
                                    ordertoedit.Order.PrductType             = customerProduct.Product.ProductType;
                                    ordertoedit.Order.CostPerSqureFoot       = customerProduct.Product.CostPerSquareFoot;
                                    ordertoedit.Order.LaborCostPerSquareFoot =
                                        customerProduct.Product.LaborCostPerSquareFoot;
                                    break;
                                }

                                else
                                {
                                    Console.WriteLine(customerProduct.Message);
                                    ConsoleIO.EnterKeyToContinue();
                                }
                            }
                            break;
                        }

                        while (true)
                        {
                            decimal area;
                            ConsoleIO.OrderHeader("Edit an Order:Type the information to edit in the following prompts. \nIf you wish to keep the information in parenthesis simply press enter.");
                            Console.Write($"Enter the squarefootage for the floor ({ordertoedit.Order.Area}): ");
                            string input = Console.ReadLine();
                            if (string.IsNullOrEmpty(input))
                            {
                                break;
                            }
                            if (!decimal.TryParse(input, out area))
                            {
                                Console.WriteLine("You must enter valid number.");
                                Console.WriteLine("Press any key to continue...");
                                Console.ReadKey();
                            }
                            if (area < 100)
                            {
                                Console.WriteLine("The square foot area must be at least 100 square feet.");
                                ConsoleIO.EnterKeyToContinue();
                            }

                            else
                            {
                                ordertoedit.Order.Area = area;
                                break;
                            }
                        }
                        ConsoleIO.OrderHeader("Edit an Order:");
                        ConsoleIO.DisplayOrders(ordertoedit.Order);
                        string answer = ConsoleIO.GetYesNoAnswerFromUser("Would you like to update this order?: ");
                        if (answer == "Y")
                        {
                            var editResponse = manager.EditOrder(ordertoedit.Order, ConsoleIO.OrderDate);
                            if (editResponse.Success)
                            {
                                Console.WriteLine("The order was updated!");
                                ConsoleIO.EnterKeyToContinue();
                            }
                            else
                            {
                                Console.WriteLine(editResponse.Message);
                                ConsoleIO.EnterKeyToContinue();
                            }
                        }
                        else
                        {
                            Console.WriteLine("The edit was cancelled.");
                            ConsoleIO.EnterKeyToContinue();
                        }


                        ordertoedit.Order.MaterialCost = ordertoedit.Order.Area * ordertoedit.Order.CostPerSqureFoot;
                        ordertoedit.Order.LaborCost    = ordertoedit.Order.Area * ordertoedit.Order.LaborCostPerSquareFoot;
                        ordertoedit.Order.Tax          = (ordertoedit.Order.MaterialCost + ordertoedit.Order.LaborCost) *
                                                         (ordertoedit.Order.TaxRate / 100);
                        ordertoedit.Order.Total = ordertoedit.Order.MaterialCost + ordertoedit.Order.LaborCost +
                                                  ordertoedit.Order.Tax;

                        Console.Clear();
                        ConsoleIO.DisplayOrders(ordertoedit.Order);
                        Console.WriteLine(ConsoleIO.SeparatorBar);
                    }

                    else
                    {
                        Console.WriteLine(response.Message);
                        ConsoleIO.EnterKeyToContinue();
                    }
                }

                else
                {
                    Console.WriteLine(ordertoedit.Message);
                    ConsoleIO.EnterKeyToContinue();
                }
            }
            else
            {
                Console.WriteLine(repo.Message);
                ConsoleIO.EnterKeyToContinue();
            }
        }