Exemple #1
0
        public async Task <OspApiScope> TryCreateApiScopeAsync(ApiScope apiScope)
        {
            var res = (await FindApiScopesByNameAsync(new[] { apiScope.Name })).ToArray();

            if (!res.Any())
            {
                var dbApiScope = new OspApiScope
                {
                    Description             = apiScope.Description,
                    Name                    = apiScope.Name,
                    Enabled                 = apiScope.Enabled,
                    DisplayName             = apiScope.DisplayName,
                    Emphasize               = apiScope.Emphasize,
                    Required                = apiScope.Required,
                    ShowInDiscoveryDocument = apiScope.ShowInDiscoveryDocument,
                    Properties              = new Dictionary <string, string>(apiScope.Properties),
                    UserClaims              = new List <string>(apiScope.UserClaims)
                };

                await CreateApiScopeAsync(dbApiScope);

                return(dbApiScope);
            }

            return((OspApiScope)res.First());
        }
Exemple #2
0
        public async Task CreateApiScopeAsync(OspApiScope apiScope)
        {
            ArgumentValidation.Validate(nameof(apiScope), apiScope);

            using (var session = await _repository.StartSessionAsync())
            {
                session.StartTransaction();

                await _apiScopeCollection.InsertAsync(session, apiScope);

                await session.CommitTransactionAsync();
            }
        }