public async Task <Area> Find(string id)
        {
            IAsyncCursor <Area> cursor = await AreaCollection
                                         .FindAsync(Builders <Area> .Filter.Eq("_id", new ObjectId(id)));

            return(await cursor.SingleOrDefaultAsync());
        }
Exemplo n.º 2
0
        public async Task <TreeHistory> Find(string id)
        {
            IAsyncCursor <TreeHistory> cursor = await repos
                                                .FindAsync(Builders <TreeHistory> .Filter.Eq("_id", new ObjectId(id)));

            return(await cursor.SingleOrDefaultAsync());
        }
        public async Task <Tree> Find(string id)
        {
            IAsyncCursor <Tree> cursor = await treeCollection
                                         .FindAsync(Builders <Tree> .Filter.Eq("_id", ObjectId.Parse(id)));

            return(await cursor.SingleOrDefaultAsync());
        }
Exemplo n.º 4
0
        public async Task <NodeType> GetNodeType(long origin)
        {
            try
            {
                var filter = Builders <EntityList> .Filter.Eq(nameof(EntityList.origin), origin);

                IAsyncCursor <EntityList> cursor = await Collection.FindAsync(filter);

                var entity_list = await cursor.SingleOrDefaultAsync();

                return(entity_list.node);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "GetNodeType Failed");
            }

            return(NodeType.None);
        }
        public async Task <Models.Users.User> GetByNameAsync(string username)
        {
            IAsyncCursor <Models.Users.User> result = await GetUserCollection().FindAsync(user => string.Equals(user.Username, username));

            return(await result.SingleOrDefaultAsync());
        }
        /// <summary>
        /// Gets a single entity from the repo according to the specified predicate condition.<para></para>
        /// If 0 or &gt;1 entities are found, <c>null</c> is returned.
        /// </summary>
        /// <param name="predicate">The search predicate.</param>
        /// <returns>Single found entity; <c>null</c> if 0 or &gt;1 entities were found.</returns>
        public async Task <T> SingleOrDefault(Expression <Func <T, bool> > predicate)
        {
            IAsyncCursor <T> cursor = await collection.FindAsync(predicate).ConfigureAwait(false);

            return(await cursor.SingleOrDefaultAsync());
        }
        public async Task <User> GetByUsernameAsync(string username)
        {
            IAsyncCursor <User> result = await GetCollection().FindAsync(user => user.Username == username);

            return(await result.SingleOrDefaultAsync());
        }
        public async Task <User> GetByIdAsync(string id)
        {
            IAsyncCursor <User> user = await GetCollection().FindAsync(user => user.Id == id);

            return(await user.SingleOrDefaultAsync());
        }
Exemplo n.º 9
0
        public async Task Execute(string roleId, RoleCreateModel changes, IValidator validator)
        {
            try
            {
                //Validate fields
                _validationStrategy.Validate(changes, validator);
                if (validator.HasErrors)
                {
                    return;
                }

                //Check if role with this name and consumer already exists
                long count = await _roleRepo.CountDocumentsAsync(x => x.Name == changes.Name && x.Consumer == changes.Consumer && x.Id != roleId);

                if (count != 0)
                {
                    validator.AddError("A role with this name already exists");
                    return;
                }

                IAsyncCursor <Role> cursor = await _roleRepo.FindAsync(x => x.Id == roleId);

                Role role = await cursor.SingleOrDefaultAsync();

                if (role == null)
                {
                    throw new Exception("Role not found");
                }

                var updateDef = Builders <Role> .Update.Set(r => r.Name, changes.Name)
                                .Set(r => r.Description, changes.Description)
                                .Set(r => r.Consumer, changes.Consumer)
                                .Set(r => r.Status, changes.Status);

                //Persist created role
                await _roleRepo.UpdateOneAsync(r => r.Id == roleId, updateDef);

                await Publish(new RoleCreatedOrEditedEvent()
                {
                    CorrelationId = Guid.NewGuid().ToString("N"),
                    IssuerSystem  = "AuthServer.UserSystem",
                    Issuer        = "AuthServer.UserSystem.Services.Commands.EditRoleCommand",
                    EventDate     = DateTime.Now,

                    Id           = role.Id,
                    Name         = role.Name,
                    Description  = role.Description,
                    Consumer     = role.Consumer,
                    RoleIsActive = (role.Status == RoleStatus.Active)
                });

                return;
            }
            catch (Exception ex)
            {
                //Log error
                await _logger.LogErrorAsync("EditRoleCommand.Execute", "Exception was thrown", new
                {
                    RoleId    = roleId,
                    Changes   = changes,
                    Exception = ex
                });

                throw;
            }
        }
        public async Task <Auction> GetByIdAsync(string id)
        {
            IAsyncCursor <Auction> auction = await GetCollection().FindAsync(auction => auction.Id == id);

            return(await auction.SingleOrDefaultAsync());
        }