Ejemplo n.º 1
0
        public IActionResult UpdateTournament(int id, [FromBody] TournamentForUpdateDto tournament)
        {
            if (tournament == null)
            {
                return(BadRequest());
            }

            var tournamentForUpdate = _tournamentKeeperRepository.GeTournament(id);

            if (tournamentForUpdate == null)
            {
                return(NotFound());
            }

            Mapper.Map(tournament, tournamentForUpdate);
            if (!_tournamentKeeperRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public IActionResult UpdateTournament(Guid id,
                                              [FromBody] TournamentForUpdateDto tournament)
        {
            if (tournament == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(new UnprocessableEntityObjectResult(ModelState));
            }

            var tournamentFromRepo = _hartPRRepository.GetTournament(id);

            if (tournamentFromRepo == null)
            {
                //not seeing a reason to add upsert implementation to tournament currently.
                return(NotFound());
            }

            //map

            //apply update

            //map update dto back to entity

            Mapper.Map(tournament, tournamentFromRepo); //TODO: Check if this needs to be configured
            tournamentFromRepo.UpdatedAt = new DateTimeOffset(DateTime.Now);

            _hartPRRepository.UpdateTournament(tournamentFromRepo);

            if (!_hartPRRepository.Save())
            {
                throw new Exception($"Updating tournament {id} failed on save.");
            }

            return(NoContent());
        }