Esempio n. 1
0
        public async Task <IActionResult> SaveRecordedPoints(int period, int minutes, int seconds, int points, int playerId)
        {
            var GameTime = new TimeSpan(0, (period - 1) * 12, 0) + (new TimeSpan(0, 12, 0) - new TimeSpan(0, minutes, seconds));

            if (!await this.CheckLoginStatus())
            {
                return(new BadRequestObjectResult("Something Went Wrong"));
            }

            if (Connector.Game == null || Connector.Game.GameComplete)
            {
                return(new BadRequestObjectResult("Game Not Available"));
            }
            if (Connector.League == null)
            {
                return(new BadRequestObjectResult("League Not Available"));
            }

            RecordScoreRequest apiRequest = new RecordScoreRequest
            {
                ApiToken  = Connector.CurrentApiToken,
                GameTime  = GameTime,
                Points    = points,
                PlayerId  = playerId,
                GameId    = Connector.Game.GameId,
                LeagueKey = Connector.League.LeagueKey
            };

            string errorMsg   = "";
            var    scoringLog = this.ApiClient.Post <ScoringLog>("Scoring/RecordScore", JsonConvert.SerializeObject(apiRequest), ref errorMsg);

            if (scoringLog != null)
            {
                Connector.UndoLog.Add(new Models.UndoLogEntry()
                {
                    Id = scoringLog.ScoringLogId, Type = Models.UndoLogType.Score, Points = scoringLog.Points
                });
                return(new OkObjectResult("Score Saved"));
            }

            return(new BadRequestObjectResult(errorMsg));
        }
Esempio n. 2
0
        public async Task <ActionResult> RecordScore(RecordScoreRequest request)
        {
            if (!await this.IsAPITokenValid(request.ApiToken))
            {
                return(new BadRequestObjectResult("UnAuthorized"));
            }

            string leagueId = await this.GetLeagueId(request.LeagueKey);

            if (leagueId == null)
            {
                return(new BadRequestObjectResult("League Not Found"));
            }

            if (await this.GameRepository.GetAsync(request.GameId) == null)
            {
                return(new BadRequestObjectResult("Game Not Found"));
            }

            if (await this.PlayerRepository.GetAsync(request.PlayerId) == null)
            {
                return(new BadRequestObjectResult("Player Not Found"));
            }

            ScoringLog log = new ScoringLog
            {
                GameTime = request.GameTime,
                Points   = request.Points,
                PlayerId = request.PlayerId,
                GameId   = request.GameId
            };

            var newScoringLog = await this.ScoringLogRepository.RecordScore(log);

            return(new OkObjectResult(newScoringLog));
        }