public async Task <Band> Get(int id) { var dbBand = await dbContext .Set <Entities.Band>() .Include(b => b.Boss) .ThenInclude(b => b.Bandit) .Include(b => b.Members) .ThenInclude(bm => bm.Bandit) .Include(b => b.Members) .ThenInclude(bm => bm.Scoring) .Include(b => b.Rounds) .ThenInclude(r => r.Sheriff) .ThenInclude(rm => rm.Member) .ThenInclude(bm => bm.Bandit) .FirstOrDefaultAsync(b => b.Id == id); if (dbBand == null) { return(null); } var boss = Bandit.Create(dbBand.Boss.Bandit.Id, dbBand.Boss.Bandit.Name, dbBand.Boss.Bandit.Email); var band = Band.Create(dbBand.Id, dbBand.Name, boss); foreach (var dbMember in dbBand.Members) { if (dbMember.Bandit.Id == band.Boss.Bandit.Id) { band.Members.Add(band.Boss); continue; } var bandit = Bandit.Create(dbMember.Bandit.Id, dbMember.Bandit.Name, dbMember.Bandit.Email); var member = BandMember.From(bandit, band); var score = dbMember.Scoring.ToModel(); member.Scoring.Add(score); band.Members.Add(member); } foreach (var dbRound in dbBand.Rounds) { var dbBandit = dbRound.Sheriff.Member.Bandit; var bandit = Bandit.Create(dbBandit.Id, dbBandit.Name, dbBandit.Email); var sheriff = BandMember.From(bandit, band); var round = Round.Create(dbRound.Id, dbRound.Name, dbRound.Place, dbRound.DateTime, sheriff, Enumerable.Empty <BandMember>()); band.Rounds.Add(round); } return(band); }
public async Task <DTOs.Notification> Invite(DTOs.InviteJoinBand request) { var host = await banditRepository.Get(request.Host.Id); if (host == null) { throw new NotFoundException("Bandit", request.Host.Id); } var guest = await banditRepository.Get(request.Guest.Id); if (guest == null) { throw new NotFoundException("Bandit", request.Guest.Id); } var band = await bandRepository.Get(request.Band.Id); if (band == null) { throw new NotFoundException("Band", request.Band.Id); } if (!band.IsMember(host)) { throw new InvalidOperationException(Strings.CantInviteToJoin.Format(host.Name, guest.Name, band.Name)); } var member = BandMember.From(host, band); if (!member.CanInviteToJoin(guest)) { throw new InvalidOperationException(Strings.CantInviteToJoin.Format(host.Name, guest.Name, band.Name)); } var invitation = Invitation.Create(guest, band, guest); await invitationRepository.Add(invitation); var message = Notifications.InviteJoinBand(host.Name, band.Name); await notifications.Send(message, to : guest); return(new DTOs.Notification { To = guest.Name, Title = message.Title, Content = message.Body }); }
public async Task <DTOs.Invitation> Handle(DTOs.HandleInvitation request) { var invitation = await invitationRepository.Get(request.Invitation.Id); if (invitation == null) { throw new NotFoundException("Invitation", request.Invitation.Id); } await invitationRepository.Remove(invitation.Id); if (!request.Accept) { return(invitation.ToDto()); } var bandMember = BandMember.From(invitation.Guest, invitation.Band); await bandRepository.AddMember(bandMember); return(invitation.ToDto()); }
public async Task <Bandit> FindByEmail(string email) { var dbBandit = await dbContext .Set <Entities.Bandit>() .Include(b => b.Scoring) .Include(b => b.Bands) .ThenInclude(bm => bm.Band) .ThenInclude(b => b.Boss) .ThenInclude(bm => bm.Bandit) .Include(b => b.Bands) .ThenInclude(bm => bm.Scoring) .FirstOrDefaultAsync(b => b.Email == email); if (dbBandit == null) { return(null); } var bandit = Bandit.Create(dbBandit.Id, dbBandit.Name, dbBandit.Email); var score = dbBandit.Scoring.ToModel(); bandit.Scoring.Add(score); foreach (var dbBand in dbBandit.Bands) { var dbBoss = dbBand.Band.Boss.Bandit; var boss = Bandit.Create(dbBoss.Id, dbBoss.Name, dbBoss.Email); var band = Band.Create(dbBand.Band.Id, dbBand.Band.Name, boss); var scoring = dbBand.Scoring.ToModel(); var bandMember = BandMember.From(bandit, band); bandMember.Scoring.Add(scoring); bandit.Bands.Add(bandMember); } return(bandit); }
public async Task <IQueryable <Band> > Get() { var dbBands = dbContext .Set <Entities.Band>() .Include(b => b.Boss) .ThenInclude(bm => bm.Bandit) .Include(b => b.Rounds) .ThenInclude(r => r.Sheriff) .ThenInclude(rm => rm.Member) .ThenInclude(bm => bm.Bandit); await dbBands.LoadAsync(); var bands = dbBands .AsEnumerable() .Select(b => { var boss = Bandit.Create(b.Boss.Bandit.Id, b.Boss.Bandit.Name, b.Boss.Bandit.Email); var band = Band.Create(b.Id, b.Name, boss); foreach (var dbRound in b.Rounds) { var dbBandit = dbRound.Sheriff.Member.Bandit; var bandit = Bandit.Create(dbBandit.Id, dbBandit.Name, dbBandit.Email); var sheriff = BandMember.From(bandit, band); var round = Round.Create(dbRound.Id, dbRound.Name, dbRound.Place, dbRound.DateTime, sheriff, Enumerable.Empty <BandMember>()); band.Rounds.Add(round); } return(band); }) .AsQueryable(); return(bands); }