public TeamModel UpdateTeam(TeamModel model) { var team = _mapper.Map <Entities.Team.Team>(model); DeleteTeamMembers(model.Id); var members = AddTeamMembers(model.Members); _context.Update(team); _context.SaveChanges(); foreach (var member in members) { _context.TeamMembers.Add(new TeamMembers { TeamId = team.Id, TeamMemberId = member.Id }); } _context.SaveChanges(); return(_mapper.Map <TeamModel>(team)); }