/// <summary>
        /// Updates an <seealso cref="MedicalModels.MedicalAppointment"/> in the repository
        /// </summary>
        /// <param name="medicalAppointment">
        /// The <seealso cref="MedicalModels.MedicalAppointment"/> to update in the repository
        /// </param>
        /// <param name="identity">
        /// The <c>IIdentity</c> of the user authorized to update the 
        /// <seealso cref="MedicalModels.MedicalAppointment"/> in the repository
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the <paramref name="medicalAppointment"/> 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 medical appointment in
        /// the repository
        /// </exception>
        public void UpdateMedicalAppointment(MedicalModels.MedicalAppointment medicalAppointment, IIdentity identity)
        {
            logger.EnterMethod("UpdateMedicalAppointment");

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

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

            try
            {
                medicalAppointmentRepository.Update(medicalAppointment);
            }
            catch (ArgumentException exception)
            {
                logger.LogException(exception);
                throw;
            }

            logger.LeaveMethod("UpdateMedicalAppointment");
        }
        /// <summary>
        /// Updates a <seealso cref="MedicalModels.Facility"/> in the repository
        /// </summary>
        /// <param name="facility">
        /// The <seealso cref="MedicalModels.Facility"/> to update in the repository
        /// </param>
        /// <param name="identity">
        /// The <c>IIdentity</c> of the user authorized to update the 
        /// <seealso cref="MedicalModels.Facility"/> in the repository
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the <paramref name="facility"/> 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 <seealso cref="MedicalModels.Facility"/>
        /// in the repository
        /// </exception>
        public void UpdateFacility(MedicalModels.Facility facility, IIdentity identity)
        {
            logger.EnterMethod("UpdateFacility");

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

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

            try
            {
                facilityRepository.Update(facility);
            }
            catch (ArgumentException exception)
            {
                logger.LogException(exception);
                throw;
            }

            logger.LeaveMethod("UpdateFacility");
        }
        /// <summary>
        /// Updates an <seealso cref="MedicalModels.Provider"/> in the repository
        /// </summary>
        /// <param name="provider">
        /// The <seealso cref="MedicalModels.Provider"/> to update in the repository
        /// </param>
        /// <param name="identity">
        /// The <c>IIdentity</c> of the user authorized to update the 
        /// <seealso cref="MedicalModels.Provider"/> in the repository
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the <paramref name="provider"/> 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 provider in
        /// the repository
        /// </exception>
        public void UpdateProvider(MedicalModels.Provider provider, IIdentity identity)
        {
            logger.EnterMethod("UpdateProvider");

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

            try
            {
                var accountId =
                    kernel.Get<IReadOnlyRepository<MedicalModels.Facility>>().FindBy(
                        facility => facility.Id.Equals(provider.FacilityId)).AccountId;
                kernel.Get<Security>().AuthorizeAction(identity, accountId);
            }
            catch (SecurityException exception)
            {
                logger.LogExceptionWithMessage(exception, "SecurityException thrown in UpdateProvider");
                throw;
            }

            try
            {
                providerRequestRepository.Update(provider);
            }
            catch (ArgumentException exception)
            {
                logger.LogException(exception);
                throw;
            }

            logger.LeaveMethod("UpdateProvider");
        }
        /// <summary>
        /// Adds a <seealso cref="MedicalModels.Facility"/> to the repository
        /// </summary>
        /// <param name="facility">
        /// The <seealso cref="MedicalModels.Facility"/> to add.
        /// </param>
        /// <param name="identity">
        /// The identity of the user authorized to add the <seealso cref="MedicalModels.Facility"/>
        ///  to the account
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if the <paramref name="facility"/> 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 <seealso cref="MedicalModels.Facility"/>
        ///  to the account
        /// </exception>
        public void CreateFacility(MedicalModels.Facility facility, IIdentity identity)
        {
            logger.EnterMethod("CreateFacility");

            Invariant.IsNotNull(facility, "facility");
            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));

                facility.AccountId = userAccount.Id;
                facilityRepository.Add(facility);
            }
            catch (Exception exception)
            {
                logger.LogException(exception);
                throw;
            }

            logger.LeaveMethod("CreateFacility");
        }