Exemplo n.º 1
0
        public Task CreateEvent(CreateEventCommand command)
        {
            var gameEvent = new GameEvent
            {
                TeamAId   = command.TeamAId,
                TeamBId   = command.TeamBId,
                EventDate = command.EventDate,
                Status    = command.Status,
                EventType = command.Type,
                Name      = command.Name,
            };

            _dbContext.Events.Add(gameEvent);

            return(_dbContext.SaveChangesAsync());
        }
Exemplo n.º 2
0
        public async Task SaveDemoData(NewDemoCommand demo)
        {
            var teamA = await _context.Teams.AsNoTracking().FirstOrDefaultAsync(f => f.Id == demo.TeamAId);

            var teamB = await _context.Teams.AsNoTracking().FirstOrDefaultAsync(f => f.Id == demo.TeamBId);

            if (teamA == null || teamB == null)
            {
                throw new HttpStatusCodeException(System.Net.HttpStatusCode.BadRequest, "Command not found");
            }

            var teamADemos = demo.Demo.TeamA.TeamName.ToLower() == teamA.Name.ToLower() ? demo.Demo.TeamA :
                             demo.Demo.TeamB.TeamName.ToLower() == teamA.Name.ToLower() ? demo.Demo.TeamB :
                             throw new HttpStatusCodeException(System.Net.HttpStatusCode.BadRequest, $"Team {teamA.Name} from demo files not found");

            teamADemos.TeamId = teamA.Id;

            var teamBDemos = demo.Demo.TeamA.TeamName.ToLower() == teamB.Name.ToLower() ? demo.Demo.TeamA :
                             demo.Demo.TeamB.TeamName.ToLower() == teamB.Name.ToLower() ? demo.Demo.TeamB :
                             throw new HttpStatusCodeException(System.Net.HttpStatusCode.BadRequest, $"Team {teamB.Name} from demo files not found");

            teamBDemos.TeamId = teamB.Id;

            demo.Demo.TeamA = teamADemos;
            demo.Demo.TeamB = teamBDemos;

            var newDemo = new GameDemo
            {
                TeamAId     = teamA.Id,
                TeamBId     = teamB.Id,
                DateCreated = DateTime.UtcNow,
                DemoData    = JsonConvert.SerializeObject(demo.Demo),
            };

            _context.Demos.Add(newDemo);
            await _context.SaveChangesAsync();
        }