Exemplo n.º 1
0
        public IHttpActionResult GetSC2Match(Guid id)
        {
            TournamentSC2Match match = _dbContext.TournamentSC2Matches.Find(id);

            if (match != null)
            {
                return(Ok(match));
            }
            return(NotFound());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetSC2Match(Guid id)
        {
            TournamentSC2Match match = await _dbContext.TournamentSC2Matches.FindAsync(id);

            if (match != null)
            {
                return(Ok(match));
            }
            return(NotFound());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> SubmitSC2Match(Guid?id, TournamentSC2Match match)
        {
            if (await UserIsInRole("event-admin"))
            {
                foreach (SC2MatchMap map in match.Maps)
                {
                    SC2MatchMap mapEntity = await _dbContext.SC2MatchMaps.FindAsync(map.Id);

                    if (mapEntity != null)
                    {
                        _dbContext.Entry(mapEntity).CurrentValues.SetValues(map);
                    }
                    else
                    {
                        _dbContext.SC2MatchMaps.Add(map);
                    }
                }

                TournamentSC2Match entity = await _dbContext.TournamentSC2Matches.FindAsync(id);

                if (entity != null)
                {
                    _dbContext.Entry(entity).CurrentValues.SetValues(match);
                    match = entity;
                }
                else
                {
                    _dbContext.TournamentSC2Matches.Add(match);
                }

                try
                {
                    await _dbContext.SaveChangesAsync();
                }
                catch (DbUpdateException e)
                {
                    System.Diagnostics.Trace.TraceError("Tournament StarCraft II match update exception: " + e.Message);
                    return(BadRequest("Something went wrong..."));
                }
                if (entity == null)
                {
                    await _dbContext.Entry(match).Reference(m => m.Player1).LoadAsync();

                    await _dbContext.Entry(match).Reference(m => m.Player2).LoadAsync();
                }
                return(Ok(match));
            }
            return(Unauthorized());
        }
Exemplo n.º 4
0
        public IHttpActionResult DeleteSC2Match(Guid?id)
        {
            if (UserIsInRole("event-admin"))
            {
                TournamentSC2Match entity = _dbContext.TournamentSC2Matches.Find(id);
                _dbContext.TournamentSC2Matches.Remove(entity);

                try
                {
                    _dbContext.SaveChanges();
                }
                catch (DbUpdateException e)
                {
                    System.Diagnostics.Trace.TraceError("Tournament StarCraft II match delete exception: " + e.Message);
                    return(BadRequest("Something went wrong..."));
                }
                return(Ok(entity));
            }
            return(Unauthorized());
        }
Exemplo n.º 5
0
        public async Task <IHttpActionResult> SubmitSC2Match(Guid?id, TournamentSC2Match match)
        {
            if (UserIsInRole("event-admin"))
            {
                TournamentSC2Match entity = _dbContext.TournamentSC2Matches.Find(id);
                if (entity != null)
                {
                    _dbContext.Entry(entity).CurrentValues.SetValues(match);
                    match = entity;
                }
                else
                {
                    if (match.TournamentId == null)
                    {
                        match.TournamentId = _dbContext.Tournaments.Where(t => t.Active).First().ID;
                    }
                    _dbContext.TournamentSC2Matches.Add(match);
                }

                try
                {
                    _dbContext.SaveChanges();
                }
                catch (DbUpdateException e)
                {
                    System.Diagnostics.Trace.TraceError("Tournament StarCraft II match update exception: " + e.Message);
                    return(BadRequest("Something went wrong..."));
                }
                if (entity == null)
                {
                    await _dbContext.Entry(match).Reference(m => m.Player1).LoadAsync().ConfigureAwait(false);

                    await _dbContext.Entry(match).Reference(m => m.Player2).LoadAsync().ConfigureAwait(false);
                }
                return(Ok(match));
            }
            return(Unauthorized());
        }