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

            ChangePassword1.SuccessPageUrl = WebConfigurationManager.AppSettings["SuccessPageURL"].ToString();
            photoRadWindow1.NavigateUrl    = WebConfigurationManager.AppSettings["PhotoUploadNavigateURL"].ToString();

            //if (!Page.IsPostBack)
            //{
            //    upcomingLeagueButton.Attributes.Add("onclick", "this.style.display='none';");
            //}

            using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext())
            {
                if (!Page.IsPostBack)
                {
                    List <TennisCourt> tennisCourts = dataContext.SelectTennisCourtsByLeague(Convert.ToInt32(WebConfigurationManager.AppSettings["LeagueCityId"])).ToList();
                    homeCourtDropDownList.Items.Add(string.Empty);
                    foreach (TennisCourt tennisCourt in tennisCourts)
                    {
                        homeCourtDropDownList.Items.Add(new ListItem(tennisCourt.CourtName, tennisCourt.CourtId.ToString()));
                    }
                    int userNextDivision = 0;

                    ISingleResult <SelectUserByEmailIdResult> users = dataContext.SelectUserByEmailId(HttpContext.Current.User.Identity.Name);
                    foreach (SelectUserByEmailIdResult user in users)
                    {
                        firstNameTextBox.Text = user.FirstName;
                        lastNameTextBox.Text  = user.LastName;
                        zipTextBox.Text       = user.Zip;
                        phoneTextBox.Text     = user.Phone;
                        homeCourtDropDownList.SelectedValue = user.HomeCourt.ToString();
                        nTRPDropDownList.Text = user.NTRPRanking.ToString();
                        ageGroupDropDownList.SelectedValue     = user.AgeGroup;
                        racquetHandDropDownList.SelectedValue  = user.RacquetHand;
                        favoriteShotDropDownList.SelectedValue = user.FavoriteShot;
                        racquetTextBox.Text  = user.Racquet;
                        facebookTextBox.Text = user.Facebook;
                        linkedInTextBox.Text = user.LinkedIn;
                        mySpaceTextBox.Text  = user.MySpace;
                        orkutTextBox.Text    = user.Orkut;
                        if (user.ProfileImageName.HasValue)
                        {
                            profileImage.ImageUrl = string.Format("~/ProfileImages/{0}.jpg", user.ProfileImageName.ToString());
                        }
                        if (user.NextDivision.HasValue)
                        {
                            userNextDivision = user.NextDivision.Value;
                        }
                        if (user.EmailPost.HasValue)
                        {
                            postEmailCheckBox.Checked = user.EmailPost.Value;
                        }
                        playTypeDropDownList.SelectedValue = user.Interest;
                    }

                    //List<SelectDivisionByLeagueIdResult> selectDivisionByLeagueIdResult = dataContext.SelectDivisionByLeagueId(Convert.ToInt32(WebConfigurationManager.AppSettings["LeagueCityId"])).ToList();
                    //SelectDivisionByLeagueIdResult nextDivision = selectDivisionByLeagueIdResult.Find(p => p.DivisionId == selectDivisionByLeagueIdResult.Max(q => q.DivisionId));
                    List <SelectDivisionResult> selectDivisionResult = dataContext.SelectDivision(StoredData.User.NextDivision).ToList();
                    if (StoredData.User.Division != StoredData.User.NextDivision)
                    {
                        ViewState["NextDivision"]     = StoredData.User.NextDivision;
                        ViewState["NextDivisionText"] = selectDivisionResult[0].Division;
                        upcomingLeagueLabel.Text      = string.Format("{0} {1} - {2}", selectDivisionResult[0].Division, selectDivisionResult[0].StartDate.ToShortDateString(), selectDivisionResult[0].EndDate.ToShortDateString());
                        upcomingLeagueButton.Visible  = true;
                    }
                    else
                    {
                        upcomingLeagueLabel.Text = string.Format("You are currently subscribed to the {0} {1} - {2}", selectDivisionResult[0].Division, selectDivisionResult[0].StartDate.ToShortDateString(), selectDivisionResult[0].EndDate.ToShortDateString());
                    }
                }

                List <SelectProfileImageByEmailIdResult> selectProfileImageByEmailIdResult = dataContext.SelectProfileImageByEmailId(HttpContext.Current.User.Identity.Name).ToList();
                if (selectProfileImageByEmailIdResult.Count > 0)
                {
                    profileImage.ImageUrl = string.Format("~/ProfileImages/{0}.jpg", selectProfileImageByEmailIdResult[0].ProfileImageName.ToString());
                }
            }
        }
        protected void uploadButton_Click(object sender, EventArgs e)
        {
            if (RadUpload1.UploadedFiles.Count > 0)
            {
                string target = Server.MapPath("~/ProfileImages");
                System.Drawing.Image.GetThumbnailImageAbort thumbnailImageAbortDelegate =
                    new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
                Guid fileName = Guid.NewGuid();
                foreach (UploadedFile file in RadUpload1.UploadedFiles)
                {
                    file.SaveAs(string.Format("{0}//{1}", target, file.GetName()));
                    using (Bitmap originalImage = new Bitmap(file.InputStream))
                    {
                        //You can implement additional logic to compute
                        // the width / height according your requirements
                        //int width = originalImage.Width / 2;
                        double ratio  = Convert.ToDouble(originalImage.Width) / Convert.ToDouble(originalImage.Height);
                        int    width  = 160;
                        int    height = Convert.ToInt32(160 * (1 / ratio));
                        if (height > 160)
                        {
                            height = 160;
                            width  = Convert.ToInt32(160 * ratio);
                        }

                        System.Drawing.Image thumbnail = new Bitmap(width, height);
                        using (Graphics g = Graphics.FromImage(thumbnail))
                        {
                            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                            g.FillRectangle(Brushes.White, 0, 0, width, height);
                            g.DrawImage(originalImage, 0, 0, width, height);
                            string thumbnailFileName = string.Format("{0}//{1}.jpg", target, fileName.ToString());
                            thumbnail.Save(thumbnailFileName);
                        }
                    }

                    //Delete original Image
                    try
                    {
                        if (File.Exists(string.Format("{0}//{1}", target, file.GetName())))
                        {
                            File.Delete(string.Format("{0}//{1}", target, file.GetName()));
                        }
                    }
                    catch
                    {
                    }

                    using (FlexibleTennisLeagueDataContext dataContext = new FlexibleTennisLeagueDataContext())
                    {
                        ISingleResult <SelectUserByEmailIdResult> users = dataContext.SelectUserByEmailId(HttpContext.Current.User.Identity.Name);
                        foreach (SelectUserByEmailIdResult result in users)
                        {
                            if (result.ProfileImageName.HasValue)
                            {
                                try
                                {
                                    if (File.Exists(string.Format("{0}//{1}.jpg", target, result.ProfileImageName)))
                                    {
                                        File.Delete(string.Format("{0}//{1}.jpg", target, result.ProfileImageName));
                                    }
                                }
                                catch (IOException)
                                {
                                }
                            }
                        }
                        dataContext.UpdateUserProfileImage(HttpContext.Current.User.Identity.Name, fileName);
                        InjectScript.Text = "<script>RefreshParentPage();CloseOnReload()</" + "script>";
                    }
                }
            }
            else if (RadUpload1.InvalidFiles.Count > 0)
            {
                if (RadUpload1.InvalidFiles[0].ContentLength > 4)
                {
                    errorLabel.Text = "Image file size should be less than 4 MB.";
                }
            }
            else
            {
                errorLabel.Text = "Please select a valid image";
            }
        }