public IHttpActionResult SubmitCSGOMatchMap(Guid?id, CSGOMatchMap map) { if (UserIsInRole("event-admin")) { CSGOMatchMap entity = _dbContext.TournamentCSGOMatchMaps.Find(id); if (entity != null) { _dbContext.Entry(entity).CurrentValues.SetValues(map); } else { entity = _dbContext.TournamentCSGOMatchMaps.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()); }
public async Task <IActionResult> SubmitCSGOMatch(Guid?id, TournamentCSGOMatch match) { if (await UserIsInRole("event-admin")) { foreach (CSGOMatchMap map in match.Maps) { CSGOMatchMap mapEntity = await _dbContext.CSGOMatchMaps.FindAsync(map.Id); if (mapEntity != null) { _dbContext.Entry(mapEntity).CurrentValues.SetValues(map); } else { _dbContext.CSGOMatchMaps.Add(map); } } TournamentCSGOMatch entity = await _dbContext.TournamentCSGOMatches.FindAsync(id); if (entity != null) { _dbContext.Entry(entity).CurrentValues.SetValues(match); match = entity; } else { _dbContext.TournamentCSGOMatches.Add(match); } try { await _dbContext.SaveChangesAsync(); } catch (DbUpdateException e) { System.Diagnostics.Trace.TraceError("Tournament CS:GO match update exception: " + e.Message); return(BadRequest("Something went wrong...")); } if (entity == null) { await _dbContext.Entry(match).Reference(m => m.Team1).LoadAsync(); await _dbContext.Entry(match).Reference(m => m.Team2).LoadAsync(); } return(Ok(match)); } return(Unauthorized()); }
public IHttpActionResult DeleteCSGOMatchMap(Guid?id) { if (UserIsInRole("event-admin")) { CSGOMatchMap entity = _dbContext.TournamentCSGOMatchMaps.Find(id); _dbContext.TournamentCSGOMatchMaps.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()); }