Exemplo n.º 1
0
        public IActionResult Post(TeamDTO model)
        {
            Team item = new Team();

            model.UpdateFromModel(item);

            foreach (int id in model.MemberIds)
            {
                User member = _userRepo.GetById(id);
                item.Members.Add(new TeamMember {
                    Team = item, Member = member
                });
            }

            _teamRepo.Add(item);
            _teamRepo.SaveChanges();

            TeamDTO dto = new TeamDTO {
                Id        = item.Id,
                Name      = item.Name,
                LeadId    = item.LeadId,
                MemberIds = item.Members.Select(x => x.MemberId)
            };

            return(CreatedAtAction(nameof(GetAll), dto));
        }
Exemplo n.º 2
0
        public IActionResult Put(int id, TeamDTO model)
        {
            Team item = _teamRepo.GetById(id);

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

            model.UpdateFromModel(item);

            item.Members.Clear();
            foreach (int memberId in model.MemberIds)
            {
                User member = _userRepo.GetById(memberId);
                item.Members.Add(new TeamMember {
                    Team = item, Member = member
                });
            }

            _teamRepo.SaveChanges();

            return(NoContent());
        }