Ejemplo n.º 1
0
        public async Task <BookingsUpdateSignalR> GetBookingsUpdateAsync(int serviceId, DateTime date, string time)
        {
            var bookings = await _context.Set <Booking>()
                           .Where(x => x.ServiceId == serviceId &&
                                  x.Date.Date == date.Date &&
                                  x.Time == time &&
                                  x.UserId == null &&
                                  x.ShowSundayService)
                           .ToListAsync();

            var availableBookings = bookings
                                    .Where(x => x.UserId == null)
                                    .ToList();

            var bookingsUpdate = new BookingsUpdateSignalR
            {
                ServiceId              = serviceId,
                Total                  = bookings.Count(),
                Time                   = time,
                AdultsAvailableSlots   = availableBookings.Where(x => x.IsAdultSlot).Count(),
                KidsAvailableSlots     = availableBookings.Where(x => x.IsKidSlot).Count(),
                ToddlersAvailableSlots = availableBookings.Where(x => x.IsToddlerSlot).Count()
            };

            return(bookingsUpdate);
        }
Ejemplo n.º 2
0
        // client to call this method to get booking update
        public async Task GetBookingsUpdate(int serviceId, DateTime date, string time)
        {
            var bookings = await _context.Set <Booking>()
                           .Where(x => x.ServiceId == serviceId &&
                                  x.Date.Date == date.Date &&
                                  x.Time == time)
                           .ToListAsync();

            var availableBookings = bookings
                                    .Where(x => x.User == null)
                                    .ToList();

            var bookingsUpdate = new BookingsUpdateSignalR
            {
                Total                  = bookings.Count(),
                ServiceId              = serviceId,
                Time                   = time,
                AdultsAvailableSlots   = bookings.Where(x => x.IsAdultSlot).Count(),
                KidsAvailableSlots     = bookings.Where(x => x.IsKidSlot).Count(),
                ToddlersAvailableSlots = bookings.Where(x => x.IsToddlerSlot).Count()
            };

            // send available book to all clients: client need to implement ReceivedBookingsUpdateAsync to receive updates
            await Clients.All.ReceivedBookingsUpdateAsync(bookingsUpdate);
        }