public async Task <IActionResult> EditFixture(int teamId, int fixtureId, [FromBody] FixtureToCreate fixtureToEditDto) { var teamFromRepo = await _repository.GetTeam(teamId); if (teamFromRepo == null) { return(BadRequest("Team does not exist")); } var fixtureFromRepo = await _repository.GetFixture(fixtureId); if (fixtureFromRepo == null) { return(BadRequest($"Fixture with id {fixtureId} does not exist")); } var fixtureToUpdate = _mapper.Map <FixtureToCreate, Fixture>(fixtureToEditDto, fixtureFromRepo); _repository.Update <Fixture>(fixtureToUpdate); if (await _repository.SaveAllChangesAsync()) { var fixtureToReturn = _mapper.Map <FixtureToReturn>(fixtureToUpdate); return(NoContent()); } throw new Exception($"Error Editing fixture with id {teamId}"); }
public async Task <IActionResult> EditTeam(int id, [FromBody] TeamToCreateDto teamToEditDto) { var teamFromRepo = await _repository.GetTeam(id); if (teamFromRepo == null) { return(BadRequest("Team does not exist")); } var teamToUpdate = _mapper.Map <TeamToCreateDto, Team>(teamToEditDto, teamFromRepo); _repository.Update <Team>(teamToUpdate); if (await _repository.SaveAllChangesAsync()) { var teamToReturn = _mapper.Map <TeamToReturnDto>(teamToUpdate); return(NoContent()); } throw new Exception($"Error Editing team with id {id}"); }