예제 #1
0
        public async Task AddProviderPermission(UpdatedPermissionsEvent updateEvent)
        {
            try
            {
                var permission = Map(updateEvent);

                await _permissionRepository.Add(permission);

                if (!permission.CanCreateCohort)
                {
                    await _reservationService.DeleteProviderFromSearchIndex(
                        Convert.ToUInt32(permission.ProviderId),
                        permission.AccountLegalEntityId);
                }
                else
                {
                    await _reservationService.AddProviderToSearchIndex(
                        (uint)permission.ProviderId,
                        permission.AccountLegalEntityId);
                }
            }
            catch (DbUpdateException e)
            {
                if (e.GetBaseException() is SqlException sqlException &&
                    (sqlException.Number == UniqueConstraintViolation ||
                     sqlException.Number == UniqueKeyViolation))
                {
                    _logger.LogWarning(
                        $"ProviderPermissionService: Rolling back adding permission for ProviderId:[{updateEvent.Ukprn}], AccountLegalEntityId:[{updateEvent.AccountLegalEntityId}] - item already exists.");
                }
            }
            catch (Exception ex)
            {
                _logger.LogWarning($"Error updating index for ProviderId:[{updateEvent.Ukprn}], AccountLegalEntityId:[{updateEvent.AccountLegalEntityId}]", ex);
            }
        }