Пример #1
0
        public async Task <DTOs.Notification> Invite(DTOs.JoinApp request)
        {
            var bandit = await banditRepository.FindByEmail(request.GuestEmail);

            if (bandit != null)
            {
                throw new InvalidOperationException(Strings.EmailAlreadyUsed.Format(request.GuestEmail));
            }

            var host = await banditRepository.Get(request.Host.Id);

            if (host == null)
            {
                throw new NotFoundException("Bandit", request.Host.Id);
            }

            bandit = Bandit
                     .Create("New Bandit", request.GuestEmail);

            var message = Notifications.JoinApp(host.Name);

            await notifications.Send(message, to : bandit);

            return(new DTOs.Notification
            {
                To = request.GuestEmail,
                Title = message.Title,
                Content = message.Body
            });
        }
        public async Task <Notification> Remove(int id)
        {
            var notification = await dbContext
                               .Set <Entities.Notification>()
                               .Include(n => n.Bandit)
                               .FirstOrDefaultAsync(n => n.Id == id);

            if (notification == null)
            {
                return(null);
            }

            var bandit = Bandit.Create(notification.Bandit.Id,
                                       notification.Bandit.Name,
                                       notification.Bandit.Email);

            var notif = Notification.For(
                notification.Id,
                bandit,
                notification.Title,
                notification.Body);

            dbContext
            .Set <Entities.Notification>()
            .Remove(notification);

            await dbContext.SaveChangesAsync();

            return(notif);
        }
Пример #3
0
        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);
        }
Пример #4
0
        public async Task <DTOs.BanditDetails> Create(DTOs.CreateBandit request)
        {
            var bandit = await banditRepository.FindByEmail(request.Email);

            if (bandit != null)
            {
                throw new InvalidOperationException(Strings.EmailAlreadyUsed.Format(request.Email));
            }

            bandit = Bandit.Create(request.Name, request.Email);
            bandit = await banditRepository.Add(bandit);

            return(bandit.ToDtoDetails());
        }
Пример #5
0
        public async Task <Bandit> Add(Bandit bandit)
        {
            var dbBandit = new Entities.Bandit
            {
                Name    = bandit.Name,
                Email   = bandit.Email.Address,
                Scoring = new Entities.Score()
            };

            await dbContext
            .Set <Entities.Bandit>()
            .AddAsync(dbBandit);

            await dbContext.SaveChangesAsync();

            return(Bandit.Create(dbBandit.Id, dbBandit.Name, dbBandit.Email));
        }
        public async Task <Invitation> Remove(int id)
        {
            var invitation = await dbContext
                             .Set <Entities.Invitation>()
                             .Include(i => i.Guest)
                             .Include(i => i.Band)
                             .ThenInclude(b => b.Boss)
                             .ThenInclude(b => b.Bandit)
                             .Include(i => i.Handler)
                             .FirstOrDefaultAsync(i => i.Id == id);

            if (invitation == null)
            {
                return(null);
            }

            var guest = Bandit.Create(invitation.Guest.Id,
                                      invitation.Guest.Name,
                                      invitation.Guest.Email);

            var handler = Bandit.Create(invitation.Handler.Id,
                                        invitation.Handler.Name,
                                        invitation.Handler.Email);

            var boss = Bandit.Create(invitation.Band.Boss.Bandit.Id,
                                     invitation.Band.Boss.Bandit.Name,
                                     invitation.Band.Boss.Bandit.Email);

            var band = Band.Create(invitation.Band.Id,
                                   invitation.Band.Name,
                                   boss);

            var invite = Invitation.Create(invitation.Id, guest, band, handler);

            dbContext
            .Set <Entities.Invitation>()
            .Remove(invitation);

            await dbContext.SaveChangesAsync();

            return(invite);
        }
Пример #7
0
        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);
        }
Пример #8
0
        public async Task <IQueryable <Bandit> > Get()
        {
            var dbBandits = dbContext
                            .Set <Entities.Bandit>()
                            .Include(b => b.Scoring);

            await dbBandits.LoadAsync();

            var bandits = dbBandits
                          .AsEnumerable()
                          .Select(b => {
                var bandit = Bandit.Create(b.Id, b.Name, b.Email);
                var score  = b.Scoring.ToModel();

                bandit.Scoring.Add(score);
                return(bandit);
            })
                          .AsQueryable();


            return(bandits);
        }
        public async Task <IQueryable <Invitation> > GetFor(int banditId)
        {
            var dbInvitations = dbContext
                                .Set <Entities.Invitation>()
                                .Include(i => i.Guest)
                                .Include(i => i.Band)
                                .ThenInclude(b => b.Boss)
                                .ThenInclude(b => b.Bandit)
                                .Include(i => i.Handler)
                                .Where(i => i.HandlerId == banditId);

            await dbInvitations.LoadAsync();

            var invitations = dbInvitations
                              .AsEnumerable()
                              .Select(i => {
                var guest = Bandit.Create(i.Guest.Id,
                                          i.Guest.Name,
                                          i.Guest.Email);

                var handler = Bandit.Create(i.Handler.Id,
                                            i.Handler.Name,
                                            i.Handler.Email);

                var boss = Bandit.Create(i.Band.Boss.Bandit.Id,
                                         i.Band.Boss.Bandit.Name,
                                         i.Band.Boss.Bandit.Email);

                var band = Band.Create(i.Band.Id,
                                       i.Band.Name,
                                       boss);

                return(Invitation.Create(i.Id, guest, band, handler));
            })
                              .AsQueryable();

            return(invitations);
        }
        public async Task <IQueryable <Notification> > GetFor(int banditId)
        {
            var dbBandit = await dbContext
                           .Set <Entities.Bandit>()
                           .Include(b => b.Notifications)
                           .FirstOrDefaultAsync(b => b.Id == banditId);

            if (dbBandit == null)
            {
                throw new NotFoundException("Bandit", banditId);
            }

            var bandit = Bandit.Create(dbBandit.Id, dbBandit.Name, dbBandit.Email);

            return(dbBandit.Notifications
                   .Select(n => {
                var notif = Notification
                            .For(n.Id, bandit, n.Title, n.Body);

                return notif;
            })
                   .AsQueryable());
        }
Пример #11
0
        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);
        }