Example #1
0
        public SuggestionsMade(ShowId showId, PartyRequested partyRequested)
        {
            ShowId         = showId;
            PartyRequested = partyRequested;

            InstantiateAnEmptyListForEveryPricingCategory();
        }
Example #2
0
 public SuggestionMade(PartyRequested partyRequested, PricingCategoryRequested pricingCategoryRequested,
                       List <Seat> seats)
 {
     PartyRequested           = partyRequested;
     PricingCategoryRequested = pricingCategoryRequested;
     _suggestedSeats          = seats;
 }
        public static IEnumerable <AdjacentSeats> SelectAdjacentSeats(this IEnumerable <Seat> seats,
                                                                      PartyRequested partyRequested)
        {
            var adjacentSeatsGroups = new List <AdjacentSeats>();
            var adjacentSeats       = new List <Seat>();
            var currentSeats        = seats.ToList();

            if (partyRequested.PartySize == 1)
            {
                return(currentSeats.Select(s => new AdjacentSeats(new List <Seat> {
                    s
                })));
            }

            foreach (var candidateSeat in currentSeats.ToList())
            {
                if (!adjacentSeats.Any())
                {
                    adjacentSeats.Add(candidateSeat);
                    continue;
                }

                adjacentSeats = adjacentSeats.OrderBy(s => s.Number).ToList();

                if (candidateSeat.IsAdjacentWith(adjacentSeats))
                {
                    adjacentSeats.Add(candidateSeat);

                    if (NoMoreSeats(adjacentSeats, currentSeats))
                    {
                        adjacentSeatsGroups.Add(new AdjacentSeats(ReduceAdjacentSeats(partyRequested, adjacentSeats)));
                    }
                }
                else
                {
                    if (adjacentSeats.Any())
                    {
                        adjacentSeatsGroups.Add(ReduceAdjacentSeats(partyRequested, adjacentSeats));
                    }

                    adjacentSeats = new List <Seat> {
                        candidateSeat
                    };
                }
            }

            return(adjacentSeatsGroups.Where(adjacent => adjacent.Count() >= partyRequested.PartySize));
        }
Example #4
0
        public static Maybe <SuggestionsMade> TryMakeSuggestions(ShowId showId, PartyRequested partyRequested, AuditoriumSeating auditoriumSeating)
        {
            var suggestionsMade = new SuggestionsMade(showId, partyRequested);

            suggestionsMade.Add(GiveMeSuggestionsFor(auditoriumSeating, partyRequested, PricingCategory.First));
            suggestionsMade.Add(GiveMeSuggestionsFor(auditoriumSeating, partyRequested, PricingCategory.Second));
            suggestionsMade.Add(GiveMeSuggestionsFor(auditoriumSeating, partyRequested, PricingCategory.Third));
            suggestionsMade.Add(GiveMeSuggestionsFor(auditoriumSeating, partyRequested, PricingCategory.Mixed));

            if (suggestionsMade.MatchExpectations())
            {
                return(new Maybe <SuggestionsMade>(suggestionsMade));
            }

            return(new Maybe <SuggestionsMade>());
        }
Example #5
0
        public async Task <SuggestionsMade> MakeSuggestions(ShowId showId, PartyRequested partyRequested)
        {
            var auditoriumSeating = await _auditoriumSeatingAdapter.GetAuditoriumSeating(showId);

            var suggestionsMade = new SuggestionsMade(showId, partyRequested);

            suggestionsMade.Add(GiveMeSuggestionsFor(auditoriumSeating, partyRequested,
                                                     PricingCategoryRequested.First));
            suggestionsMade.Add(
                GiveMeSuggestionsFor(auditoriumSeating, partyRequested, PricingCategoryRequested.Second));
            suggestionsMade.Add(GiveMeSuggestionsFor(auditoriumSeating, partyRequested,
                                                     PricingCategoryRequested.Third));
            suggestionsMade.Add(GiveMeSuggestionsFor(auditoriumSeating, partyRequested,
                                                     PricingCategoryRequested.Mixed));

            if (suggestionsMade.DoesMatchExpectations())
            {
                return(suggestionsMade);
            }

            return(new SuggestionNotAvailable(showId, partyRequested));
        }
Example #6
0
        private static IEnumerable <SuggestionMade> GiveMeSuggestionsFor(
            AuditoriumSeating auditoriumSeating,
            PartyRequested partyRequested,
            PricingCategoryRequested pricingCategoryRequested)
        {
            var foundedSuggestions = new List <SuggestionMade>();

            for (var i = 0; i < NumberOfSuggestionsPerPricingCategory; i++)
            {
                var seatOptionsSuggested = auditoriumSeating
                                           .SuggestSeatingOptionFor(new SuggestionRequest(partyRequested, pricingCategoryRequested));

                if (seatOptionsSuggested.MatchExpectation())
                {
                    // We get the new version of the Auditorium after the allocation
                    auditoriumSeating = auditoriumSeating.Allocate(seatOptionsSuggested);

                    foundedSuggestions.Add(new SuggestionMade(partyRequested, pricingCategoryRequested,
                                                              seatOptionsSuggested.Seats));
                }
            }

            return(foundedSuggestions);
        }
 public SeatingOptionSuggested(SuggestionRequest suggestionRequest)
 {
     PartyRequested  = suggestionRequest.PartyRequested;
     PricingCategory = suggestionRequest.PricingCategory;
 }
Example #8
0
 public SuggestionRequest(PartyRequested partyRequested, PricingCategory pricingCategory)
 {
     PartyRequested  = partyRequested;
     PricingCategory = pricingCategory;
 }
 private static bool DoesNotExceedPartyRequestedAndCandidateSeatIsAdjacent(Seat candidateSeat, List <Seat> adjacentSeats, PartyRequested partyRequested)
 {
     return(candidateSeat.IsAdjacentWith(adjacentSeats) && adjacentSeats.Count < partyRequested.PartySize);
 }
        public static IEnumerable <AdjacentSeats> SelectAdjacentSeats(this IEnumerable <Seat> seats, PartyRequested partyRequested)
        {
            var adjacentSeatsGroups = new List <AdjacentSeats>();
            var adjacentSeats       = new List <Seat>();

            if (partyRequested.PartySize == 1)
            {
                return(seats.Select(s => new AdjacentSeats(new List <Seat> {
                    s
                })));
            }

            foreach (var candidateSeat in seats.OrderBy(s => s.DistanceFromRowCentroid))
            {
                if (!adjacentSeats.Any())
                {
                    adjacentSeats.Add(candidateSeat);
                    continue;
                }

                adjacentSeats = adjacentSeats.OrderBy(s => s.Number).ToList();

                if (DoesNotExceedPartyRequestedAndCandidateSeatIsAdjacent(candidateSeat, adjacentSeats, partyRequested))
                {
                    adjacentSeats.Add(candidateSeat);
                }
                else
                {
                    if (adjacentSeats.Any())
                    {
                        adjacentSeatsGroups.Add(new AdjacentSeats(adjacentSeats));
                    }

                    adjacentSeats = new List <Seat> {
                        candidateSeat
                    };
                }
            }

            return(adjacentSeatsGroups.Where(adjacent => adjacent.Count() == partyRequested.PartySize));
        }
        public async static Task <SuggestionsMade> MakeSuggestionsImperativeShell(Ports.IProvideUpToDateAuditoriumSeating auditoriumSeatingProvider, ShowId id, PartyRequested partyRequested)
        {
            // non-pure function
            var auditoriumSeating = await auditoriumSeatingProvider.GetAuditoriumSeating(id);

            // call pure function
            return(SeatAllocator
                   .TryMakeSuggestions(id, partyRequested, auditoriumSeating)
                   .GetValueOrFallback(new SuggestionNotAvailable(id, partyRequested)));

            // Balance restored:
            // - inner hexagon knows about adapter capabilities but not implementation
            // - orchestration is back in the 'core' where we can locally reason about it

            // Notes:
            // in this case the imperative shells can be easily distinguished by the 'async' keyword which kind of plays the role of the IO<> marker type.
        }
        private static AdjacentSeats ReduceAdjacentSeats(PartyRequested partyRequested, IEnumerable <Seat> adjacentSeats)
        {
            var orderedAdjacentSeats = adjacentSeats.OrderBy(s => s.DistanceFromRowCentroid).ToList();

            return(new AdjacentSeats(orderedAdjacentSeats.Take(partyRequested.PartySize).OrderBy(s => s.Number)));
        }