Ejemplo n.º 1
0
        // News
        public async Task CreateCoachNotification(string coachId, string content)
        {
            CoachNotification notification = new CoachNotification()
            {
                CoachId = coachId,
                Date    = DateTime.Now,
                Content = content,

                Seen = false
            };

            await _coachNotifications.InsertOneAsync(notification);
        }
Ejemplo n.º 2
0
        public async Task NotifyAllAsync(string content)
        {
            List <Builder> builders = await(await _builders.FindAsync(dbBuilder => true)).ToListAsync();
            List <Coach>   coachs   = await(await _coachs.FindAsync(dbCoach => true)).ToListAsync();

            List <BuilderNotification> builderNotifications = new List <BuilderNotification>();
            List <CoachNotification>   coachNotifications   = new List <CoachNotification>();

            foreach (var builder in builders)
            {
                BuilderNotification notification = new BuilderNotification()
                {
                    BuilderId = builder.Id,
                    Date      = DateTime.Now,
                    Content   = content,

                    Seen = false
                };

                builderNotifications.Add(notification);
            }

            foreach (var coach in coachs)
            {
                CoachNotification notification = new CoachNotification()
                {
                    CoachId = coach.Id,
                    Date    = DateTime.Now,
                    Content = content,

                    Seen = false
                };

                coachNotifications.Add(notification);
            }

            await _builderNotifications.InsertManyAsync(builderNotifications);

            await _coachNotifications.InsertManyAsync(coachNotifications);
        }
Ejemplo n.º 3
0
        public async Task MakeCoachNotificationReadAsync(string coachId, string notificationId)
        {
            CoachNotification notification = await GetCoachNotification(notificationId);

            if (notification == null)
            {
                throw new Exception("The notification seems to not exist anymore");
            }

            if (notification.CoachId != coachId)
            {
                throw new UnauthorizedAccessException("You are not the coach for this notifiction");
            }

            var update = Builders <CoachNotification> .Update
                         .Set(databaseNotification => databaseNotification.Seen, true);

            await _coachNotifications.UpdateOneAsync(databaseNotification =>
                                                     databaseNotification.Id == notificationId,
                                                     update
                                                     );
        }