protected void Page_Load(object sender, EventArgs e)
        {
            if (!Request.IsAuthenticated)
            {
                Response.Redirect(WebConfigurationManager.AppSettings["LoginPageURL"].ToString());
            }

            RadAjaxManager.GetCurrent(Page).AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(Schedule_AjaxRequest);
            if (!Page.IsPostBack)
            {
                using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext())
                {
                    if (!StoredData.User.TempDivision.Value && !StoredData.User.AccessExpired.Value)
                    {
                        var upcomingMatches = dataContext.GetUpcomingMatches(StoredData.User.UserId);
                        upcomingMatchesRadGrid.DataSource = upcomingMatches;
                        upcomingMatchesRadGrid.DataBind();

                        var previousMatches = dataContext.GetPreviousMatches(StoredData.User.UserId);
                        previousMatchesRadGrid.DataSource = previousMatches;
                        previousMatchesRadGrid.DataBind();

                        List <SelectDivisionResult> selectDivisionResult = dataContext.SelectDivision(StoredData.User.Division.Value).ToList();
                        foreach (SelectDivisionResult result in selectDivisionResult)
                        {
                            if (result.StartDate > DateTime.Now)
                            {
                                warningImage.Visible      = true;
                                warningLinkButton.Visible = true;
                                warningLinkButton.Text    = "Although you may play practice matches with members in your league. You will not be able to record scores until the league start date of " + result.StartDate.ToShortDateString();
                                HyperLink1.Visible        = false;
                                Image1.Visible            = false;
                            }
                        }
                    }
                    else
                    {
                        warningImage.Visible      = true;
                        warningLinkButton.Visible = true;
                        Image1.Visible            = false;
                        HyperLink1.Visible        = false;

                        if (StoredData.User.TempDivision.Value)
                        {
                            warningLinkButton.Text = "Your account is still being created. You will not be able to schedule matches or report scores. Please wait for the email confirming your account activation.";
                        }
                        else if (StoredData.User.AccessExpired.Value)
                        {
                            warningLinkButton.Text        = "Your access has expired. Please click here to subscribe to the current season and regain access.";
                            warningLinkButton.PostBackUrl = WebConfigurationManager.AppSettings["NewLeagueRegisterURL"].ToString();
                        }
                    }
                }
            }
        }
        protected void Schedule_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            if (e.Argument == "RefreshPreviousMatches")
            {
                using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext())
                {
                    var upcomingMatches = dataContext.GetUpcomingMatches(StoredData.User.UserId);
                    upcomingMatchesRadGrid.DataSource = upcomingMatches;
                    upcomingMatchesRadGrid.Rebind();

                    var previousMatches = dataContext.GetPreviousMatches(StoredData.User.UserId);
                    previousMatchesRadGrid.DataSource = previousMatches;
                    previousMatchesRadGrid.Rebind();
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Request.IsAuthenticated)
            {
                Response.Redirect(WebConfigurationManager.AppSettings["LoginPageURL"].ToString());
            }

            Guid userId = new Guid(Request.QueryString["UserId"]);

            using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext())
            {
                ISingleResult <SelectUserPublicProfileByProfileIdResult> users = dataContext.SelectUserPublicProfileByProfileId(userId);
                SelectUserPublicProfileByProfileIdResult user = users.First();
                userLabel.Text = user.FirstName + " " + user.LastName;

                //Load Image
                if (user.ProfileImageName.HasValue)
                {
                    profileImage.ImageUrl = string.Format("~/ProfileImages/{0}.jpg", user.ProfileImageName.ToString());
                }

                divisionLabel.Text     = user.Division;
                homeCourtLabel.Text    = user.CourtName;
                ntrpRankingLabel.Text  = user.NTRPRanking.ToString();
                ageGroupLabel.Text     = user.AgeGroup;
                racquetHandLabel.Text  = user.RacquetHand;
                favoriteShotLabel.Text = user.FavoriteShot;
                racquetLabel.Text      = user.Racquet;


                if (!StoredData.User.TempDivision.Value || (user.DivisionId != StoredData.User.Division) || !StoredData.User.AccessExpired.Value)
                {
                    emailHyperLink.Text           = user.EmailId;
                    emailHyperLink.NavigateUrl    = string.Format("mailto:{0}", user.EmailId);
                    phoneLabel.Text               = user.Phone;
                    facebookHyperLink.Text        = user.Facebook;
                    facebookHyperLink.NavigateUrl = user.Facebook;
                    linkedInHyperLink.Text        = user.LinkedIn;
                    linkedInHyperLink.NavigateUrl = user.LinkedIn;
                    myspaceHyperLink.Text         = user.MySpace;
                    myspaceHyperLink.NavigateUrl  = user.MySpace;
                    orkutHyperLink.Text           = user.Orkut;
                    orkutHyperLink.NavigateUrl    = user.Orkut;
                }

                List <Performance> performances = dataContext.SelectPerformanceByUserId(user.UserId).ToList();

                Performance seasonPerformance = performances.Find(p => p.DivisionId == user.DivisionId);
                seasonWinsLabel.Text   = string.Format("{0}W - {1}L", seasonPerformance.Win, seasonPerformance.Loss);
                seasonPointsLabel.Text = seasonPerformance.TotalPoints.ToString();

                overallWinsLabel.Text   = string.Format("{0}W - {1}L", performances.Sum(p => p.Win), performances.Sum(p => p.Loss));
                overallPointsLabel.Text = performances.Sum(p => p.TotalPoints).ToString();

                if (!StoredData.User.TempDivision.Value)
                {
                    List <GetUpcomingMatchesResult> upcomingMatches = dataContext.GetUpcomingMatches(user.UserId).ToList();
                    upcomingMatchesRadGrid.DataSource = upcomingMatches;
                    upcomingMatchesRadGrid.DataBind();

                    List <GetPreviousMatchesResult> previousMatches = dataContext.GetPreviousMatches(user.UserId).ToList();
                    previousMatchesRadGrid.DataSource = previousMatches;
                    previousMatchesRadGrid.DataBind();


                    int upcomingMatchCount = Convert.ToInt32(upcomingMatches.Count(p => p.UserId == StoredData.User.UserId));
                    int previousMatchCount = Convert.ToInt32(previousMatches.Count(p => p.UserId == StoredData.User.UserId));
                }

                //Get availability
                List <SelectAvailabilitiesByUserIdResult> availabilities = dataContext.SelectAvailabilitiesByUserId(user.UserId).ToList();
                SetAvailabilities(availabilities);

                if (StoredData.User.TempDivision.Value || StoredData.User.AccessExpired.Value)
                {
                    matchRequestLinkButton.Enabled = false;
                }
                else
                {
                    List <SelectDivisionResult> selectDivisionResult = dataContext.SelectDivision(StoredData.User.Division.Value).ToList();
                    foreach (SelectDivisionResult result in selectDivisionResult)
                    {
                        if (result.StartDate > DateTime.Now)
                        {
                            matchRequestLinkButton.Enabled = false;
                        }
                    }
                }

                //TODO: Have to uncomment these lines below
                //if ((upcomingMatchCount + previousMatchCount) < 2)
                matchRequestLinkButton.Attributes.Add("onClick", string.Format("openRadWindow('{0}'); return false;", user.UserId));
                //else
                //matchRequestLinkButton.Attributes.Add("onClick", "alert('You have already played two matches against this player for the season. You cannot play against a player more than twice.');return false;");
                //matchRequestLinkButton.PostBackUrl = WebConfigurationManager.AppSettings["MatchRequestPath"].ToString();
            }
        }