protected void btnSubmitProfile_Click(object sender, EventArgs e)
    {
        try
        {
            using (DIYPTEntities db = new DIYPTEntities())
            {
                try
                {
                    PrizeMember memberUpdating = (from c in db.PrizeMembers
                                                  where c.UmbracoId == member.UmbracoId
                                                  select c).FirstOrDefault();
                    memberUpdating.Firstname = tbFirstName.Text;
                    memberUpdating.Surname   = tbLastName.Text;
                    memberUpdating.WhyDIYPT  = tbWhyDiypt.Text;
                    memberUpdating.Facebook  = tbFacebook.Text;
                    memberUpdating.Instagram = tbInstagram.Text;
                    memberUpdating.Twiter    = tbTwitter.Text;

                    /*
                     * string s = null;
                     * if (memberUpdating.UserSettings != null)
                     * s = string.Copy(memberUpdating.UserSettings);
                     * if (cbShowProgram.Checked == true)
                     * PrizeMemberAuthUtils.SetMemberSetting(ref s, PrizeConstants.MemberSettings.ShowProgram, '1');
                     * else
                     * PrizeMemberAuthUtils.SetMemberSetting(ref s, PrizeConstants.MemberSettings.ShowProgram, '0');
                     *
                     * if (cbShowLevel.Checked == true)
                     * PrizeMemberAuthUtils.SetMemberSetting(ref s, PrizeConstants.MemberSettings.ShowLevel, '1');
                     * else
                     * PrizeMemberAuthUtils.SetMemberSetting(ref s, PrizeConstants.MemberSettings.ShowLevel, '0');
                     * memberUpdating.UserSettings = s;
                     */
                    // db.PrizeMembers(member);

                    //photoUpload
                    if (photoUpload != null && !string.IsNullOrEmpty(photoUpload.FileName))
                    {
                        string attachmentServerPath = "";
                        string sSuffix         = photoUpload.FileName.Substring(photoUpload.FileName.Length - 4);
                        string sServerFileName = memberUpdating.UmbracoId + "_" + PrizeCommonUtils.ParseDateTimeSimple(DateTime.Now) + "_" + sSuffix;

                        string uploadPath = HttpContext.Current.Server.MapPath("~/member_images");
                        //@"C:\workspace\asp_project\diypt.club\home\member_images";
                        attachmentServerPath = String.Format(@"http://{0}/member_images/{1}", HttpContext.Current.Request.Url.Authority, sServerFileName);
                        decimal attachmentFileSize = Math.Round(Convert.ToDecimal(photoUpload.PostedFile.ContentLength / 1024), 2);

                        //if (attachmentFileSize + Helper.GetTrialTotalAttachmentSize(TrialId) < Convert.ToDecimal(ConfigurationManager.AppSettings["TotalAttachmentSizeLimit"]))
                        if (attachmentFileSize < 15000)
                        {
                            string[] dirs         = Directory.GetFiles(uploadPath);
                            string   folderPath   = String.Format(@"\{0}", sServerFileName);
                            string   fullFilePath = uploadPath + folderPath;

                            photoUpload.SaveAs(fullFilePath);
                            memberUpdating.Photo = attachmentServerPath;
                        }
                    }
                    char cc = '1';
                    if (!cbPromotionalPhoto.Checked)
                    {
                        cc = '0';
                    }
                    string s = string.Copy(memberUpdating.UserSettings);
                    PrizeMemberAuthUtils.SetMemberSetting(ref s, PrizeConstants.MemberSettings.PromotionalPhoto, cc);
                    memberUpdating.UserSettings = s;
                    db.SaveChanges();
                }
                finally
                {
                    db.Database.Connection.Close();
                    divViewProfile.Visible = true;
                    divEditProfile.Visible = false;
                    DisableValidatorsControls();
                    member = PrizeMemberAuthUtils.GetMemberData();
                    LoadMemberDetails();
                }
            }
        }
        catch (MembershipCreateUserException me)
        {
            lblMsg.Text    = GetErrorMessage(me.StatusCode);
            lblMsgTop.Text = lblMsg.Text;
        }
        catch (HttpException httpe)
        {
            lblMsg.Text    = httpe.Message;
            lblMsgTop.Text = lblMsg.Text;
        }
    }
Exemple #2
0
    protected string UpdateMemberPlanWeekPhoto(MemberExercisePlanWeek memberPlanWeek, FileUpload loader, int iType = 0)
    {
        FileUpload tempFileupload       = loader;
        string     sPhotoTypeName       = "";
        string     attachmentServerPath = "";

        if (iType == 0)
        {
            sPhotoTypeName = "front";
        }
        if (iType == 1)
        {
            sPhotoTypeName = "side";
        }
        if (iType == 2)
        {
            sPhotoTypeName = "back";
        }

        string sSuffix         = Path.GetExtension(tempFileupload.FileName);
        string sServerFileName = memberPlanWeek.MemberId + "_" + PrizeCommonUtils.ParseDateTimeSimple(memberPlanWeek.StartDate) + "_" + sPhotoTypeName + sSuffix;

        if (tempFileupload != null && !string.IsNullOrEmpty(tempFileupload.FileName))
        {
            string uploadPath = @"d:\sites\jrguico\diypt.com.au\home\member_images";
            //string uploadPath = @"C:\workspace\asp_project\diypt.club\home\member_images";
            attachmentServerPath = String.Format(@"http://{0}/member_images/{1}", HttpContext.Current.Request.Url.Authority, sServerFileName);
            decimal attachmentFileSize = Math.Round(Convert.ToDecimal(tempFileupload.PostedFile.ContentLength / 1024), 2);

            //if (attachmentFileSize + Helper.GetTrialTotalAttachmentSize(TrialId) < Convert.ToDecimal(ConfigurationManager.AppSettings["TotalAttachmentSizeLimit"]))
            if (attachmentFileSize < 15000)
            {
                string[] dirs         = Directory.GetFiles(uploadPath);
                string   folderPath   = String.Format(@"\{0}", sServerFileName);
                string   fullFilePath = uploadPath + folderPath;

                tempFileupload.SaveAs(fullFilePath);
                ImageHelper.RotateImageByExifOrientationData(fullFilePath, fullFilePath, System.Drawing.Imaging.ImageFormat.Jpeg, true);
                using (DIYPTEntities db = new DIYPTEntities())
                {
                    MemberPlanWeekResult weekResult = (from c in db.MemberPlanWeekResults
                                                       where c.MemberExercisePlanWeekId == memberPlanWeek.Id
                                                       select c).FirstOrDefault();
                    if (weekResult != null)
                    {
                        switch (iType)
                        {
                        case 0:
                            weekResult.FrontPhoto = attachmentServerPath;
                            break;

                        case 1:
                            weekResult.SidePhoto = attachmentServerPath;
                            break;

                        case 2:
                            weekResult.BackPhoto = attachmentServerPath;
                            break;

                        default:
                            break;
                        }
                        db.SaveChanges();
                    }
                }
            }
            else
            {
                Response.Write("<script>alert('You cannot attach this file. The maximum file size limit is 15mb.');</script>");
                return("");
            }
        }
        else
        {
            Response.Write("<script>alert('Please choose a file to attach.');</script>");
        }

        WeekResults = dbAccess.GetMemberPlanResults(_MemberPlanWeek.MemberExercisePlanId);

        return(attachmentServerPath);
    }