Пример #1
0
        public StatusModel CreateTicket(Ticket domainModel)
        {
            var response = new StatusModel();

            domainModel.DateCreated  = DateTime.Now;
            domainModel.TicketStatus = TicketStatusType.Pending;
            _ticketsRepository.Add(domainModel);

            return(response);
        }
Пример #2
0
        public async Task PurchaseAsync(Guid conferenceId, Guid userId)
        {
            var conference = await _conferencesRepository.GetAsync(conferenceId);

            if (conference is null)
            {
                throw new ConferenceNotFoundException(conferenceId);
            }

            var ticket = await _ticketsRepository.GetAsync(conferenceId, userId);

            if (ticket is not null)
            {
                throw new TicketAlreadyPurchasedException(conferenceId, userId);
            }

            var utcNow     = _dateTimeService.GetDateTimeUtcNow();
            var ticketSale = await _ticketSaleRepository.GetCurrentForConferenceAsync(conferenceId, utcNow);

            if (ticketSale is null)
            {
                throw new TicketSaleUnavailableException(conferenceId);
            }

            if (ticketSale.Amount.HasValue)
            {
                await PurchaseAvailableAsync(ticketSale, userId);

                return;
            }

            ticket = _ticketsFactory.Generate(conferenceId, ticketSale.Price, ticketSale);
            ticket.Purchase(userId, utcNow, ticketSale.Price);
            _ticketsRepository.Add(ticket);
            await _ticketsRepository.UnitOfWork.SaveChangesAsync();
        }
 public void AddTicket(Ticket ticket)
 {
     _ticketsRepository.Add(ticket);
 }