public IHttpActionResult UpdateProfile(ProfileUpdateRequest request)
        {
            var response = new ProfileUpdateResponse();

            try
            {
                var isValidRequest = false;
                var emailChanged = false;

                var memberId = request.GetMemberId();

                var member = MembershipAdapter.GetMember(memberId);

                if (request.IsValidModel())
                {
                    if (member.Exists())
                    {
                        if (member.ConfirmedRegistration())
                        {
                            if (memberId == member.Id)
                            {
                                isValidRequest = true;
                                emailChanged = !string.Equals(request.Email, member.Email, StringComparison.InvariantCultureIgnoreCase);
                            }
                        }
                    }
                }

                if (isValidRequest)
                {
                    var memberProfile = new MemberProfile
                    {
                        MemberId = member.Id,
                        TimeZoneId = request.TimeZoneId,
                        Alias = request.Alias,
                        Gender = request.Gender,
                        BirthDate = request.BirthDate
                    };

                    memberProfile = MembershipAdapter.UpdateProfile(memberProfile);

                    if (emailChanged)
                    {
                        var memberEmailChange = MembershipAdapter.GetMemberEmailChange(member.Id);

                        if (memberEmailChange.Exists())
                        {
                            if (!string.Equals(memberEmailChange.Email, request.Email, StringComparison.InvariantCultureIgnoreCase))
                            {
                                memberEmailChange.Email = request.Email;

                                MembershipAdapter.UpdateEmailChange(memberEmailChange);
                            }
                        }
                        else
                        {
                            memberEmailChange.MemberId = member.Id;
                            memberEmailChange.Email = request.Email;

                            MembershipAdapter.CreateEmailChange(memberEmailChange);
                        }

                        var memberTokens = MembershipAdapter.GetMemberTokens(member.Id, TokenTypes.EmailChange, true);

                        var memberToken = new MemberToken();

                        memberToken.MemberId = member.Id;
                        memberToken.TokenType = TokenTypes.EmailChange;
                        memberToken.RequestDate = DateTime.Now.ToUniversalTime();

                        if (memberTokens.Any())
                        {
                            memberToken.Token = memberTokens.ElementAt(0).Token;
                            memberToken = MembershipAdapter.UpdateToken(memberToken);
                        }
                        else
                        {
                            memberToken.Token = Guid.NewGuid();
                            memberToken = MembershipAdapter.CreateToken(memberToken);
                        }

                        var email = new EmailChangeEmail
                        {
                            DomainName = ConfigHelper.DomainName,
                            DomainBaseUrl = ConfigHelper.DomainBaseUrl,
                            Alias = request.Alias,
                            ConfirmationToken = memberToken.Token
                        };

                        var emailBuilder = new EmailBuilder(EmailReference.HTML.Templates.Main, EmailReference.HTML.Contents.EmailChange);
                        var emailBody = emailBuilder.BuildBody<EmailChangeEmail>(email);
                        var emailResult = EmailHelper.SendEmail(ConfigHelper.NoReplayEmailAddress,
                                                                ConfigHelper.DomainName,
                                                                request.Email,
                                                                member.Profile.Alias,
                                                                email.Subject,
                                                                emailBody,
                                                                true);
                    }

                    response.IsSuccessful = true;
                    response.StatusMessage = "Update profile succeeded";
                }
                else
                {
                    response.IsSuccessful = false;
                    response.StatusMessage = "Update profile was unsuccessful";
                    response.Errors.AddRange(request.GetErrors());
                }
            }
            catch (Exception ex)
            {
                this.Log<ProfileUpdateRequest>(LogCategories.Error, request, ex.Message);

                response.IsSuccessful = false;
                response.StatusMessage = this.StatusMessageForExpection;
                response.Errors.Add(ex.Message);
            }

            return Ok(response);
        }
        public MemberProfile UpdateProfile(MemberProfile memberProfile)
        {
            using (context = new DomainContext())
            {
                var memberIdVariable = "@memberId";
                var timeZoneIdVariable = "@timeZoneId";
                var aliasVariable = "@alias";
                var genderVariable = "@gender";
                var birthDateVariable = "@birthDate";

                var command = string.Format("exec UpdateProfile {0}, {1}, {2}, {3}, {4}",
                                            memberIdVariable,
                                            timeZoneIdVariable,
                                            aliasVariable,
                                            genderVariable,
                                            birthDateVariable);

                var memberId = new SqlParameter(memberIdVariable, memberProfile.MemberId);
                var timeZondeId = new SqlParameter(timeZoneIdVariable, memberProfile.TimeZoneId);
                var alias = new SqlParameter(aliasVariable, memberProfile.Alias);
                var gender = new SqlParameter(genderVariable, memberProfile.Gender);
                var birthDate = new SqlParameter(birthDateVariable, memberProfile.BirthDate);

                context.Database.ExecuteSqlCommand(command, memberId, timeZondeId, alias, gender, birthDate);
            }

            return memberProfile;
        }