示例#1
0
        public Task <bool> CompliesWithRuleAsync(PitchBooking booking)
        {
            var startHourPasses = booking.StartDateTime.Hour >= _clubConfiguration.OpenHour;
            var endHourPasses   = booking.EndDateTime.Hour <= _clubConfiguration.CloseHour;

            return(Task.FromResult(startHourPasses && endHourPasses));
        }
        public async Task <PitchBookingResult> MakeBookingAsync(DateTime startDateTime,
                                                                DateTime endDateTime,
                                                                int pitchId,
                                                                Member member)
        {
            var pitchBooking = new PitchBooking
            {
                PitchId       = pitchId,
                Member        = member,
                StartDateTime = startDateTime,
                EndDateTime   = endDateTime
            };

            var(passedRules, errors) = await _bookingRuleProcessor.PassesAllRulesAsync(pitchBooking);

            if (!passedRules)
            {
                return(PitchBookingResult.Failure(errors));
            }

            await _bookingService.CreatePitchBooking(pitchBooking);

            await _messagingService.SendAsync("Thank you. Your booking is confirmed", member.User.Id);

            return(PitchBookingResult.Success(pitchBooking));
        }
示例#3
0
        public async Task <bool> CompliesWithRuleAsync(PitchBooking booking)
        {
            var todaysBookings = (await _pitchBookingService
                                  .MemberBookingsForDayAsync(booking.StartDateTime.Date, booking.Member))
                                 .ToArray();

            if (!todaysBookings.Any())
            {
                return(true); // no bookings, so cannot be overlap
            }
            var bookingHours = Enumerable.Range(booking.StartDateTime.Hour,
                                                booking.EndDateTime.Hour - booking.StartDateTime.Hour).ToArray();

            foreach (var existingBooking in todaysBookings)
            {
                for (var hour = existingBooking.StartDateTime.Hour; hour < existingBooking.EndDateTime.Hour; hour++)
                {
                    if (bookingHours.Contains(hour))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        public Task <bool> CompliesWithRuleAsync(PitchBooking booking)
        {
            var bookingLength = booking.EndDateTime - booking.StartDateTime;

            var compliesWithRule = bookingLength <= TimeSpan.FromHours(_bookingConfiguration.MaxRegularBookingLengthInHours);

            return(Task.FromResult(compliesWithRule));
        }
示例#5
0
        public async Task <bool> CompliesWithRuleAsync(PitchBooking booking)
        {
            var hoursBooked = await _pitchBookingService.GetBookedHoursForMemberAsync(booking.Member, booking.StartDateTime.Date);

            var hoursRequested = (booking.EndDateTime - booking.StartDateTime).Hours;

            return(hoursBooked + hoursRequested <= 5);
        }
        public async Task <(bool, IEnumerable <string>)> PassesAllRulesAsync(PitchBooking pitchBooking)
        {
            var passedRules = true;

            var errors = new List <string>();

            foreach (var rule in _rules)
            {
                if (!await rule.CompliesWithRuleAsync(pitchBooking))
                {
                    errors.Add(rule.ErrorMessage);
                    passedRules = false;
                }
            }

            return(passedRules, errors);
        }
        public Task <bool> CompliesWithRuleAsync(PitchBooking booking)
        {
            if (booking.EndDateTime.Hour < _clubConfiguration.PeakStartHour)
            {
                return(Task.FromResult(true));
            }

            var peakHours = 0;

            for (var hour = booking.StartDateTime.Hour; hour < booking.EndDateTime.Hour; hour++)
            {
                if (hour >= _clubConfiguration.PeakStartHour && hour <= _clubConfiguration.PeakEndHour)
                {
                    peakHours++;
                }
            }

            return(Task.FromResult(peakHours <= _bookingConfiguration.MaxPeakBookingLengthInHours));
        }
        public async Task CreatePitchBooking(PitchBooking pitchBooking)
        {
            _dbContext.PitchBookings.Add(pitchBooking);

            await _dbContext.SaveChangesAsync();
        }