public async Task <PagedResults <Opening> > GetOpeningsAsync(
            PagingOptions pagingOptions,
            SortOptions <Opening, OpeningEntity> sortOptions,
            SearchOptions <Opening, OpeningEntity> searchOptions,
            CancellationToken ct)
        {
            var rooms = await _context.Rooms.ToArrayAsync();

            var allOpenings = new List <OpeningEntity>();

            foreach (var room in rooms)
            {
                // Generate a sequence of raw opening slots
                var allPossibleOpenings = _dateLogicService.GetAllSlots(
                    DateTimeOffset.UtcNow,
                    _dateLogicService.FurthestPossibleBooking(DateTimeOffset.UtcNow))
                                          .ToArray();

                var conflictedSlots = await GetConflictingSlots(
                    room.Id,
                    allPossibleOpenings.First().StartAt,
                    allPossibleOpenings.Last().EndAt,
                    ct);

                // Remove the slots that have conflicts and project
                var openings = allPossibleOpenings
                               .Except(conflictedSlots, new BookingRangeComparer())
                               .Select(slot => new OpeningEntity
                {
                    RoomId  = room.Id,
                    Rate    = room.Rate,
                    StartAt = slot.StartAt,
                    EndAt   = slot.EndAt
                });

                allOpenings.AddRange(openings);
            }

            var pseudoQuery = allOpenings.AsQueryable();

            pseudoQuery = searchOptions.Apply(pseudoQuery);
            pseudoQuery = sortOptions.Apply(pseudoQuery);

            var size = pseudoQuery.Count();

            var items = pseudoQuery
                        .Skip(pagingOptions.Offset.Value)
                        .Take(pagingOptions.Limit.Value)
                        .ProjectTo <Opening>()
                        .ToArray();

            return(new PagedResults <Opening>
            {
                TotalSize = size,
                Items = items
            });
        }
Пример #2
0
        public async Task <PagedResults <Opening> > GetOpeningsAsync(PagingOptions pagingOptions, SortOptions <Opening, OpeningEntity> sortOptions)
        {
            var rooms = await _context.Rooms.ToArrayAsync();

            var allOpenings = new List <OpeningEntity>();

            foreach (var room in rooms)
            {
                var allPossibleOpenings = _dateLogicService.GetAllSlots(
                    DateTimeOffset.UtcNow,
                    _dateLogicService.FurthestPossibleBooking(DateTimeOffset.UtcNow))
                                          .ToArray();

                var conflictedSlots = await GetConflictingSlots(
                    room.Id,
                    allPossibleOpenings.First().StartAt,
                    allPossibleOpenings.Last().EndAt);

                //remove the slots that have conflicts and project
                var openings = allPossibleOpenings.
                               Except(conflictedSlots, new BookingRangeComparer())
                               .Select(slot => new OpeningEntity
                {
                    Roomid  = room.Id,
                    Rate    = room.Rate,
                    StartAt = slot.StartAt,
                    EndAt   = slot.EndAt
                });
                //.Select(model => _mapper.Map<Opening>(model));

                allOpenings.AddRange(openings);
            }

            IQueryable <OpeningEntity> pseudoQuery = allOpenings.AsQueryable();

            pseudoQuery = sortOptions.Apply(pseudoQuery);

            var pagedOpenings = pseudoQuery
                                .Skip(pagingOptions.Offset.Value)
                                .Take(pagingOptions.Limit.Value)
                                .ProjectTo <Opening>(_mappingConfiguration)
                                .ToArray();

            var size = pseudoQuery.Count();

            return(new PagedResults <Opening> {
                Items = pagedOpenings,
                TotalSize = size
            }

                   );
        }
Пример #3
0
        public async Task <PagedResults <Opening> > GetOpeningsAsync(PagingOptions paggingOptions)
        {
            var rooms = await _context.Rooms.ToArrayAsync();

            var allOpenings = new List <Opening>();

            foreach (var room in rooms)
            {
                // Generate a sequence of raw opening slots
                var allPossibleOpenings = _dateLogicService.GetAllSlots(
                    DateTimeOffset.UtcNow,
                    _dateLogicService.FurthestPossibleBooking(DateTimeOffset.UtcNow))
                                          .ToArray();

                if (allPossibleOpenings.Length == 0)
                {
                    continue;
                }

                var conflictedSlots = await GetConflictingSlots(
                    room.Id,
                    allPossibleOpenings.First().StartAt,
                    allPossibleOpenings.Last().EndAt);

                // Remove the slots that have conflicts and project
                var openings = allPossibleOpenings
                               .Except(conflictedSlots, new BookingRangeComparer())
                               .Select(slot => new OpeningEntity
                {
                    RoomId  = room.Id,
                    Rate    = room.Rate,
                    StartAt = slot.StartAt,
                    EndAt   = slot.EndAt
                })
                               .Select(model => _mapper.Map <Opening>(model));

                allOpenings.AddRange(openings);
            }

            var paggedOpenings = allOpenings.Skip(paggingOptions.Offset.Value).Take(paggingOptions.Limit.Value);

            return(new PagedResults <Opening>
            {
                Items = paggedOpenings,
                TotalSize = allOpenings.Count
            });
        }
        public async Task <IEnumerable <Opening> > GetOpeningsAsync(CancellationToken ct)
        {
            var rooms = await _context.Rooms.ToArrayAsync();

            var allOpenings = new List <Opening>();

            foreach (var room in rooms)
            {
                // Generate a sequence of raw opening slots
                var allPossibleOpenings = _dateLogicService.GetAllSlots(
                    DateTimeOffset.UtcNow,
                    _dateLogicService.FurthestPossibleBooking(DateTimeOffset.UtcNow))
                                          .ToArray();

                var conflictedSlots = await GetConflictingSlots(
                    room.Id,
                    allPossibleOpenings.First().StartAt,
                    allPossibleOpenings.Last().EndAt,
                    ct);

                // Remove the slots that have conflicts and project
                var openings = allPossibleOpenings
                               .Except(conflictedSlots, new BookingRangeComparer())
                               .Select(slot => new OpeningEntity
                {
                    RoomId  = room.Id,
                    Rate    = room.Rate,
                    StartAt = slot.StartAt,
                    EndAt   = slot.EndAt
                })
                               .Select(model => Mapper.Map <Opening>(model));

                allOpenings.AddRange(openings);
            }

            return(allOpenings);
        }