public async Task <IActionResult> DeleteGameFromVault([FromBody] DeleteGameRequest request)
        {
            var result = await _operationFactory.Create <DeleteGameFromVaultCommand>(x =>
            {
                x.GameId = request.GameId;
                x.UserId = HttpContext.GetUserId();
            }).HandleAsync();

            if (result.HasFailed())
            {
                return(BadRequest(result.Errors));
            }

            return(Ok());
        }
Example #2
0
 public async Task <DeleteGameResult> DeleteGame(DeleteGameRequest request)
 {
     try
     {
         DynamicParameters parameters = new DynamicParameters();
         parameters.Add("@IdGame", request.IdGame);
         return(await SqlMapper.QueryFirstOrDefaultAsync <DeleteGameResult>(cnn : connect,
                                                                            sql : "sp_DeleteGames",
                                                                            param : parameters,
                                                                            commandType : CommandType.StoredProcedure));
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        public Task DeleteGameAsync(GameDTO targetGame, long relativeTeamId, CancellationTokenSource cancellationTokenSource) =>
        Task.Run(async() => {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION);
            }

            DeleteGameRequest deleteGameRequest = new DeleteGameRequest()
            {
                AccessToken = GlobalSettings.Instance.UserProfile.AccesToken,
                Url         = string.Format(GlobalSettings.Instance.Endpoints.ScheduleEndpoints.DeleteGame, targetGame.Id),
                Data        = new DeleteGameDataModel()
                {
                    GameId = targetGame.Id,
                    TeamId = relativeTeamId
                }
            };

            try {
                DeleteGameResponse deleteGameResponse = await _requestProvider.PostAsync <DeleteGameRequest, DeleteGameResponse>(deleteGameRequest);

                if (deleteGameResponse == null)
                {
                    throw new InvalidOperationException(DELETE_GAME_COMMON_ERROR_MESSAGE);
                }
            }
            catch (HttpRequestExceptionEx exc) {
                DeleteGameResponse deleteGameBadResponse = JsonConvert.DeserializeObject <DeleteGameResponse>(exc.Message);

                string output = string.Format("{0}",
                                              deleteGameBadResponse.Errors?.FirstOrDefault());

                output = (string.IsNullOrWhiteSpace(output) || string.IsNullOrEmpty(output)) ? DELETE_GAME_COMMON_ERROR_MESSAGE : output.Trim();

                throw new InvalidOperationException(output);
            }
            catch (Exception exc) {
                Crashes.TrackError(exc);

                throw;
            }
        }, cancellationTokenSource.Token);
        public IActionResult Delete([FromBody] DeleteGameRequest deleteReq)
        {
            Player player = (Player)HttpContext.Items["Player"];

            NotAllowedResponse     na  = new NotAllowedResponse();
            BadRequestObjectResult res = new BadRequestObjectResult(na);

            res.StatusCode = 400; // TODO, find correct HTTP resp. code

            Race race = raceRepo.Find(deleteReq.gameId);

            if (race == null)
            {
                na.message = "No such race with id '" + deleteReq.gameId + "' exists.";
            }

            if (!race.getOwner().Equals(player))
            {
                na.message = "You're not the owner of this race.";
            }

            if (race.GetState() != Race.State.notStarted)
            {
                na.message = "You can't delete a game in progress.";
            }

            bool deletionOk = raceRepo.Delete(race);

            if (!deletionOk)
            {
                // TODO, Internal 500?
            }

            if (na.message != "")
            {
                return(res);
            }

            return(new OkResult());
        }
Example #5
0
 public async Task <DeleteGameResult> DeleteGame(DeleteGameRequest request)
 {
     return(await gameRepository.DeleteGame(request));
 }
Example #6
0
 public async Task <OkObjectResult> Delete(DeleteGameRequest request)
 {
     return(Ok(await gameService.DeleteGame(request)));
 }