Exemple #1
0
        public async Task <IActionResult> CreateTeam([FromBody] TeamSaveResource teamResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var team = mapper.Map <TeamSaveResource, Team>(teamResource);

            team.Users.Add(new UserTeam {
                UserId = teamResource.Captain, Status = true
            });                                                                            //DateJoined = DateTime.Now

            teamRepository.Add(team);
            await unitOfWork.Complete();

            team = await teamRepository.GetTeam(team.Id);

            var result = mapper.Map <Team, TeamResource>(team);

            return(Ok(result));
        }
Exemple #2
0
        public async Task <IActionResult> EditTeam([FromBody] TeamSaveResource teamResource, int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var team = await teamRepository.GetTeam(id);

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

            mapper.Map <TeamSaveResource, Team>(teamResource, team);
            await unitOfWork.Complete();

            //team = await teamRepository.GetTeam(team.Id);

            var result = mapper.Map <Team, TeamResource>(team);

            return(Ok(result));
        }