public async Task <IActionResult> AddUser(string key, [FromBody] AddUserToCollectionRequest request) { try { var userKey = _contextAccessor.UserKeyFromContext(); bool userCanAccessCollection = await UserCanAccessCollection(userKey, key, _hiarcDatabase, AccessLevelGroup.ReadWriteOrHigher); if (userCanAccessCollection) { await _hiarcDatabase.AddUserToCollection(key, request); return(Ok(new Empty())); } else { return(StatusCode(StatusCodes.Status403Forbidden)); } } catch (InvalidOperationException ex) { _logger.LogError(ex.Message); return(StatusCode(StatusCodes.Status403Forbidden)); } catch (Exception ex) { return(BuildErrorResponse(ex, _logger)); } }