public async Task <IActionResult> PutTeam(string id, Team team) { if (id != team.Code) { return(BadRequest()); } _context.Entry(team).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeamExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <IEnumerable <object> > > CreateGameStates() { var exists = await _context.GameStates.ToListAsync(); if (exists.Any()) { throw new Exception("State is not empty!"); } var teams = await _context.Teams.ToListAsync(); var ciphers = await _context.Ciphers.ToListAsync(); int counter = 0; foreach (var team in teams) { int order = 0; foreach (var cipher in ciphers) { _context.GameStates.Add(new GameState { Id = ++counter, Order = ++order, Team = team, Cipher = cipher, IsPlaceFound = false, IsAnswerFound = false }); } } await _context.SaveChangesAsync(); return(await _context.GameStates .Select(x => new { TeamCode = x.TeamCode, CipherCode = x.Cipher.Code, IsPlaceFound = x.IsPlaceFound, IsAnswerFound = x.IsAnswerFound, }) .ToListAsync()); }
public async Task <ActionResult <IEnumerable <AuditLog> > > DeleteAuditLogs() { var logs = await _context.AuditLogs.ToArrayAsync(); foreach (var log in logs) { _context.AuditLogs.Remove(log); } await _context.SaveChangesAsync(); return(await _context.AuditLogs.ToListAsync()); }
public async Task <ActionResult <TeamStateModel> > SetPlaceCode([FromForm] string teamCode, [FromForm] string placeCode) { await LogActivity(teamCode, $"SetPlaceCode(teamCode:{teamCode}, placeCode: {placeCode})"); try { var(state, errorModel) = GetFirstUnresolvedState(teamCode); if (state == null) { await LogActivity(teamCode, $"SetPlaceCode returns: {errorModel}"); return(errorModel); } if (state.IsPlaceFound) { await LogActivity(teamCode, $"SetPlaceCode returns: {errorModel}"); return(errorModel); } if (string.IsNullOrWhiteSpace(placeCode)) { errorModel.Message = "Není vyplněný kód stanoviště"; await LogActivity(teamCode, $"SetPlaceCode returns: {errorModel}"); // we dont send cipherCode on this place errorModel.CipherCode = string.Empty; return(errorModel); } if (state.Cipher.Code.ToUpper() == placeCode.ToUpper()) { state.IsPlaceFound = true; await _context.SaveChangesAsync(); errorModel.IsPlaceFound = true; errorModel.Message = "Kód stanoviště je správný!"; await LogActivity(teamCode, $"SetPlaceCode returns: {errorModel}"); return(errorModel); } errorModel.Message = "Kód stanoviště není správný"; await LogActivity(teamCode, $"SetPlaceCode returns: {errorModel}"); // we dont send cipherCode on this place errorModel.CipherCode = string.Empty; return(errorModel); }catch (Exception exc) { await LogActivity(teamCode, $"Exception: {exc}"); return(new TeamStateModel { TeamName = teamCode, Message = exc.Message, CipherCode = string.Empty, IsPlaceFound = false }); } }