public async Task <IActionResult> GetKit(int squadId, int id) { var squad = await _squadService.GetDetailByIdAsync(squadId); if (squad == null) { return(NotFound()); } var kit = await _kitService.GetByIdAsync(id); if (kit == null) { return(NotFound()); } if (squad.Kits.All(k => k.Id != id)) { return(BadRequest()); } var returnKit = _mapper.Map <KitDetailDto>(kit); return(Ok(returnKit)); }
public async Task <IActionResult> GetSquad(int id) { var squad = await _squadService.GetDetailByIdAsync(id); if (squad == null) { return(NotFound()); } var returnSquad = _mapper.Map <SquadDetailDto>(squad); return(Ok(returnSquad)); }
public async Task <IActionResult> AddPlayerToSquad(int squadId, [FromBody] SquadPlayerAddDto squadPlayerAddDto) { var squad = await _squadService.GetDetailByIdAsync(squadId); if (squad == null) { return(NotFound()); } var player = await _playerService.GetDetailByIdAsync(squadPlayerAddDto.PlayerId); if (player == null) { return(NotFound()); } if (player.SquadPlayers.Any(sp => sp.Squad.SeasonId == squad.SeasonId)) { return(BadRequest()); } if (squad.SquadPlayers.Any(sp => sp.Number == squadPlayerAddDto.Number)) { return(BadRequest()); } if (squadPlayerAddDto.StartDate < player.Birthdate) { return(BadRequest()); } if (squadPlayerAddDto.EndDate.HasValue && squadPlayerAddDto.EndDate.Value < squadPlayerAddDto.StartDate) { return(BadRequest()); } squad.SquadPlayers.Add(new SquadPlayer { Squad = squad, Player = player, Number = squadPlayerAddDto.Number, StartDate = squadPlayerAddDto.StartDate, EndDate = squadPlayerAddDto.EndDate }); await _squadService.UpdateAsync(squad); return(Ok()); }