Ejemplo n.º 1
0
        public async Task<IEnumerable<Climb>> ExecuteAsync(GetClimbsQueryParameters parameters,
            IMongoCollection<Climb> collection)
        {
            var filters = new List<FilterDefinition<Climb>>();

            if (parameters.Id != Guid.Empty)
            {
                var filter = Builders<Climb>.Filter.Eq(c => c.Id == parameters.Id, true);

                filters.Add(filter);
            }

            if (parameters.Styles != null && parameters.Styles.Count > 0)
            {
                var filter = Builders<Climb>.Filter.AnyIn(c => c.Styles, parameters.Styles);
                filters.Add(filter);
            }

            if (!string.IsNullOrEmpty(parameters.Name))
            {
                var filter = Builders<Climb>.Filter.Eq(c => c.Name == parameters.Name, true);
                filters.Add(filter);
            }

            var complexFilter = Builders<Climb>.Filter.And(filters);

            var fullCollection = await collection.FindAsync(complexFilter);
            return await fullCollection.ToListAsync();
        }
Ejemplo n.º 2
0
        public async Task<IEnumerable<Climb>> GetManyAsync(GetClimbsParameters parameters)
        {
            var collection = _database.GetCollection<Climb>("climbs");
            var queryParameters = new GetClimbsQueryParameters
            {
                Id = parameters.Id,
                Name = parameters.Name
            };

            if (parameters.Styles != null)
            {
                queryParameters.Styles = parameters.Styles.ToList();
            }

            return await _getClimbsQuery.ExecuteAsync(queryParameters, collection);
        }