Пример #1
0
        public async Task CreateBuilderNotification(string builderId, string content)
        {
            BuilderNotification notification = new BuilderNotification()
            {
                BuilderId = builderId,
                Date      = DateTime.Now,
                Content   = content,

                Seen = false
            };

            await _builderNotifications.InsertOneAsync(notification);
        }
Пример #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);
        }
Пример #3
0
        public async Task MakeBuilderNotificationReadAsync(string builderId, string notificationId)
        {
            BuilderNotification notification = await GetBuilderNotification(notificationId);

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

            if (notification.BuilderId != builderId)
            {
                throw new UnauthorizedAccessException("You are not the builder for this notifiction");
            }

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

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