public Member AddMember(Member member)
        {
            using (context = new DomainContext())
            {
                context.Members.Add(member);
                context.SaveChanges();
            }

            return member;
        }
        public Member ConfirmRegistration(Member member)
        {
            using (context = new DomainContext())
            {
                var memberIdVariable = "@memberId";
                var tokenVariable = "@token";
                var membershipDateVariable = "@membershipDate";

                var command = string.Format("exec ConfirmRegistration {0}, {1}, {2}",
                                            memberIdVariable,
                                            tokenVariable,
                                            membershipDateVariable);

                var memberId = new SqlParameter(memberIdVariable, member.Id);
                var token = new SqlParameter(tokenVariable, member.Tokens.ElementAt(0).Token);
                var membershipDate = new SqlParameter(membershipDateVariable, member.MembershipDate);

                context.Database.ExecuteSqlCommand(command, memberId, token, membershipDate);
            }

            return member;
        }
        public Member GetMember(string email)
        {
            Member member = null;

            using (context = new DomainContext())
            {
                context.Configuration.LazyLoadingEnabled = false;

                var result = context.Members
                                    .Include("Security")
                                    .Include("Profile")
                                    .Where(m => string.Compare(m.Email, email, true) == 0)
                                    .FirstOrDefault();

                if (result == null)
                {
                    member = new Member();
                    member.Security = new MemberPassword();
                }
                else
                {
                    member = result;
                }
            }

            return member;
        }
        public Member ReRegisterMember(Member member)
        {
            using (context = new DomainContext())
            {
                var memberIdVariable = "@memberId";
                var aliasVariable = "@alias";
                var saltValueVariable = "@saltValue";
                var passwordVariable = "@password";

                var command = string.Format("exec ReRegisterMember {0}, {1}, {2}, {3}",
                                            memberIdVariable,
                                            aliasVariable,
                                            saltValueVariable,
                                            passwordVariable);

                var memberId = new SqlParameter(memberIdVariable, member.Id);
                var alias = new SqlParameter(aliasVariable, member.Profile.Alias);
                var saltValue = new SqlParameter(saltValueVariable, member.Security.SaltValue);
                var password = new SqlParameter(passwordVariable, member.Security.Password);

                context.Database.ExecuteSqlCommand(command, memberId, alias, saltValue, password);
            }

            return member;
        }
        public Member GetMember(Guid token)
        {
            Member member = null;

            using (context = new DomainContext())
            {
                context.Configuration.LazyLoadingEnabled = false;

                var result = context.MemberTokens
                                    .Include("Member")
                                    .Include("Profile")
                                    .Where(mt => mt.Token == token)
                                    .FirstOrDefault();

                if (result == null)
                {
                    member = new Member();
                }
                else
                {
                    member = result.Member;
                }
            }

            return member;
        }
        public Member GetMember(int id)
        {
            Member member = null;

            using (context = new DomainContext())
            {
                context.Configuration.LazyLoadingEnabled = false;

                var result = context.Members
                                    .Include("Security")
                                    .Include("Profile")
                                    .Where(m => m.Id == id)
                                    .FirstOrDefault();

                if (result == null)
                {
                    member = new Member();
                }
                else
                {
                    member = result;
                }
            }

            return member;
        }