public async Task <Permission> Add(Permission model)
        {
            var entity = model.ToEntity();

            entity.PermissionId  = Guid.NewGuid();
            entity.SecurableItem =
                _authorizationDbContext.SecurableItems.First(s => !s.IsDeleted && s.Name == model.SecurableItem);
            _authorizationDbContext.Permissions.Add(entity);
            await _authorizationDbContext.SaveChangesAsync();

            return(entity.ToModel());
        }
        public async Task <Permission> Add(Permission permission)
        {
            permission.Id = Guid.NewGuid();
            var permissionEntity = permission.ToEntity();

            permissionEntity.SecurableItem =
                AuthorizationDbContext.SecurableItems.First(s => !s.IsDeleted && s.Name == permission.SecurableItem);

            AuthorizationDbContext.Permissions.Add(permissionEntity);

            await AuthorizationDbContext.SaveChangesAsync();

            await EventService.RaiseEventAsync(new EntityAuditEvent <Permission>(EventTypes.EntityCreatedEvent, permission.Id.ToString(), permissionEntity.ToModel()));

            return(permissionEntity.ToModel());
        }
        public async Task Update(Permission model)
        {
            var permission = await _authorizationDbContext.Permissions
                             .SingleOrDefaultAsync(p =>
                                                   p.PermissionId == model.Id &&
                                                   !p.IsDeleted);

            if (permission == null)
            {
                throw new NotFoundException <Permission>($"Could not find {typeof(Permission).Name} entity with ID {model.Id}");
            }

            model.ToEntity(permission);
            _authorizationDbContext.Permissions.Update(permission);
            await _authorizationDbContext.SaveChangesAsync();
        }
        public async Task Update(Permission permission)
        {
            var permissionEntity = await AuthorizationDbContext.Permissions
                                   .SingleOrDefaultAsync(p =>
                                                         p.PermissionId == permission.Id &&
                                                         !p.IsDeleted);

            if (permissionEntity == null)
            {
                throw new NotFoundException <Permission>(
                          $"Could not find {typeof(Permission).Name} entity with ID {permission.Id}");
            }

            permission.ToEntity(permissionEntity);
            AuthorizationDbContext.Permissions.Update(permissionEntity);
            await AuthorizationDbContext.SaveChangesAsync();

            await EventService.RaiseEventAsync(new EntityAuditEvent <Permission>(EventTypes.EntityUpdatedEvent, permission.Id.ToString(), permissionEntity.ToModel()));
        }