/// <summary>
        /// Deletes an account from the membership store and removes the
        /// account from the repository
        /// </summary>
        /// <param name="account">The <c>Account</c> to delete from the repository</param>
        /// <param name="identity">The <c>IIdentity</c> of the user authorized to
        /// delete the <c>Account</c> from the repository</param>
        /// <exception cref="SecurityException">Thrown if the user cannot properly be
        /// authenticated or the user is not authorized to delete the account from
        /// the repository</exception>
        public void DeleteAccount(AccountModels.Account account, IIdentity identity)
        {
            logger.EnterMethod("DeleteAccount");

            try
            {
                kernel.Get<Security>().AuthorizeAction(identity, account.Id);
            }
            catch (SecurityException exception)
            {
                logger.LogExceptionWithMessage(exception, "SecurityException thrown in DeleteAccount");
                throw;
            }

            try
            {
                accountRepository.Delete(account);

                Membership.DeleteUser(account.Name, true);
            }
            catch (ArgumentException exception)
            {
                logger.LogException(exception);
                throw;
            }

            logger.LeaveMethod("DeleteAccount");
        }
        /// <summary>
        /// Updates an account in the repository and the email addresss in the
        /// membership store
        /// </summary>
        /// <param name="account">The <c>Account</c> to update in the repository</param>
        /// <param name="identity">The <c>IIdentity</c> of the user authorized to
        /// update the <c>Account</c> in the repository</param>
        /// <exception cref="SecurityException">Thrown if the user cannot properly be
        /// authenticated or the user is not authorized to update the account in
        /// the repository</exception>
        public void UpdateAccount(AccountModels.Account account, IIdentity identity)
        {
            logger.EnterMethod("UpdateAccount");

            if (account == null)
            {
                throw new ArgumentNullException("account", "The account parameter cannot be null.");
            }

            try
            {
                kernel.Get<Security>().AuthorizeAction(identity, account.Id);
            }
            catch (SecurityException exception)
            {
                logger.LogExceptionWithMessage(exception, "SecurityException thrown in UpdateAccount");
                throw;
            }

            try
            {
                var membershipUser = Membership.GetUser(account.Name, false);

                // ReSharper disable PossibleNullReferenceException
                membershipUser.Email = account.EmailAddress;
                // ReSharper restore PossibleNullReferenceException
                Membership.UpdateUser(membershipUser);

                accountRepository.Update(account);
            }
            catch (ArgumentException exception)
            {
                logger.LogException(exception);
                throw;
            }

            logger.LeaveMethod("UpdateAccount");
        }
        /// <summary>
        /// Adds an account to the repository and creates a membership entry
        /// in the <c>IMembershipProvider</c> 
        /// </summary>
        /// <param name="account">The <c>Account</c> to add to the repository</param>
        /// <param name="password">The new account's password </param>
        /// <exception cref="ArgumentNullException">Thrown if the account parameter
        /// is null</exception>
        /// <exception cref="ArgumentNullException">Thrown if the account's Contacts
        /// property is null</exception>
        /// <exception cref="ArgumentException">Thrown if the password is null or
        /// empty string</exception>
        /// <exception cref="ArgumentException">Thrown if the account does not have
        /// exactly one contact that is designated as the primary and that contact
        /// does not have exactly one email address and one phone number that is 
        /// designated as primary</exception>
        /// <exception cref="SecurityException">Thrown if the user cannot properly be
        /// authenticated or the user is not authorized to add the address to the
        /// repository</exception>
        /// <exception cref="MembershipCreateUserException">The user was not created
        /// by the membership provider.</exception>
        public virtual void AddAccount(AccountModels.Account account, string password)
        {
            logger.EnterMethod("AddAccount");

            Invariant.IsNotNull(account, "account");
            Invariant.IsNotBlank(password, "password");

            try
            {
                var newUserAccount = Membership.CreateUser(account.Name, password, account.EmailAddress);

                // ReSharper disable PossibleNullReferenceException
                account.UserId = (Guid)newUserAccount.ProviderUserKey;
                // ReSharper restore PossibleNullReferenceException
                accountRepository.Add(account);
            }
            catch (MembershipCreateUserException exception)
            {
                var createErrorDescription = CreateMembershipStatusDescriptions.Status[exception.StatusCode];

                logger.LogExceptionWithMessage(exception, createErrorDescription);

                throw;
            }
            catch (ArgumentException exception)
            {
                logger.LogException(exception);
                throw;
            }

            logger.LeaveMethod("AddAccount");
        }