/// <summary>
        /// Delete an api usage record
        /// </summary>
        /// <param name="api">ApiAuthentication</param>
        public void DeleteApiUsage(ApiAuthentication api)
        {
            if (api == null)
                throw new ArgumentNullException("api");

            if (api.Deleted)
                return;

            _apiAuthenticationRepository.Delete(api);
        }
        public static ApiAuthentication ToEntity(this ApiAuthenticationModel model)
        {
            if (model == null)
                return null;

            var encryptionService = EngineContext.Current.Resolve<IEncryptionService>();

            var entity = new ApiAuthentication
            {
                Active = model.Active,
                CreatedDate = model.CreatedDate,
                Deleted = model.Deleted,
                Id = model.Id,
                LastModifiedBy = model.LastModifiedBy,
                LastModifiedDate = model.LastModifiedDate,
                NameOfApplication = model.NameOfApplication,
                ApiUser = model.ApiUser.ToEntity(),
                Description = model.Description,
                SecretKey = encryptionService.CreateSaltKey(6),
                WebsiteAddress = model.WebsiteAddress
            };

            return entity;
        }
        /// <summary>
        /// Insert an api usage record
        /// </summary>
        /// <param name="api">ApiAuthentication</param>
        public void InsertApiUsage(ApiAuthentication api)
        {
            if (api == null)
                throw new ArgumentNullException("api");

            api.LastModifiedBy = api.ApiUser.Id;
            api.CreatedDate = DateTime.Now;
            api.LastModifiedDate = DateTime.Now;
            api.Active = true;

            _apiAuthenticationRepository.Insert(api);

            api.AccessToken = _encryptionService.EncryptText(api.SecretKey + api.WebsiteAddress);
        }
        /// <summary>
        /// Updates an api usage record
        /// </summary>
        /// <param name="api">ApiAuthentication</param>
        public void UpdateApiUsage(ApiAuthentication api)
        {
            if (api == null)
                throw new ArgumentNullException("api");

            api.LastModifiedDate = DateTime.Now;
            _apiAuthenticationRepository.Update(api);
            api.AccessToken = _encryptionService.EncryptText(api.SecretKey + api.WebsiteAddress);
        }