Exemple #1
0
        public async Task EditGame(EditGameDto editedGame)
        {
            using (unitOfWork)
            {
                Game gameEntity = await unitOfWork.GameRepository
                                  .GetSingleAsync(filter : g => g.Id == editedGame.Id);

                if (gameEntity == null)
                {
                    throw new ArgumentException("No such game found");
                }

                //mapping real entity
                EditGameDto mappedGameEnity = mapper.Map <EditGameDto>(gameEntity);

                //changing values of Mapped Entity
                mappedGameEnity = mapper.Map(editedGame, mappedGameEnity);


                //mapping back to real entity
                gameEntity = mapper.Map(editedGame, gameEntity);

                await DeletePlatforms(editedGame.Platforms, gameEntity);
                await DeleteGenres(editedGame.Genres, gameEntity);

                unitOfWork.GameRepository.Update(gameEntity);

                await unitOfWork.CommitAsync();
            }
        }
Exemple #2
0
        public async Task <IActionResult> EditGame(Guid id, [FromBody] EditGameDto editGameDto)
        {
            var token = await HttpContext.GetTokenAsync("access_token");

            if (await _logic.GetGameById(id, token) == null)
            {
                return(NotFound("Game with that ID was not found."));
            }
            return(Ok(await _logic.EditGame(id, editGameDto, token)));
        }
Exemple #3
0
        public async Task <IActionResult> EditGame(int id, [FromBody] GameCreateModel game)
        {
            EditGameDto dto = new EditGameDto()
            {
                Id          = id,
                Description = game.Description,
                Genres      = game.Genres,
                Name        = game.Name,
                Platforms   = game.Platforms,
                PublisherId = game.PublisherId
            };

            await gameService.EditGame(dto);

            return(StatusCode((int)HttpStatusCode.NoContent));
        }
Exemple #4
0
        public IActionResult Put(int id, [FromBody] EditGameDto dto)
        {
            try
            {
                var user = context.Users.Find(id);
                if (user == null)
                {
                    return(NotFound());
                }

                editGame.Execute(dto);
                return(NoContent());
            }
            catch (NotFoundEx e)
            {
                return(UnprocessableEntity(e.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
        public void Execute(EditGameDto request)
        {
            var game = context.Games.Find(request.Id);

            if (game == null)
            {
                throw new NotFoundEx();
            }

            if (game.Title != null)
            {
                game.Title = request.Title;
            }
            else
            {
                throw new NotFoundEx();
            }

            if (game.Picture != null)
            {
                game.Picture = request.Picture;
            }
            else
            {
                throw new NotFoundEx();
            }

            if (game.Picture != null)
            {
                game.Picture = request.Picture;
            }
            else
            {
                throw new NotFoundEx();
            }
        }
Exemple #6
0
        /// <summary>
        /// Edit a Game
        /// </summary>
        /// <param name="id">GameID</param>
        /// <param name="editGameDto">New information</param>
        /// <returns>modified Game</returns>
        public async Task <GameDto> EditGame(Guid id, EditGameDto editGameDto, string token)
        {
            Game editedGame = await _repo.GetGameById(id);

            if (editedGame.GameDate != editGameDto.GameDate && editGameDto.GameDate != null)
            {
                editedGame.GameDate = (DateTime)editGameDto.GameDate;
            }
            if (editedGame.WinningTeam != editGameDto.WinningTeamID && editGameDto.GameDate != null)
            {
                editedGame.WinningTeam = (Guid)editGameDto.WinningTeamID;
            }
            if (editedGame.HomeScore != editGameDto.HomeScore && editGameDto.GameDate != null)
            {
                editedGame.HomeScore = (int)editGameDto.HomeScore;
            }
            if (editedGame.AwayScore != editGameDto.AwayScore && editGameDto.GameDate != null)
            {
                editedGame.AwayScore = (int)editGameDto.AwayScore;
            }

            await _repo.CommitSave();

            Team homeTeam = new Team();
            Team awayTeam = new Team();

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                var response = await httpClient.GetAsync($"http://20.62.247.144:80/api/Team/{editedGame.HomeTeamID}");

                var apiResponse = await response.Content.ReadAsStringAsync();

                homeTeam = JsonConvert.DeserializeObject <Team>(apiResponse);

                response = await httpClient.GetAsync($"http://20.62.247.144:80/api/Team/{editedGame.AwayTeamID}");

                apiResponse = await response.Content.ReadAsStringAsync();

                awayTeam = JsonConvert.DeserializeObject <Team>(apiResponse);
            }
            GameDto gameDto = new GameDto
            {
                GameID        = editedGame.GameID,
                GameDate      = editedGame.GameDate,
                HomeScore     = editedGame.HomeScore,
                AwayScore     = editedGame.AwayScore,
                AwayTeam      = awayTeam,
                HomeTeam      = homeTeam,
                HomeTeamID    = editedGame.HomeTeamID,
                AwayTeamID    = editedGame.AwayTeamID,
                SeasonID      = editedGame.SeasonID,
                WinningTeamID = editedGame.WinningTeam
            };

            if (editedGame.WinningTeam == editedGame.AwayTeamID)
            {
                gameDto.WinningTeam = awayTeam;
            }
            if (editedGame.WinningTeam == editedGame.HomeTeamID)
            {
                gameDto.WinningTeam = homeTeam;
            }
            return(gameDto);
        }