/// <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); }
public string GetDetailsHtml(PizzaState pizzaState) { return(replacedStep.GetDetailsHtml(pizzaState)); }