Click here to Skip to main content
15,891,529 members
Articles / Web Development / HTML

Build a Google IG like AJAX Start Page in 7 days using ASP.NET AJAX and .NET 3.0

Rate me:
Please Sign up or sign in to vote.
4.80/5 (325 votes)
10 Mar 2010CPOL38 min read 1.8M   7.8K   1.1K  
Build a Start Page similar to Google IG in 7 nights using ASP.NET AJAX, .NET 3.0, LINQ, DLinq, and XLinq.
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Security;
using System.Transactions;
using System.Query;
using System.Data.DLinq;

using DashboardDataAccess;

namespace DashboardBusiness
{    
	public class DashboardFacade
	{
        private string _UserName; 

        public DashboardFacade( string userName )
        {
            this._UserName = userName;
        }

        public UserPageSetup NewUserVisit( )
        {
            using( new TimedLog(this._UserName, "New user visit") )
            {
                var properties = new Dictionary<string,object>();
                properties.Add("UserName", this._UserName);
                var userSetup = new UserPageSetup();
                properties.Add("UserPageSetup", userSetup);
                
                WorkflowHelper.ExecuteWorkflow( typeof( NewUserSetupWorkflow ), properties ); 

                return userSetup;
            }
        }

        public UserPageSetup LoadUserSetup( )
        {
            using( new TimedLog(this._UserName, "Total: Existing user visit") )
            {
                var properties = new Dictionary<string,object>();
                properties.Add("UserName", this._UserName);
                var userSetup = new UserPageSetup();
                properties.Add("UserPageSetup", userSetup);
                    
                WorkflowHelper.ExecuteWorkflow( typeof( UserVisitWorkflow ), properties ); 

                return userSetup;
            }
        }

        public void AddNewPage( )
        {
            using( new TimedLog(this._UserName, "Add New Page") )
            {
                var properties = new Dictionary<string,object>();
                properties.Add("UserName", this._UserName);
                    
                WorkflowHelper.ExecuteWorkflow( typeof( AddNewTabWorkflow ), properties ); 
            }
        }


        public void DeleteWidgetInstance( WidgetInstance instance )
        {
            using( new TimedLog(this._UserName, "Delete Widget:" + instance.Title) )
            {
                var properties = new Dictionary<string,object>();
                properties.Add("WidgetInstanceId", instance.Id);
                properties.Add("PageId", instance.PageId);
                properties.Add("ColumnNo", instance.ColumnNo);
                
                WorkflowHelper.ExecuteWorkflow( typeof( DeleteWidgetInstanceWorkflow ), properties );
            }
        }

        public void MoveWidgetInstance( int widgetInstanceId, int toColumn, int toRow )
        {
            using( new TimedLog(this._UserName, "Move Widget:" + widgetInstanceId) )
            {
                var properties = new Dictionary<string,object>();
                properties.Add("WidgetInstanceId", widgetInstanceId);
                properties.Add("ColumnNo", toColumn);
                properties.Add("RowNo", toRow);
                
                WorkflowHelper.ExecuteWorkflow( typeof( MoveWidgetInstanceWorkflow ), properties );
            }
        }

        public List<Widget> GetWidgetList()
        {
            return DatabaseHelper.GetDashboardData().Widgets.ToList();
        }

        public void AddWidget(int widgetId)
        {
            using( new TimedLog(this._UserName, "Add Widget" + widgetId) )
            {
                var properties = new Dictionary<string,object>();
                properties.Add("UserName", this._UserName);
                properties.Add("WidgetId", widgetId);
                
                WorkflowHelper.ExecuteWorkflow( typeof( AddWidgetWorkflow ), properties );
            }
        }

        public void RegisterAs(string email)
        {
            using( new TimedLog( this._UserName, "Register As: " + email) )
            {
                DashboardData db = DatabaseHelper.GetDashboardData();

                MembershipUser newUser = Membership.GetUser(email);
                
                // Get the User Id for the anonymous user from the aspnet_users table
                AspnetUser anonUser = db.AspnetUsers.Single( u => u.LoweredUserName == this._UserName && u.ApplicationId == DatabaseHelper.ApplicationGuid );

                Guid oldGuid = anonUser.UserId;
                Guid newGuid = (Guid)newUser.ProviderUserKey;

                // Move page ownership
                using( TransactionScope ts = new TransactionScope() )
                {
                    List<Page> pages = db.Pages.Where( p => p.UserId == oldGuid ).ToList();
                    foreach( Page page in pages )
                        page.UserId = newGuid;
                    
                    // Change setting ownership
                    UserSetting setting = db.UserSettings.Single( u => u.UserId == oldGuid );
                    db.UserSettings.Remove(setting);
                    
                    setting.UserId = newGuid;
                    db.UserSettings.Add(setting);
                    db.SubmitChanges();

                    ts.Complete();
                }
            }
        }

        public void ChangePageName(string newName)
        {
            using( new TimedLog(this._UserName, "Change Page Name") )
            {
                var properties = new Dictionary<string,object>();
                properties.Add("UserName", this._UserName);
                var userSetup = new UserPageSetup();
                properties.Add("PageName", newName);
                    
                WorkflowHelper.ExecuteWorkflow( typeof( ChangePageNameWorkflow ), properties ); 
            }
        }
	}
}

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
Architect BT, UK (ex British Telecom)
United Kingdom United Kingdom

Comments and Discussions