public async Task <IActionResult> OmlResult([FromBody] OmlScore score) { if (!Request.Cookies.ContainsKey("judgeid")) { return(Unauthorized()); } var judgeId = Request.Cookies["judgeid"]; var teamInBase = from it in _dbContext.OMLScoreBoard where it.Round == score.Round where it.TeamId == score.TeamId select it; if (!teamInBase.Any()) { score.JudgeId = judgeId; await _dbContext.OMLScoreBoard.AddAsync(score); await _dbContext.SaveChangesAsync(); return(Ok()); } var record = teamInBase.First(); if (record.Saved == 1) { return(Forbid()); } record.JudgeId = judgeId; record.BlackBlockState = score.BlackBlockState; record.BlueBlockState = score.BlueBlockState; record.BrokenWall = score.BrokenWall; record.FinishCorrectly = score.FinishCorrectly; record.LiesCorrectly = score.LiesCorrectly; record.LiesIncorrectly = score.LiesIncorrectly; record.None = score.None; record.PartiallyCorrect = score.PartiallyCorrect; record.Saved = score.Saved; record.StaysCorrectly = score.StaysCorrectly; record.StaysIncorrectly = score.StaysIncorrectly; record.TimeMils = score.TimeMils; await _dbContext.SaveChangesAsync(); return(Ok()); }
public OmlItemViewModel(OmlScore omlScore) { _tokenStorage = ServiceProvider.GetService <ITokenStorage>(); _teamId = omlScore.TeamId; _redBlockState = omlScore.RedBlockState; _yellowBlockState = omlScore.YellowBlockState; _greenBlockState = omlScore.GreenBlockState; _whiteBlock1State = omlScore.WhiteBlock1State; _whiteBlock2State = omlScore.WhiteBlock2State; _blueBlockState = omlScore.BlueBlockState; _battaryBlock1State = omlScore.BattaryBlock1State; _battaryBlock2State = omlScore.BattaryBlock2State; _robotState = omlScore.RobotState; _wall1State = omlScore.Wall1State; _wall2State = omlScore.Wall2State; _time1 = omlScore.Time1; _time2 = omlScore.Time2; _saved = omlScore.Saved; }
public async Task <ActionResult <string> > OmlPreResult([FromBody] OmlScore score) { if (!Request.Headers.ContainsKey("token")) { return(BadRequest(ScoreBoardPostError.TokenNotPassed)); } var token = Request.Headers["token"][0]; var payload = JWTJudgeProvider.DecodeToken(token); if (payload == null) { return(BadRequest(ScoreBoardPostError.InvalidToken)); } if (payload.Expires <= DateTime.Now) { return(BadRequest(ScoreBoardPostError.TokenExpired)); } var judgeId = payload.JudgeId; if (score.JudgeId != judgeId) { return(BadRequest(ScoreBoardPostError.RecordPayloadMismatch)); } if (score.Saved == 1) { var hasNulls = score.RedBlockState == null || score.YellowBlockState == null || score.GreenBlockState == null || score.WhiteBlock1State == null || score.WhiteBlock2State == null || score.BlueBlockState == null || score.BattaryBlock1State == null || score.BattaryBlock2State == null || score.RobotState == null || score.Wall1State == null || score.Wall2State == null || score.Time1 == null || score.Time2 == null; if (hasNulls) { return(BadRequest(ScoreBoardPostError.InvalidModelContainsNulls)); } } var teamInBase = from it in _dbContext.OMLPreResults where it.Round == score.Round where it.TeamId == score.TeamId select it; if (!teamInBase.Any()) { score.JudgeId = judgeId; await _dbContext.OMLPreResults.AddAsync(score); await _dbContext.SaveChangesAsync(); var newToken = RefreshTokenInternal(token); return(newToken); } var record = teamInBase.First(); if (record.Saved == 1) { return(BadRequest(ScoreBoardPostError.OverwritingForbidden)); } record.JudgeId = judgeId; record.Tour = score.Tour; record.RedBlockState = score.RedBlockState; record.YellowBlockState = score.YellowBlockState; record.GreenBlockState = score.GreenBlockState; record.WhiteBlock1State = score.WhiteBlock1State; record.WhiteBlock2State = score.WhiteBlock2State; record.BlueBlockState = score.BlueBlockState; record.BattaryBlock1State = score.BattaryBlock1State; record.BattaryBlock2State = score.BattaryBlock2State; record.RobotState = score.RobotState; record.Wall1State = score.Wall1State; record.Wall2State = score.Wall2State; record.Time1 = score.Time1; record.Time2 = score.Time2; record.Saved = score.Saved; await _dbContext.SaveChangesAsync(); var newToken2 = RefreshTokenInternal(token); return(newToken2); }