public async Task <ServiceResponse <GetTournamentDto> > UpdateTournament(UpdateTournamentDto updateTournament) { ServiceResponse <GetTournamentDto> serviceResponse = new ServiceResponse <GetTournamentDto>(); try { webApi.Models.Tournament tournament = await _context.Tournaments .Include(c => c.user) .FirstOrDefaultAsync(c => c.TournamentId == updateTournament.TournamentId); if (tournament.user.Id == GetUserId()) { tournament.TournamentName = updateTournament.TournamentName; _context.Tournaments.Update(tournament); await _context.SaveChangesAsync(); serviceResponse.Data = _mapper.Map <GetTournamentDto>(tournament); } else { serviceResponse.Success = false; serviceResponse.Message = "Tournament not found"; } } catch (Exception ex) { serviceResponse.Success = false; serviceResponse.Message = ex.Message; } return(serviceResponse); }
public async Task <IActionResult> UpdateTournament(UpdateTournamentDto updateTournament) //Update Tournament { ServiceResponse <GetTournamentDto> response = await _tournamentService.UpdateTournament(updateTournament); if (response.Data == null) { return(NotFound(response)); } return(Ok(response)); }