Esempio n. 1
0
        public async Task <IActionResult> CreateTeam([FromBody] TeamToCreateDto teamToCreateDto)
        {
            if (await _repository.TeamExists(teamToCreateDto.Name))
            {
                return(BadRequest("Team name exists"));
            }
            var teamToCreate = _mapper.Map <Team>(teamToCreateDto);

            _repository.Add <Team>(teamToCreate);
            if (await _repository.SaveAllChangesAsync())
            {
                var teamToReturn = _mapper.Map <TeamToReturnDto>(teamToCreate);
                return(CreatedAtRoute("GetTeam", new { id = teamToReturn.Id }, teamToReturn));
            }
            return(BadRequest("An Error occurred while creating Team"));
        }
Esempio n. 2
0
        public async Task <IActionResult> CreateTeamFixture(int teamId, [FromBody] FixtureToCreate fixtureToCreateDto)
        {
            fixtureToCreateDto.TeamId = teamId;
            var teamFromRepo = await _repository.GetTeam(teamId);

            if (teamFromRepo == null)
            {
                return(BadRequest("Team does not exist"));
            }
            var fixtureToCreate = _mapper.Map <Fixture>(fixtureToCreateDto);

            _repository.Add <Fixture>(fixtureToCreate);
            if (await _repository.SaveAllChangesAsync())
            {
                var fixtureToReturn = _mapper.Map <TeamToReturnDto>(fixtureToCreate);
                return(CreatedAtRoute("GetFixture", new { id = fixtureToReturn.Id }, fixtureToReturn));
            }
            return(BadRequest("An Error occurred while creating the fixture"));
        }