Esempio n. 1
0
        public async Task <PageResult <HeaderDoc <UserRoleDoc> > > List(IWorkContext context, PageRequest pageRequest)
        {
            Verify.IsNotNull(nameof(context), context);
            Verify.IsNotNull(nameof(pageRequest), pageRequest);
            context = context.WithTag(_tag);

            var options = new driver.FindOptions <HeaderDoc <UserRoleDoc> >
            {
                Limit      = pageRequest.Limit,
                Projection = "{'_id': 0}"
            };

            IEnumerable <HeaderDoc <UserRoleDoc> > result;

            if (pageRequest.Index.IsEmpty())
            {
                result = await _collection.Find(context, new BsonDocument(), options);
            }
            else
            {
                var query = new And()
                            + (new Field(HeaderDoc.FieldName(nameof(UserRoleDoc.RoleId))) > pageRequest.Index);

                result = await _collection.Find(context, query.ToDocument(), options).ConfigureAwait(false);
            }

            return(new PageResult <HeaderDoc <UserRoleDoc> >(result.LastOrDefault()?.Payload?.RoleId, result));
        }
Esempio n. 2
0
        public Task <int> Delete(IWorkContext context, string roleId, string eTag = null)
        {
            Verify.IsNotNull(nameof(context), context);
            Verify.IsNotEmpty(nameof(roleId), roleId);
            context = context.WithTag(_tag);

            var query = new And()
                        + (new Field(HeaderDoc.FieldName(nameof(UserRoleDoc.RoleId))) == roleId);

            if (eTag.IsNotEmpty())
            {
                query += (new Field(nameof(HeaderDoc <UserRoleDoc> .ETag)) == eTag);
            }

            return(_collection.Delete(context, query.ToDocument()));
        }
Esempio n. 3
0
        public Task <int> Delete(IWorkContext context, string userName, string eTag = null)
        {
            Verify.IsNotNull(nameof(context), context);
            Verify.IsNotEmpty(nameof(userName), userName);
            context = context.WithTag(_tag);

            var query = new And()
                        + (new Field(HeaderDoc.FieldName(nameof(UserDoc.NormalizedUserName))) == userName.ToLowerInvariant());

            if (eTag.IsNotEmpty())
            {
                query += (new Field(nameof(HeaderDoc <UserDoc> .ETag)) == eTag);
            }

            return(_collection.Delete(context, query.ToDocument()));
        }
Esempio n. 4
0
        public async Task <HeaderDoc <UserRoleDoc> > Get(IWorkContext context)
        {
            if (_cache.TryGetValue(out HeaderDoc <UserRoleDoc> value))
            {
                return(value);
            }

            HeaderDoc <UserRoleDoc> result = await _roleRepository.Get(context, ActorKey.VectorKey);

            if (result == null)
            {
                return(null);
            }

            _cache.Set(result);
            return(result);
        }
Esempio n. 5
0
        public async Task <bool> Set(IWorkContext context, UserRoleDoc userRole, string eTag = null)
        {
            Verify.IsNotNull(nameof(context), context);
            Verify.IsNotNull(nameof(userRole), userRole);
            context = context.WithTag(_tag);

            var envelope = new HeaderDoc <UserRoleDoc>(userRole);

            var query = new And()
                        + (new Field(HeaderDoc.FieldName(nameof(UserRoleDoc.RoleId))) == userRole.RoleId);

            if (eTag.IsEmpty())
            {
                return(await _collection.Upsert(context, query.ToDocument(), envelope).ConfigureAwait(false));
            }

            query += (new Field(nameof(HeaderDoc <UserRoleDoc> .ETag)) == eTag);
            return(await _collection.Update(context, query.ToDocument(), envelope).ConfigureAwait(false));
        }
Esempio n. 6
0
        public async Task <HeaderDoc <UserRoleDoc> > Get(IWorkContext context, string roleId)
        {
            Verify.IsNotNull(nameof(context), context);
            Verify.IsNotEmpty(nameof(roleId), roleId);
            context = context.WithTag(_tag);

            var options = new driver.FindOptions <HeaderDoc <UserRoleDoc> >
            {
                Limit      = 1,
                Projection = "{'_id': 0}"
            };

            var query = new And()
                        + (new Field(HeaderDoc.FieldName(nameof(UserRoleDoc.RoleId))) == roleId);

            var result = await _collection.Find(context, query.ToDocument(), options).ConfigureAwait(false);

            return(result.FirstOrDefault());
        }
        public AdministrationRepository(IIdentityConfiguration identityConfiguration)
        {
            Verify.IsNotNull(nameof(identityConfiguration), identityConfiguration);
            Verify.IsNotEmpty(nameof(identityConfiguration.DatabaseName), identityConfiguration.DatabaseName);
            Verify.IsNotEmpty(nameof(identityConfiguration.IdentityRoleCollectionName), identityConfiguration.IdentityRoleCollectionName);
            Verify.IsNotEmpty(nameof(identityConfiguration.IdentityUserCollectionName), identityConfiguration.IdentityUserCollectionName);

            _configuration  = identityConfiguration;
            _documentServer = new DocumentServer(_configuration.ConnectionString);

            _models = new CollectionModel[]
            {
                new CollectionModel
                {
                    CollectionName = identityConfiguration.IdentityRoleCollectionName,
                    Indexes        = new CollectionIndex[]
                    {
                        new CollectionIndex
                        {
                            Name   = $"{nameof(UserRoleDoc.RoleId)}_index",
                            Unique = true,
                            Keys   = new IndexKey[]
                            {
                                new IndexKey {
                                    FieldName = HeaderDoc.FieldName(nameof(UserRoleDoc.RoleId)), Descending = false
                                },
                            }
                        }
                    }
                },

                new CollectionModel
                {
                    CollectionName = identityConfiguration.IdentityUserCollectionName,
                    Indexes        = new CollectionIndex[]
                    {
                        new CollectionIndex
                        {
                            Name   = $"{nameof(UserDoc.NormalizedEmail)}_index",
                            Unique = false,
                            Keys   = new IndexKey[]
                            {
                                new IndexKey {
                                    FieldName = HeaderDoc.FieldName(nameof(UserDoc.NormalizedEmail)), Descending = false
                                },
                            }
                        },
                        new CollectionIndex
                        {
                            Name   = $"{nameof(UserDoc.NormalizedUserName)}_index",
                            Unique = true,
                            Keys   = new IndexKey[]
                            {
                                new IndexKey {
                                    FieldName = HeaderDoc.FieldName(nameof(UserDoc.NormalizedUserName)), Descending = false
                                },
                            }
                        }
                    }
                }
            };
        }