Пример #1
0
        public async Task <ActionResult> RecordFoul(RecordFoulRequest 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"));
            }

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

            var newScoringLog = await this.FoulLogRepository.RecordFoul(log);

            return(new OkObjectResult(newScoringLog));
        }
Пример #2
0
        public async Task <IActionResult> SaveRecordedFoul(int period, int minutes, int seconds, 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"));
            }

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

            string errorMsg = "";
            var    foulLog  = this.ApiClient.Post <FoulLog>("Scoring/RecordFoul", JsonConvert.SerializeObject(apiRequest), ref errorMsg);

            if (foulLog != null)
            {
                Connector.UndoLog.Add(new Models.UndoLogEntry()
                {
                    Id = foulLog.FouldLogId, Type = Models.UndoLogType.Foul
                });
                return(new OkObjectResult("Foul Saved"));
            }

            return(new BadRequestObjectResult(errorMsg));
        }