Пример #1
0
        private PaginatedList <NotificationDetails> GetNotifications(NotificationQuery query)
        {
            Trace.Assert(Context.SchoolLocalId.HasValue);
            Trace.Assert(Context.PersonId.HasValue);

            using (var uow = Read())
            {
                if (BaseSecurity.IsDistrictAdmin(Context))
                {
                    query.SchoolId = Context.SchoolLocalId.Value;
                }
                query.PersonId = Context.PersonId.Value;
                query.RoleId   = Context.RoleId;
                var notifications = new NotificationDataAccess(uow).GetPaginatedNotificationsDetails(query, !Context.MessagingDisabled);
                var classIds      = notifications.Where(x => x.AnnouncementRef.HasValue && x.Announcement is ClassAnnouncement)
                                    .Select(x => (x.Announcement as ClassAnnouncement).ClassRef)
                                    .ToList();
                IList <ClassAnnouncementType> classAnnouncementTypes = ServiceLocator.ClassAnnouncementTypeService.GetClassAnnouncementTypes(classIds);
                foreach (var notification in notifications)
                {
                    var classAnn = notification.Announcement as ClassAnnouncement;
                    if (classAnn != null && classAnn.ClassAnnouncementTypeRef.HasValue)
                    {
                        var classAnnType = classAnnouncementTypes.First(x => x.Id == classAnn.ClassAnnouncementTypeRef);
                        notification.ClassAnnouncementType = classAnnType;
                    }
                }
                return(notifications);
            }
        }
Пример #2
0
        public void MarkAsShown(int[] notificationIds)
        {
            Trace.Assert(Context.SchoolLocalId.HasValue);
            Trace.Assert(Context.PersonId.HasValue);

            using (var uow = Update())
            {
                var da            = new NotificationDataAccess(uow);
                var notifications = da.GetNotifications(new NotificationQuery
                {
                    Shown    = false,
                    PersonId = Context.PersonId.Value,
                    SchoolId = Context.SchoolLocalId.Value,
                    RoleId   = Context.RoleId
                });
                foreach (var notificationId in notificationIds)
                {
                    var notification = notifications.FirstOrDefault(x => x.Id == notificationId);
                    if (notification == null)
                    {
                        continue;
                    }
                    if (!NotificationSecurity.CanModify(notification, Context))
                    {
                        throw new ChalkableSecurityException();
                    }
                    notification.Shown = true;
                }
                da.Update(notifications);
                uow.Commit();
            }
        }