Example #1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            UserProfileInfo objinfo     = new UserProfileInfo();
            string          filename    = "";
            string          thumbTarget = Server.MapPath("~/Modules/Admin/UserManagement/UserPic");
            if (!Directory.Exists(thumbTarget))
            {
                Directory.CreateDirectory(thumbTarget);
            }
            System.Drawing.Image.GetThumbnailImageAbort thumbnailImageAbortDelegate = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
            if (fuImage.HasFile)
            {
                string   fName = fuImage.PostedFile.FileName;
                FileInfo fi    = new FileInfo(fName);
                fName = Path.GetFileName(fName);
                string ext = fi.Extension.ToLower();
                if (ext == ".jpeg" || ext == ".jpg" || ext == ".png")
                {
                    double fs = fuImage.PostedFile.ContentLength / (1024 * 1024);
                    if (fs > 3)
                    {
                        ShowHideProfile();
                        ShowMessage("", GetSageMessage("UserManagement", "ImageTooLarge"), "", SageMessageType.Alert);
                        return;
                    }
                    else
                    {
                        Random ran  = new Random();
                        int    rand = ran.Next(1111111, 9999999);
                        if (!File.Exists(Server.MapPath("~/Modules/Admin/UserManagement/UserPic/" + fName)))
                        {
                            string fullfileName = Path.GetFileNameWithoutExtension(fName) + rand + ext;
                            Session[SessionKeys.Profile_Image] = fullfileName;
                            imgUser.ImageUrl = "~/Modules/Admin/UserManagement/UserPic/" + fullfileName;
                            using (
                                System.Drawing.Bitmap originalImage =
                                    new System.Drawing.Bitmap(fuImage.PostedFile.InputStream))
                            {
                                using (
                                    System.Drawing.Image thumbnail = originalImage.GetThumbnailImage(200, 150,
                                                                                                     thumbnailImageAbortDelegate,
                                                                                                     IntPtr.Zero))
                                {
                                    thumbnail.Save(System.IO.Path.Combine(thumbTarget, fullfileName));
                                }
                            }
                        }
                    }
                }
                else
                {
                    {
                        ShowHideProfile();
                        ShowMessage("", GetSageMessage("UserManagement", "InvalidImageFormat"), "", SageMessageType.Error);
                        return;
                    }
                }
            }

            if (filename == "")
            {
                if (Session[SessionKeys.Profile_Image] != null)
                {
                    filename = Session[SessionKeys.Profile_Image].ToString();
                }
                btnDeleteProfilePic.Visible = false;
            }
            else
            {
                btnDeleteProfilePic.Visible = true;
            }
            objinfo.Image       = filename;
            objinfo.UserName    = GetUsername;
            objinfo.FirstName   = txtFName.Text;
            objinfo.LastName    = txtLName.Text;
            objinfo.FullName    = txtFullName.Text;
            objinfo.Location    = txtLocation.Text;
            objinfo.AboutYou    = txtAboutYou.Text;
            objinfo.Email       = txtEmail1.Text + (txtEmail2.Text != "" ? "," + txtEmail2.Text : "") + (txtEmail3.Text != "" ? ',' + txtEmail3.Text : "");
            objinfo.ResPhone    = txtResPhone.Text;
            objinfo.MobilePhone = txtMobile.Text;
            objinfo.Others      = txtOthers.Text;
            objinfo.AddedOn     = DateTime.Now;
            objinfo.AddedBy     = GetUsername;
            objinfo.UpdatedOn   = DateTime.Now;
            objinfo.PortalID    = GetPortalID;
            objinfo.UpdatedBy   = GetUsername;
            objinfo.BirthDate   = txtBirthDate.Text == string.Empty ? DateTime.Parse(falseDate) : DateTime.Parse(txtBirthDate.Text);
            objinfo.Gender      = rdbGender.SelectedIndex;
            UserProfileController.AddUpdateProfile(objinfo);
            LoadUserDetails();
            divUserInfo.Visible                = true;
            tblEditProfile.Visible             = false;
            tblViewProfile.Visible             = true;
            imgProfileEdit.Visible             = false;
            imgProfileView.Visible             = true;
            btnDeleteProfilePic.Visible        = false;
            divEditprofile.Visible             = true;
            sfUserProfile.Visible              = false;
            Session[SessionKeys.Profile_Image] = null;
            ShowMessage("", GetSageMessage("UserManagement", "UserProfileSavedSuccessfully"), "", SageMessageType.Success);
        }
        catch (Exception ex)
        {
            ProcessException(ex);
        }
    }