コード例 #1
0
 public Pizza(String pName)
 {
     pizzaName        = pName;
     productGathering = new ProductGatheringState(this);
     cooking          = new CookingState(this);
     packing          = new PackingState(this);
     delivery         = new DeliveryState(this);
     currentState     = productGathering;
 }
コード例 #2
0
        public string GetDetailsHtml(PizzaState wizardState)
        {
            var pizza = pizzaFactory.CreatePizza(wizardState);

            return
                (string.Format(
                     "<div>Selected pizza: {0}</div><div>Price: <span style=\"font-weight: bold; font-size: larger;\">{1}</span></div>",
                     pizza.PizzaDescription,
                     priceCalculator.CalculatePrice(pizza).ToString("c")));
        }
コード例 #3
0
        /// <summary>
        /// Examines the current state object and uses it to build the view model
        /// </summary>
        /// <param name="currentState"></param>
        /// <returns></returns>
        private PizzaCreationViewModel BuildViewModel(PizzaState currentState)
        {
            IPizzaCreationStep currentStep = null;
            var viewModel = new PizzaCreationViewModel();

            // Iterate through all steps in the creation process
            foreach (var step in creationProcess.GetStepsInProcess())
            {
                // If the state object contains data for the current step, test for validation
                var stateForCurrentStep = currentState.StepResults.SingleOrDefault(x => x.StepName == step.StepName);
                if (stateForCurrentStep != null)
                {
                    // test for validation
                    var validationResult = step.Validate(stateForCurrentStep);
                    if (!validationResult)
                    {
                        // If validation fails, this is the current step.
                        currentStep = step;
                        // Add the validation message to the view model
                        viewModel.ShowValidationMessage = true;
                        viewModel.ValidationMessage     = currentStep.ValidationErrorMessage(stateForCurrentStep);
                        break;
                    }
                    else
                    {
                        // If validation passes, move on to the next step.
                        continue;
                    }
                }
                else
                {
                    // If the state object does not contain this step, it is the current step
                    currentStep = step;
                    break;
                }
            }

            // If the user has continued past the last step, throw an exception. This could be handled better.
            if (currentStep == null)
            {
                throw new ApplicationException("Continued past last step. Last step should not have any options.");
            }

            // Build the view model using the current step object of our current state.
            viewModel.CanSelectMultiple = currentStep.CanSelectMultiple;
            viewModel.CurrentStateId    = currentState.Id;
            viewModel.CurrentStepName   = currentStep.StepName;
            viewModel.DetailsHtml       = currentStep.GetDetailsHtml(currentState);
            viewModel.HeaderText        = currentStep.StepHeaderText;
            viewModel.Options           = currentStep.Options;

            // Return the view model
            return(viewModel);
        }
コード例 #4
0
        public IPizza CreatePizza(PizzaState pizzaState)
        {
            var size     = pizzaState.StepResults.Single(x => x.StepName == "Size").SelectedOptions.Single();
            var dough    = pizzaState.StepResults.Single(x => x.StepName == "Dough").SelectedOptions.Single();
            var toppings = pizzaState.StepResults.Single(x => x.StepName == "Toppings").SelectedOptions;

            return(new BasicPizza()
            {
                Size = size,
                Dough = dough,
                Toppings = toppings,
                PizzaDescription = string.Format("{0} Pizza on {1} Dough, and topped with {2}", size, dough, string.Join(", ", toppings))
            });
        }
コード例 #5
0
        public void Save(PizzaState pizzaState)
        {
            if (string.IsNullOrEmpty(pizzaState.Id))
            {
                pizzaState.Id = Guid.NewGuid().ToString();
            }

            if (stateDictionary.ContainsKey(pizzaState.Id))
            {
                stateDictionary[pizzaState.Id] = pizzaState;
            }
            else
            {
                stateDictionary.Add(pizzaState.Id, pizzaState);
            }
        }
コード例 #6
0
        public ActionResult Index(string id = null)
        {
            // Attempt to load the state associated with the id
            var currentState = stateRepository.Load(id);

            // If the state doesn't exist, create a new state object and save it
            if (currentState == null)
            {
                currentState = new PizzaState()
                {
                    Id = Guid.NewGuid().ToString()
                };
                stateRepository.Save(currentState);
            }

            // Build the view model based on the state object and return the view
            return(View(BuildViewModel(currentState)));
        }
コード例 #7
0
 public string GetDetailsHtml(PizzaState pizzaState)
 {
     return("");
 }
コード例 #8
0
 public void setState(PizzaState state)
 {
     this.currentState = state;
 }
コード例 #9
0
 public string GetDetailsHtml(PizzaState pizzaState)
 {
     return(replacedStep.GetDetailsHtml(pizzaState));
 }