private Guid AssignCompetitor(BuyTicketCommand command)
        {
            var context = new SweepstakeContext(
                new DbContextOptionsBuilder <SweepstakeContext>()
                .UseSqlServer(Constants.ConnectionString)
                .Options);
            var competitors = context.Competitors.Where(c => c.CompetitionId == command.CompetitionId);

            return(competitors.Skip(new Random().Next(0, competitors.Count())).First().Id);
        }
        public async Task HandleAsync(BuyTicketCommand command)
        {
            var context = new SweepstakeContext(
                new DbContextOptionsBuilder <SweepstakeContext>()
                .UseSqlServer(Constants.ConnectionString)
                .Options);

            context.Tickets.AddAsync(new Ticket
            {
                Id                = command.Id,
                CompetitionId     = command.CompetitionId,
                CompetitorId      = command.CompetitorId,
                GamblerId         = command.GamblerId,
                IsPaymentReceived = command.IsPaymentReceived,
                BoughtAt          = DateTime.Now,
                PaymentReceivedAt = command.IsPaymentReceived ? DateTime.UtcNow : null as DateTime?
            });
            context.SaveChangesAsync();
        }