示例#1
0
        private async Task ShowCancelled(ShowTime showTime)
        {
            var emailService = _serviceProvider.GetService <EmailSender>();
            var dbBookings   = _context.Bookings.Where(b => b.ShowTimeId == showTime.Id);

            foreach (var booking in dbBookings)
            {
                var userEmail = await _httpContextService.
                                GetClientEmailByIdAsync(booking.UserId.ToString());

                await emailService.SendBookingCanceled(userEmail,
                                                       showTime.Show.Name, showTime.StartDate);
            }
        }
        public async Task DeleteBooking(Guid id)
        {
            var booking = await GetBookingById(id);

            // check if user is client
            if (_httpContextService.IsClient())
            {
                var userId = _httpContextService.GetUserId();
                if (booking.UserId == userId)
                {
                    throw new ArgumentException("Action not allowed.");
                }
            }
            _context.Bookings.Remove(booking);
            await _context.SaveChangesAsync();

            var emailService = _serviceProvider.GetService <EmailSender>();
            var userEmail    = await _httpContextService.GetClientEmailByIdAsync(booking.UserId);

            await emailService.SendBookingCanceled(userEmail,
                                                   booking.ShowTime.Show.Name, booking.ShowTime.StartDate);
        }