Click here to Skip to main content
15,885,366 members
Articles / Web Development / ASP.NET

Navigational Workflows Unleashed in WWF/ASP.NET 3.5

Rate me:
Please Sign up or sign in to vote.
4.97/5 (42 votes)
21 Oct 2008CPOL18 min read 224.9K   1.6K   165  
Case-study on the internals of a Navigational Workflow engine for a fictional dating website called “World Wide Dating”.
using System;

namespace DateSite
{
    /// <summary>
    /// Page for entering personal appearance information.
    /// </summary>
    public partial class appearance : System.Web.UI.Page
    {
        private WorkflowManager _workflowManager;
        private Profile _profile;

        /// <summary>
        /// Page initialization code.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Init(object sender, EventArgs e)
        {
            // create an instance of the navigational workflow manager
            _workflowManager = new WorkflowManager(Application, Session, Request, Response);

            // make sure the workflow is synchronized... meaning the page we are on is the page we should be on / can be on
            _workflowManager.SynchronizeWorkflow();

            // get the dating id from session
            string datingId = Session["datingId"] as string;

            // retrieve the given user's profile
            _profile = Database.SelectProfile(datingId);

            // populate the data on the page
            LoadData();
        }

        /// <summary>
        /// Navigate to the previous page in the navigational workflow.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnPrevious_Click(object sender, EventArgs e)
        {
            // navigate to the previous page
            string pageToGoTo = _workflowManager.Previous();
            _workflowManager.ManagedRedirect(pageToGoTo);
        }

        /// <summary>
        /// Navigate to the next page in the navigational workflow.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnNext_Click(object sender, EventArgs e)
        {
            // save data to database
            SaveData();

            // navigate to the next page
            string pageToGoTo = _workflowManager.Next();
            _workflowManager.ManagedRedirect(pageToGoTo);
        }

        /// <summary>
        /// Load appearance information from the database.
        /// </summary>
        private void LoadData()
        {
            if (_profile.EyeColor != null)
                ddlEyeColor.SelectedValue = _profile.EyeColor;

            if (_profile.HairColor != null)
                ddlHairColor.SelectedValue = _profile.HairColor;

            if (_profile.BestFeature != null)
                ddlBestFeature.SelectedValue = _profile.BestFeature;
        }

        /// <summary>
        /// Save the appearance information to the database.
        /// </summary>
        private void SaveData()
        {
            _profile.EyeColor = ddlEyeColor.SelectedValue;
            _profile.HairColor = ddlHairColor.SelectedValue;
            _profile.BestFeature = ddlBestFeature.SelectedValue;

            Database.UpdateProfile(_profile);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Turing Inc.
United States United States

Comments and Discussions