Esempio n. 1
0
        public IHttpActionResult SubmitSC2MatchMap(Guid?id, SC2MatchMap map)
        {
            if (UserIsInRole("event-admin"))
            {
                SC2MatchMap entity = _dbContext.TournamentSC2MatchMaps.Find(id);
                if (entity != null)
                {
                    _dbContext.Entry(entity).CurrentValues.SetValues(map);
                }
                else
                {
                    entity = _dbContext.TournamentSC2MatchMaps.Add(map);
                }

                try
                {
                    _dbContext.SaveChanges();
                }
                catch (DbUpdateException e)
                {
                    System.Diagnostics.Trace.TraceError("Tournament CS:GO match map update exception: " + e.Message);
                    return(BadRequest("Something went wrong..."));
                }
                return(Ok(entity));
            }
            return(Unauthorized());
        }
Esempio n. 2
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());
        }
Esempio n. 3
0
        public IHttpActionResult DeleteSC2MatchMap(Guid?id)
        {
            if (UserIsInRole("event-admin"))
            {
                SC2MatchMap entity = _dbContext.TournamentSC2MatchMaps.Find(id);
                _dbContext.TournamentSC2MatchMaps.Remove(entity);

                try
                {
                    _dbContext.SaveChanges();
                }
                catch (DbUpdateException e)
                {
                    System.Diagnostics.Trace.TraceError("Tournament CS:GO match map delete exception: " + e.Message);
                    return(BadRequest("Something went wrong..."));
                }
                return(Ok(entity));
            }
            return(Unauthorized());
        }