Пример #1
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            lblPicCheckType.Visible = false;
            lblPicCheckSize.Visible = false;
            byte[] imageBytes;
            Expert expertProfileObj = (Expert)Session["expertProfileObj"];
            string username = expertProfileObj.username;
            int count = Convert.ToInt32(DbMethods.CheckIfUsernameExists(txtUsername.Text));
            if (count >= 1 && txtUsername.Text != username)
            {
                lblUsernameCheck.Visible = true;
            }
            else if (vlad.IsBlank(txtFirstName.Text) || vlad.IsBlank(txtLastName.Text) || vlad.IsBlank(txtEmail.Text) || vlad.IsBlank(txtUsername.Text) || vlad.IsBlank(txtEmail.Text))
            {
                lblRequired.Visible = true;
            }
            else
            {
                string fileExtension = Path.GetExtension(fileNew1.PostedFile.FileName);//uploaded file extension
                int iFileSize = fileNew1.PostedFile.ContentLength;//uploaded file size
                
                if (fileNew1.FileContent != null && fileNew1.HasFile == true)
                {//if you have a file in the file upload control
                    if (vlad.TestForLegalImageTypes(fileExtension) == false)
                    {//fail
                        lblPicCheckType.Visible = true;
                        lblPicCheckType.Text = fileExtension + " file extension is not allowed. Please use .png, .gif, .jpg, .jpeg, .pdf, .pcd, .fpx, .tif instead";
                    }
                    else if(iFileSize >= 90000)
                    {//fail
                        lblPicCheckSize.Visible = true;
                        lblPicCheckSize.Text = "Your file size is "+ iFileSize+" bytes. Please reduce the size to less than 90 KB (90000 bytes).";
                    }
                    else
                    {
                        MemoryStream ms = new MemoryStream();
                        var img = System.Drawing.Image.FromStream(fileNew1.FileContent);
                        img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                        imageBytes = ms.ToArray();
                        Session.Add("picture", imageBytes);

                        Expert updatedExpert = new Expert
                        {
                            firstName = txtFirstName.Text,
                            lastName = txtLastName.Text,
                            username = txtUsername.Text,
                            email = txtEmail.Text,
                            phoneNumber = txtPhoneNumber.Text,
                            linkedIn = txtLinkedIn.Text,
                            aboutMe = aboutMe.Text,
                            picture = imageBytes,
                            skillGroupID = Convert.ToInt32(SkillGroupDropdown.SelectedItem.Value)
                        };
                        int x = DbMethods.UpdateExpert(updatedExpert, (string)Session["TU_ID"]);
                        sm.storeExpertDataInSession();
                        FillControls();
                        Response.Redirect("ExpertPage.aspx?username="******"TU_ID"]);
                    sm.storeExpertDataInSession();
                    FillControls();
                    Response.Redirect("ExpertPage.aspx?username=" + updatedExpert.username);
                }
            }
            
        }