Exemple #1
0
        public AnnouncementDetails Edit(int adminAnnouncementId, string title, string content, DateTime?expiresDate)
        {
            Trace.Assert(Context.PersonId.HasValue);
            using (var uow = Update())
            {
                var da = CreateAdminAnnouncementDataAccess(uow);
                var adminAnnouncement = da.GetAnnouncement(adminAnnouncementId, Context.PersonId.Value);
                AnnouncementSecurity.EnsureInModifyAccess(adminAnnouncement, Context);

                adminAnnouncement.Title   = title;
                adminAnnouncement.Content = content;
                if (expiresDate.HasValue)
                {
                    adminAnnouncement.Expires = expiresDate.Value;
                }

                if (adminAnnouncement.IsSubmitted)
                {
                    ValidateAdminAnnouncement(adminAnnouncement, uow, da);
                }
                da.Update(adminAnnouncement);
                uow.Commit();
                return(InternalGetDetails(da, adminAnnouncementId)); // da.GetDetails(adminAnnouncementId, Context.PersonId.Value, Context.RoleId);
            }
        }
Exemple #2
0
        public override void Submit(int announcementId)
        {
            Trace.Assert(Context.PersonId.HasValue);

            using (var u = Update())
            {
                var da  = CreateLessonPlanDataAccess(u);
                var res = InternalGetDetails(da, announcementId); // da.GetDetails(announcementId, Context.PersonId.Value, Context.RoleId);
                var ln  = res.LessonPlanData;

                if (ln.InGallery)
                {
                    if (!Context.SCEnabled)
                    {
                        throw new ChalkableException("Cannot create lesson plan template, Study Center disabled!");
                    }
                    if (ln.LpGalleryCategoryRef == null)
                    {
                        throw new ChalkableException("Cannot create lesson plan template without category!");
                    }
                }

                AnnouncementSecurity.EnsureInModifyAccess(res, Context);
                ValidateLessonPlan(ln, da);
                if (ln.IsDraft)
                {
                    ln.State   = AnnouncementState.Created;
                    ln.Created = Context.NowSchoolTime.Date;
                    da.Update(ln);
                }
                ServiceLocator.AnnouncementAssignedAttributeService.ValidateAttributes(res.AnnouncementAttributes);
                u.Commit();
            }
        }
Exemple #3
0
        public override void Submit(int announcementId)
        {
            Trace.Assert(Context.SchoolLocalId.HasValue);
            var res = GetAnnouncementDetails(announcementId);

            if (res.ClassAnnouncementData.Title == null || Exists(res.ClassAnnouncementData.Title, res.ClassAnnouncementData.ClassRef, res.ClassAnnouncementData.Expires, res.ClassAnnouncementData.Id))
            {
                throw new ChalkableException("Invalid Class Announcement Title");
            }

            using (var uow = Update())
            {
                var da = CreateClassAnnouncementDataAccess(uow);
                AnnouncementSecurity.EnsureInModifyAccess(res, Context);
                if (res.ClassAnnouncementData.IsDraft)
                {
                    ServiceLocator.AnnouncementAssignedAttributeService.ValidateAttributes(res.AnnouncementAttributes);
                    res.ClassAnnouncementData.State   = AnnouncementState.Created;
                    res.ClassAnnouncementData.Created = Context.NowSchoolTime.Date;

                    var activity = new Activity();
                    MapperFactory.GetMapper <Activity, AnnouncementDetails>().Map(activity, res);
                    activity = ConnectorLocator.ActivityConnector.CreateActivity(res.ClassAnnouncementData.ClassRef, activity);
                    if (da.Exists(activity.Id))
                    {
                        throw new ChalkableException("Announcement with such activityId already exists");
                    }

                    var annAttDa = new AnnouncementAssignedAttributeDataAccess(uow);
                    annAttDa.Delete(res.AnnouncementAttributes);
                    MapperFactory.GetMapper <AnnouncementDetails, Activity>().Map(res, activity);
                    var attributes = res.AnnouncementAttributes.Where(x => x.Attachment != null).ToList();
                    if (attributes.Count > 0)
                    {
                        var atts = new AttachmentDataAccess(uow).GetBySisAttachmentIds(attributes.Select(a => a.Attachment.SisAttachmentId.Value).ToList());
                        foreach (var attribute in res.AnnouncementAttributes)
                        {
                            if (attribute.Attachment == null)
                            {
                                continue;
                            }
                            var att = atts.FirstOrDefault(x => x.SisAttachmentId == attribute.Attachment.SisAttachmentId);
                            if (att == null)
                            {
                                continue;
                            }
                            attribute.AttachmentRef = att.Id;
                        }
                    }
                    annAttDa.Insert(res.AnnouncementAttributes);
                }
                da.Update(res.ClassAnnouncementData);
                uow.Commit();
            }
        }
        public AnnouncementDetails Edit(int supplementalAnnouncementId, int classId, int?classAnnouncementTypeId, string title,
                                        string content, DateTime?expiresDate, bool visibleForStudent, IList <int> recipientsIds
                                        , bool discussionEnabled, bool previewCommentsEnabled, bool requireCommentsEnabled)
        {
            Trace.Assert(Context.PersonId.HasValue);
            var suppAnnouncement = InternalGetAnnouncementById(supplementalAnnouncementId);

            using (var uow = Update())
            {
                var da = CreateSupplementalAnnouncementDataAccess(uow);
                AnnouncementSecurity.EnsureInModifyAccess(suppAnnouncement, Context);

                if (suppAnnouncement.ClassRef != classId)
                {
                    if (!suppAnnouncement.IsDraft)
                    {
                        throw new ChalkableException("Class can't be changed for submited supplemental announcements");
                    }

                    suppAnnouncement.ClassRef = classId;
                    new AnnouncementApplicationDataAccess(uow).DeleteByAnnouncementId(suppAnnouncement.Id);
                    new AnnouncementStandardDataAccess(uow).DeleteNotAssignedToClass(suppAnnouncement.Id, classId);
                    new SupplementalAnnouncementRecipientDataAccess(uow).DeleteByAnnouncementId(supplementalAnnouncementId);
                }

                suppAnnouncement.Title                    = title;
                suppAnnouncement.Content                  = content;
                suppAnnouncement.Expires                  = expiresDate ?? suppAnnouncement.Expires;
                suppAnnouncement.VisibleForStudent        = visibleForStudent;
                suppAnnouncement.ClassAnnouncementTypeRef = classAnnouncementTypeId;

                if (previewCommentsEnabled && discussionEnabled && !suppAnnouncement.PreviewCommentsEnabled)
                {
                    if (suppAnnouncement.IsSubmitted)
                    {
                        new AnnouncementCommentDataAccess(uow).HideAll(suppAnnouncement.Id);
                    }
                }
                suppAnnouncement.DiscussionEnabled      = discussionEnabled;
                suppAnnouncement.RequireCommentsEnabled = requireCommentsEnabled;
                suppAnnouncement.PreviewCommentsEnabled = previewCommentsEnabled;


                if (suppAnnouncement.IsSubmitted)
                {
                    ValidateSupplementalAnnouncement(suppAnnouncement, da, ServiceLocator, recipientsIds, classId);
                }

                new SupplementalAnnouncementRecipientDataAccess(uow).UpdateRecipients(supplementalAnnouncementId, recipientsIds);
                da.Update(suppAnnouncement);
                uow.Commit();
                return(InternalGetDetails(da, supplementalAnnouncementId));
            }
        }
Exemple #5
0
        public void SetVisibleForStudent(int lessonPlanId, bool visible)
        {
            var lessonPlan = GetLessonPlanById(lessonPlanId);

            AnnouncementSecurity.EnsureInModifyAccess(lessonPlan, Context);
            if (lessonPlan.VisibleForStudent == visible)
            {
                return;
            }
            lessonPlan.VisibleForStudent = visible;
            DoUpdate(u => CreateLessonPlanDataAccess(u).Update(lessonPlan));
        }
        public void SetVisibleForStudent(int supplementalAnnouncementPlanId, bool visible)
        {
            var suppAnnouncement = GetSupplementalAnnouncementById(supplementalAnnouncementPlanId);

            AnnouncementSecurity.EnsureInModifyAccess(suppAnnouncement, Context);
            if (suppAnnouncement.VisibleForStudent == visible)
            {
                return;
            }

            suppAnnouncement.VisibleForStudent = visible;
            DoUpdate(u => CreateSupplementalAnnouncementDataAccess(u).Update(suppAnnouncement));
        }
        public Standard RemoveStandard(int announcementId, int standardId)
        {
            var ann = InternalGetAnnouncementById(announcementId);

            AnnouncementSecurity.EnsureInModifyAccess(ann, Context);

            using (var uow = Update())
            {
                new AnnouncementStandardDataAccess(uow).Delete(announcementId, standardId);
                AfterRemovingStandard(ann, standardId);
                uow.Commit();
                return(new StandardDataAccess(uow).GetById(standardId));
            }
        }
Exemple #8
0
        public AnnouncementDetails Edit(ClassAnnouncementInfo announcement)
        {
            if (!Context.PersonId.HasValue)
            {
                throw new UnassignedUserException();
            }
            using (var uow = Update())
            {
                var da  = CreateClassAnnouncementDataAccess(uow);
                var ann = da.GetAnnouncement(announcement.AnnouncementId, Context.PersonId.Value);
                AnnouncementSecurity.EnsureInModifyAccess(ann, Context);

                ann = UpdateTeacherAnnouncement(ann, announcement, announcement.ClassId, uow, da);
                var res = MergeEditAnnResultWithStiData(da, ann);
                uow.Commit();
                return(res);
            }
        }
        public Standard AddAnnouncementStandard(int announcementId, int standardId)
        {
            var ann = InternalGetAnnouncementById(announcementId);

            AnnouncementSecurity.EnsureInModifyAccess(ann, Context);
            var annStandard = new AnnouncementStandard
            {
                AnnouncementRef = announcementId,
                StandardRef     = standardId
            };

            using (var uow = Update())
            {
                new AnnouncementStandardDataAccess(uow).Insert(annStandard);
                AfterAddingStandard(ann, annStandard);
                uow.Commit();
                return(new StandardDataAccess(uow).GetById(standardId));
            }
        }
        public IList <Standard> SubmitStandardsToAnnouncement(int announcementId, IList <int> standardsIds)
        {
            var ann = InternalGetAnnouncementById(announcementId);

            AnnouncementSecurity.EnsureInModifyAccess(ann, Context);
            standardsIds = standardsIds ?? new List <int>();
            var annStandards = standardsIds.Select(sId => new AnnouncementStandard
            {
                AnnouncementRef = announcementId,
                StandardRef     = sId
            }).ToList();

            using (var uow = Update())
            {
                var da = new AnnouncementStandardDataAccess(uow);
                da.Delete(announcementId, null);
                da.Insert(annStandards);
                AfterSubmitStandardsToAnnouncement(ann, standardsIds);
                uow.Commit();
                return(new StandardDataAccess(uow).GetStandardsByIds(standardsIds));
            }
        }
Exemple #11
0
        public override void Submit(int announcementId)
        {
            Trace.Assert(Context.PersonId.HasValue);
            BaseSecurity.EnsureDistrictAdmin(Context);
            var res = GetAnnouncementDetails(announcementId);

            using (var uow = Update())
            {
                var da  = CreateAdminAnnouncementDataAccess(uow);
                var ann = da.GetAnnouncement(announcementId, Context.PersonId.Value);
                AnnouncementSecurity.EnsureInModifyAccess(ann, Context);
                ValidateAdminAnnouncement(ann, uow, da);
                ServiceLocator.AnnouncementAssignedAttributeService.ValidateAttributes(res.AnnouncementAttributes);
                if (ann.IsDraft)
                {
                    ann.Created = Context.NowSchoolTime;
                    ann.State   = AnnouncementState.Created;
                }
                da.Update(ann);
                uow.Commit();
            }
        }
        public override void Submit(int announcementId)
        {
            Trace.Assert(Context.PersonId.HasValue);
            using (var u = Update())
            {
                var da  = CreateSupplementalAnnouncementDataAccess(u);
                var res = InternalGetDetails(da, announcementId);
                var suppAnnouncement = res.SupplementalAnnouncementData;
                var recipients       = new SupplementalAnnouncementRecipientDataAccess(u).GetRecipientsByAnnouncementId(suppAnnouncement.Id);
                AnnouncementSecurity.EnsureInModifyAccess(res, Context);

                ValidateSupplementalAnnouncement(suppAnnouncement, da, ServiceLocator, recipients.Select(x => x.StudentRef).ToList(), suppAnnouncement.ClassRef);

                if (suppAnnouncement.IsDraft)
                {
                    suppAnnouncement.State   = AnnouncementState.Created;
                    suppAnnouncement.Created = Context.NowSchoolTime.Date;
                    da.Update(suppAnnouncement);
                }
                ServiceLocator.AnnouncementAssignedAttributeService.ValidateAttributes(res.AnnouncementAttributes);
                u.Commit();
            }
        }
Exemple #13
0
        public AnnouncementDetails Edit(int lessonPlanId, int?classId, int?lpGalleryCategoryId, string title, string content, DateTime?startDate,
                                        DateTime?endDate, bool visibleForStudent, bool inGallery, bool discussionEnabled, bool previewCommentsEnabled, bool requireCommentsEnabled)
        {
            Trace.Assert(Context.PersonId.HasValue);
            var lessonPlan = GetLessonPlanById(lessonPlanId); // security check

            if (inGallery && !lessonPlan.IsDraft)
            {
                if (!Context.SCEnabled)
                {
                    throw new ChalkableException("Cannot create lesson plan template, Study Center disabled!");
                }
                if (lpGalleryCategoryId == null)
                {
                    throw new ChalkableException("Cannot create lesson plan template without category!");
                }
            }

            using (var uow = Update())
            {
                var da = CreateLessonPlanDataAccess(uow);
                AnnouncementSecurity.EnsureInModifyAccess(lessonPlan, Context);

                if (classId != null && lessonPlan.ClassRef != classId)
                {
                    if (!lessonPlan.IsDraft)
                    {
                        throw new ChalkableException("Class can't be changed for submited lesson plan");
                    }

                    lessonPlan.ClassRef = classId;
                    //clear old data befor swiching
                    new AnnouncementApplicationDataAccess(uow).DeleteByAnnouncementId(lessonPlan.Id);
                    new AnnouncementStandardDataAccess(uow).DeleteNotAssignedToClass(lessonPlan.Id, classId.Value);
                }

                lessonPlan.Title             = title;
                lessonPlan.Content           = content;
                lessonPlan.StartDate         = startDate;
                lessonPlan.EndDate           = endDate;
                lessonPlan.VisibleForStudent = visibleForStudent;
                lessonPlan.InGallery         = inGallery;
                lessonPlan.GalleryOwnerRef   = Context.PersonId;

                if (previewCommentsEnabled && discussionEnabled && !lessonPlan.PreviewCommentsEnabled)
                {
                    if (lessonPlan.IsSubmitted)
                    {
                        new AnnouncementCommentDataAccess(uow).HideAll(lessonPlan.Id);
                    }
                }
                lessonPlan.DiscussionEnabled      = discussionEnabled;
                lessonPlan.RequireCommentsEnabled = requireCommentsEnabled;
                lessonPlan.PreviewCommentsEnabled = previewCommentsEnabled;


                lessonPlan.LpGalleryCategoryRef = lpGalleryCategoryId;

                if (lessonPlan.IsSubmitted)
                {
                    ValidateLessonPlan(lessonPlan, da);
                }
                da.Update(lessonPlan);
                uow.Commit();
                return(InternalGetDetails(da, lessonPlanId));
            }
        }