public async Task HandleAsync(CreateGamblerCommand command)
        {
            var context = new SweepstakeContext(
                new DbContextOptionsBuilder <SweepstakeContext>()
                .UseSqlServer(Constants.ConnectionString)
                .Options);

            context.Gamblers.Add(new Gambler
            {
                Name = command.Name,
            });
            context.SaveChanges();
        }
        public async Task HandleAsync(CreateCompetitorCommand command)
        {
            var context = new SweepstakeContext(
                new DbContextOptionsBuilder <SweepstakeContext>()
                .UseSqlServer(Constants.ConnectionString)
                .Options);

            context.Competitors.Add(new Competitor
            {
                Id            = command.Id == Guid.Empty ? Guid.NewGuid() : command.Id,
                CompetitionId = command.CompetitionId,
                Name          = command.Name,
                Tickets       = command.Tickets.ToList()
            });

            context.SaveChanges();
        }
Example #3
0
        public async Task HandleAsync(CreateCompetitionCommand command)
        {
            var context = new SweepstakeContext(
                new DbContextOptionsBuilder <SweepstakeContext>()
                .UseSqlServer(Constants.ConnectionString)
                .Options);

            context.Competitions.Add(new Competition
            {
                Id          = command.Id == Guid.Empty ? Guid.NewGuid() : command.Id,
                Name        = command.Name,
                Description = command.Description,
                EntryFee    = command.EntryFee,
                Competitors = command.CompetitorNames.Select(cn => new Competitor
                {
                    Id   = Guid.NewGuid(),
                    Name = cn
                }).ToList()
            });
            context.SaveChanges();
        }