public override IEnumerable <Team> Execute(GetUserOwnedTeamsQuery query, ICommandAndQueryDispatcher dispatcher) { return(db.Teams .Include(x => x.Owner) .Include(x => x.Members.Select(m => m.User)) .Where(x => x.Owner.Id == query.UserId).ToList()); }
public override void Execute(CreateNewTeamCommand command, ICommandAndQueryDispatcher dispatcher) { if (!command.TeamName.HasValue) { throw new ArgumentException("The team name was invalid, it cannot be blank."); } var teamExistsQuery = new GetUserOwnedTeamsQuery(command.TeamOwnerId.Id); if (dispatcher.ExecuteQuery(teamExistsQuery).Any(t => t.Name == command.TeamName.Value)) { //team with this name already exists, so we can't add a new one throw new ArgumentException( string.Format("The team name was invalid. A team called '{0}' already exists.", command.TeamName.Value)); } var team = new Team(command.TeamName.Value, command.TeamOwnerId); db.Teams.Add(team); db.SaveChanges(); command.TeamId = team.Id; }