/// <summary>
        /// Updates an insurer in the repository
        /// </summary>
        /// <param name="insurer">
        /// The <seealso cref="InsuranceModels.Insurer"/> to update in the repository
        /// </param>
        /// <param name="identity">
        /// The <c>IIdentity</c> of the user authorized to update the 
        /// <seealso cref="InsuranceModels.Insurer"/> in the repository
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the <paramref name="insurer"/> parameter is null
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the <paramref name="identity"/> parameter is null
        /// </exception>
        /// <exception cref="SecurityException">
        /// Thrown if the user is not authorized to update the insurer in
        /// the repository
        /// </exception>
        public void UpdateInsurer(InsuranceModels.Insurer insurer, IIdentity identity)
        {
            logger.EnterMethod("UpdateInsurer");

            Invariant.IsNotNull(insurer, "insurer");
            Invariant.IsNotNull(identity, "identity");

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

            try
            {
                insurerRepository.Update(insurer);
            }
            catch (ArgumentException exception)
            {
                logger.LogException(exception);
                throw;
            }

            logger.LeaveMethod("UpdateInsurer");
        }
        /// <summary>
        /// Adds an insurer to the repository
        /// </summary>
        /// <param name="insurer">
        /// The insurer to add.
        /// </param>
        /// <param name="identity">
        /// The identity of the user authorized to add the insurer to the insurer
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the <paramref name="insurer"/> parameter is null
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the <paramref name="identity"/> parameter is null
        /// </exception>
        /// <exception cref="SecurityException">
        /// Thrown if the user is not authorized to add the insurer to the
        /// repository
        /// </exception>
        public void CreateInsurer(InsuranceModels.Insurer insurer, IIdentity identity)
        {
            logger.EnterMethod("CreateInsurer");

            Invariant.IsNotNull(insurer, "insurer");
            Invariant.IsNotNull(identity, "identity");

            try
            {
                var user = Membership.GetUser(identity.Name, false);
                var accountReadRepository = kernel.Get<IReadOnlyRepository<AccountModels.Account>>();
                var userAccount = accountReadRepository.FindBy(account => account.UserId.Value.Equals((Guid)user.ProviderUserKey));

                insurer.AccountId = userAccount.Id;

                insurerRepository.Add(insurer);
            }
            catch (Exception exception)
            {
                logger.LogException(exception);
                throw;
            }

            logger.LeaveMethod("CreateInsurer");
        }
        /// <summary>
        /// Updates an <seealso cref="InsuranceModels.AuthorizationFollowUp"/> in the repository
        /// </summary>
        /// <param name="authorizationFollowUp">
        /// The <seealso cref="InsuranceModels.AuthorizationFollowUp"/> to update in the repository
        /// </param>
        /// <param name="identity">
        /// The <c>IIdentity</c> of the user authorized to update the 
        /// <seealso cref="InsuranceModels.AuthorizationFollowUp"/> in the repository
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the <paramref name="authorizationFollowUp"/> parameter is null
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the <paramref name="identity"/> parameter is null
        /// </exception>
        /// <exception cref="SecurityException">
        /// Thrown if the user is not authorized to update the authorization follow up in
        /// the repository
        /// </exception>
        public void UpdateAuthorizationFollowUp(InsuranceModels.AuthorizationFollowUp authorizationFollowUp, IIdentity identity)
        {
            logger.EnterMethod("UpdateAuthorizationFollowUp");

            Invariant.IsNotNull(authorizationFollowUp, "authorizationFollowUp");
            Invariant.IsNotNull(identity, "identity");

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

            try
            {
                authorizationFollowUpRepository.Update(authorizationFollowUp);
            }
            catch (ArgumentException exception)
            {
                logger.LogException(exception);
                throw;
            }

            logger.LeaveMethod("UpdateAuthorizationFollowUp");
        }
        /// <summary>
        /// Updates an <seealso cref="InsuranceModels.AuthorizationNote"/> in the repository
        /// </summary>
        /// <param name="authorizationNote">
        /// The <seealso cref="InsuranceModels.AuthorizationNote"/> to update in the repository
        /// </param>
        /// <param name="identity">
        /// The <c>IIdentity</c> of the user authorized to update the 
        /// <seealso cref="InsuranceModels.AuthorizationNote"/> in the repository
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the <paramref name="authorizationNote"/> parameter is null
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the <paramref name="identity"/> parameter is null
        /// </exception>
        /// <exception cref="SecurityException">
        /// Thrown if the user is not authorized to update the authorization note in
        /// the repository
        /// </exception>
        public void UpdateAuthorizationNote(InsuranceModels.AuthorizationNote authorizationNote, IIdentity identity)
        {
            logger.EnterMethod("UpdateAuthorizationNote");

            Invariant.IsNotNull(authorizationNote, "authorizationNote");
            Invariant.IsNotNull(identity, "identity");

            try
            {
                var accountId =
                    kernel.Get<IReadOnlyRepository<InsuranceModels.AuthorizationRequest>>().FindBy(
                        request => request.Id.Equals(authorizationNote.AuthorizationRequestId)).AccountId;

                kernel.Get<Security>().AuthorizeAction(identity, accountId);
            }
            catch (SecurityException exception)
            {
                logger.LogExceptionWithMessage(exception, "SecurityException thrown in UpdateAuthorizationNote");
                throw;
            }

            try
            {
                this.authorizationNoteRepository.Update(authorizationNote);
            }
            catch (ArgumentException exception)
            {
                logger.LogException(exception);
                throw;
            }

            logger.LeaveMethod("UpdateAuthorizationNote");
        }
        /// <summary>
        /// Deletes an <seealso cref="InsuranceModels.AuthorizationRequest"/> from the repository
        /// </summary>
        /// <param name="authorizationRequest">
        /// The <seealso cref="InsuranceModels.AuthorizationRequest"/> to delete from the repository
        /// </param>
        /// <param name="identity">
        /// The <c>IIdentity</c> of the user authorized to delete the 
        /// <seealso cref="InsuranceModels.AuthorizationRequest"/> from the repository
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the <paramref name="authorizationRequest"/> parameter is null
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the <paramref name="identity"/> parameter is null
        /// </exception>
        /// <exception cref="SecurityException">
        /// Thrown if the user is not authorized to delete the authorization request from the repository
        /// </exception>
        public void DeleteAuthorizationRequest(InsuranceModels.AuthorizationRequest authorizationRequest, IIdentity identity)
        {
            logger.EnterMethod("DeleteAuthorizationRequest");

            Invariant.IsNotNull(authorizationRequest, "authorizationRequest");
            Invariant.IsNotNull(identity, "identity");

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

            try
            {
                authorizationRequestRepository.Delete(authorizationRequest);
            }
            catch (ArgumentException exception)
            {
                logger.LogException(exception);
                throw;
            }

            logger.LeaveMethod("DeleteAuthorizationRequest");
        }