private IQueryable <Reservation> ApplyFilters(GetAllReservationsQuery filters, IQueryable <Reservation> query)
        {
            if (filters.HostId != null)
            {
                query = query.Where(r => r.Apartment.HostId == filters.HostId);
            }

            if (filters.GuestId != null)
            {
                query = query.Where(r => r.GuestId == filters.GuestId);
            }
            if (!string.IsNullOrEmpty(filters.GuestUsername))
            {
                query = query.Where(r => string.Equals(r.Guest.User.Username, filters.GuestUsername, StringComparison.OrdinalIgnoreCase));
            }

            if (filters.ApartmentId != null)
            {
                query = query.Where(r => r.ApartmentId == filters.ApartmentId);
            }

            if (!string.IsNullOrEmpty(filters.ReservationState))
            {
                query = query.Where(r => string.Equals(r.ReservationState, filters.ReservationState, StringComparison.OrdinalIgnoreCase));
            }

            return(query);
        }
Exemplo n.º 2
0
        private IMongoQueryable <ReservationModel> ApplyFilters(GetAllReservationsQuery filters, IMongoQueryable <ReservationModel> query)
        {
            if (filters.HostId != null)
            {
                query = query.Where(r => r.HostId == filters.HostId);
            }

            if (filters.GuestId != null)
            {
                query = query.Where(r => r.GuestId == filters.GuestId);
            }
            if (!string.IsNullOrEmpty(filters.GuestUsername))
            {
                query = query.Where(r => r.GuestUsername.ToLower() == filters.GuestUsername.ToLower());
            }

            if (filters.ApartmentId != null)
            {
                query = query.Where(r => r.ApartmentId == filters.ApartmentId);
            }

            if (!string.IsNullOrEmpty(filters.ReservationState))
            {
                query = query.Where(r => r.ReservationState.ToLower() == filters.ReservationState.ToLower());
            }

            return(query);
        }
Exemplo n.º 3
0
        public async Task <IEnumerable <ReservationDto> > Handle(GetAllReservationsQuery request, CancellationToken cancellationToken)
        {
            IMongoQueryable <ReservationModel> query = this.context.Reservations.AsQueryable();

            query = this.ApplyFilters(request, query);

            var reservations = await query.ToListAsync(cancellationToken).ConfigureAwait(false);

            return(reservations.Select(r => CustomMapper.Map <ReservationDto>(r)));
        }
        public async Task <IEnumerable <ReservationDto> > Handle(GetAllReservationsQuery request, CancellationToken cancellationToken)
        {
            var query = this.context.Reservations
                        .Include(r => r.Guest).ThenInclude(g => g.User)
                        .Include(r => r.Apartment).ThenInclude(a => a.Host).ThenInclude(h => h.User)
                        .Where(r => !r.IsDeleted && !r.Apartment.IsDeleted && !r.Guest.IsDeleted);

            query = this.ApplyFilters(request, query);

            var reservations = await query.ToListAsync(cancellationToken).ConfigureAwait(false);

            return(reservations.Select(r => new ReservationDto(r)));
        }