Beispiel #1
0
        public void CopyToGallery(int fromAnnouncementId, int toAnnouncementId)
        {
            //AnnouncementAttachmentService.CopyAttachments(fromAnnouncementId, new List<int>(), lpGalleryId);
            //var annApp = ApplicationSchoolService.GetAnnouncementApplicationsByAnnIds(new List<int> { fromAnnouncementId }, true);
            //ApplicationSchoolService.CopyAnnApplications(lpGalleryId, annApp);
            //StandardService.CopyStandardsToAnnouncement(fromAnnouncementId, lpGalleryId, (int)AnnouncementTypeEnum.LessonPlan);

            Trace.Assert(Context.SchoolYearId.HasValue);
            Trace.Assert(Context.PersonId.HasValue);
            BaseSecurity.EnsureTeacher(Context);

            //get announcementApplications for copying
            var annApps = ServiceLocator.ApplicationSchoolService.GetAnnouncementApplicationsByAnnId(fromAnnouncementId, true);
            var appIds  = annApps.Select(aa => aa.ApplicationRef).ToList();
            //get only simple apps
            var apps = ServiceLocator.ServiceLocatorMaster.ApplicationService.GetApplicationsByIds(appIds).Where(a => !a.IsAdvanced).ToList();

            annApps = annApps.Where(aa => apps.Any(a => a.Id == aa.ApplicationRef)).ToList();

            using (var u = Update())
            {
                AnnouncementAttachmentService.CopyAnnouncementAttachments(fromAnnouncementId, new List <int>(), new List <int> {
                    toAnnouncementId
                }, u, ServiceLocator, ConnectorLocator);
                AnnouncementAssignedAttributeService.CopyNonStiAttributes(fromAnnouncementId, new List <int> {
                    toAnnouncementId
                }, u, ServiceLocator, ConnectorLocator);
                ApplicationSchoolService.CopyAnnApplications(annApps, new List <int> {
                    toAnnouncementId
                }, u);
                ServiceLocator.StandardService.CopyStandardsToAnnouncement(fromAnnouncementId, toAnnouncementId, (int)AnnouncementTypeEnum.LessonPlan);
                u.Commit();
            }
        }
Beispiel #2
0
        public void DuplicateLessonPlan(int lessonPlanId, IList <int> classIds)
        {
            Trace.Assert(Context.SchoolYearId.HasValue);
            Trace.Assert(Context.PersonId.HasValue);
            var lessonPlan = GetLessonPlanById(lessonPlanId); // security check

            BaseSecurity.EnsureTeacher(Context);
            if (lessonPlan.IsDraft)
            {
                throw new ChalkableException("Only submited lesson plan can be duplicated");
            }

            //get announcementApplications for copying
            var annApps = ServiceLocator.ApplicationSchoolService.GetAnnouncementApplicationsByAnnId(lessonPlanId, true);
            var appIds  = annApps.Select(aa => aa.ApplicationRef).ToList();
            //get only simple apps
            var apps = ServiceLocator.ServiceLocatorMaster.ApplicationService.GetApplicationsByIds(appIds).Where(a => !a.IsAdvanced).ToList();

            annApps = annApps.Where(aa => apps.Any(a => a.Id == aa.ApplicationRef)).ToList();

            using (var u = Update())
            {
                var teachers = new ClassTeacherDataAccess(u).GetClassTeachers(lessonPlan.ClassRef, null).Select(x => x.PersonRef).ToList();
                var resIds   = CreateLessonPlanDataAccess(u).DuplicateLessonPlan(lessonPlanId, classIds, Context.NowSchoolYearTime);
                AnnouncementAttachmentService.CopyAnnouncementAttachments(lessonPlanId, teachers, resIds, u, ServiceLocator, ConnectorLocator);
                AnnouncementAssignedAttributeService.CopyNonStiAttributes(lessonPlanId, resIds, u, ServiceLocator, ConnectorLocator);
                ApplicationSchoolService.CopyAnnApplications(annApps, resIds, u);
                u.Commit();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Copies lesson plans. Its attachments, attributes and
        /// announcement applications for simple apps
        /// </summary>
        /// <returns>Copied ids. Not new!</returns>
        public override IList <int> Copy(IList <int> lessonPlanIds, int fromClassId, int toClassId, DateTime?startDate)
        {
            Trace.Assert(Context.PersonId.HasValue);
            BaseSecurity.EnsureAdminOrTeacher(Context);

            if (!ServiceLocator.ClassService.IsTeacherClasses(Context.PersonId.Value, fromClassId, toClassId))
            {
                throw new ChalkableSecurityException("You can copy announcements only between your classes");
            }

            if (lessonPlanIds == null || lessonPlanIds.Count == 0)
            {
                return(new List <int>());
            }

            startDate = startDate ?? CalculateStartDateForCopying(toClassId);

            var announcements         = DoRead(u => CreateLessonPlanDataAccess(u, true).GetByIds(lessonPlanIds));
            var announcementIdsToCopy = announcements.Where(x => !x.IsDraft).Select(x => x.Id).ToList();

            var announcementApps = ServiceLocator.ApplicationSchoolService.GetAnnouncementApplicationsByAnnIds(announcementIdsToCopy, true);
            var applicationIds   = announcementApps.Select(x => x.ApplicationRef).ToList();
            var applications     = ServiceLocator.ServiceLocatorMaster.ApplicationService.GetApplicationsByIds(applicationIds)
                                   .Where(x => !x.IsAdvanced).ToList();

            //Filter simple apps
            announcementApps = announcementApps.Where(x => applications.Any(y => y.Id == x.ApplicationRef)).ToList();

            IDictionary <int, int> fromToAnnouncementIds;
            IList <Pair <AnnouncementAttachment, AnnouncementAttachment> > annAttachmentsCopyResult;
            IList <Pair <AnnouncementAssignedAttribute, AnnouncementAssignedAttribute> > annAttributesCopyResult;

            using (var unitOfWork = Update())
            {
                var teachers = new ClassTeacherDataAccess(unitOfWork).GetClassTeachers(fromClassId, null).Select(x => x.PersonRef).ToList();

                fromToAnnouncementIds = CreateLessonPlanDataAccess(unitOfWork, true).CopyLessonPlansToClass(lessonPlanIds, toClassId, startDate.Value, Context.NowSchoolTime);

                annAttachmentsCopyResult = AnnouncementAttachmentService.CopyAnnouncementAttachments(fromToAnnouncementIds, teachers, unitOfWork, ServiceLocator, ConnectorLocator);
                annAttributesCopyResult  = AnnouncementAssignedAttributeService.CopyNonStiAttributes(fromToAnnouncementIds, unitOfWork, ServiceLocator, ConnectorLocator);

                ApplicationSchoolService.CopyAnnApplications(announcementApps, fromToAnnouncementIds.Select(x => x.Value).ToList(), unitOfWork);

                unitOfWork.Commit();
            }

            //Here we will copy all contents.
            //var attachmentsToCopy = annAttachmentsCopyResult.Transform(x => x.Attachment).ToList();
            //attachmentsToCopy.AddRange(annAttributesCopyResult.Where(x=>x.Second.Attachment != null).Transform(x=>x.Attachment));

            //ServiceLocator.AttachementService.CopyContent(attachmentsToCopy);

            return(fromToAnnouncementIds.Select(x => x.Value).ToList());
        }
Beispiel #4
0
        public void CopyAnnouncement(int classAnnouncementId, IList <int> classIds)
        {
            Trace.Assert(Context.PersonId.HasValue);

            var ann = GetClassAnnouncemenById(classAnnouncementId);

            if (ann.IsDraft)
            {
                throw new ChalkableException("Current announcement is not submited yet");
            }

            if (!ann.SisActivityId.HasValue)
            {
                throw new ChalkableException("Current announcement doesn't have activityId");
            }

            var inowRes = ConnectorLocator.ActivityConnector.CopyActivity(ann.SisActivityId.Value, classIds);

            if (inowRes != null && inowRes.Any(x => x.NewActivityId.HasValue))
            {
                //var activities = inowRes.Where(x => x.NewActivityId.HasValue)
                //    .Select(x => new Activity { Id = x.NewActivityId.Value, SectionId = x.CopyToSectionId })
                //    .ToList();

                //get announcementApplications for copying
                var annApps = ServiceLocator.ApplicationSchoolService.GetAnnouncementApplicationsByAnnId(classAnnouncementId, true);
                var appIds  = annApps.Select(aa => aa.ApplicationRef).ToList();
                //get only simple apps
                var apps = ServiceLocator.ServiceLocatorMaster.ApplicationService.GetApplicationsByIds(appIds).Where(a => !a.IsAdvanced).ToList();
                annApps = annApps.Where(aa => apps.Any(a => a.Id == aa.ApplicationRef)).ToList();

                using (var u = Update())
                {
                    var da            = CreateClassAnnouncementDataAccess(u);
                    var sisCopyResult = inowRes.Where(x => x.NewActivityId.HasValue)
                                        .Select(x => new SisActivityCopyResult
                    {
                        FromActivityId = x.SourceActivityId,
                        ToActivityId   = x.NewActivityId.Value,
                        ToClassId      = x.CopyToSectionId
                    }).ToList();

                    var resAnnIds = da.CopyClassAnnouncementsToClass(sisCopyResult, Context.NowSchoolYearTime)
                                    .Select(x => x.ToAnnouncementId).Distinct().ToList();
                    var attOwners = new ClassTeacherDataAccess(u).GetClassTeachers(ann.ClassRef, null).Select(x => x.PersonRef).ToList();

                    AnnouncementAttachmentService.CopyAnnouncementAttachments(classAnnouncementId, attOwners, resAnnIds, u, ServiceLocator, ConnectorLocator);
                    ApplicationSchoolService.CopyAnnApplications(annApps, resAnnIds, u);

                    u.Commit();
                }
            }
        }
Beispiel #5
0
        public AnnouncementDetails CreateFromTemplate(int lessonPlanTemplateId, int classId)
        {
            Trace.Assert(Context.PersonId.HasValue);
            BaseSecurity.EnsureStudyCenterEnabled(Context);
            BaseSecurity.EnsureAdminOrTeacher(Context);

            AnnouncementDetails res;
            var annApps = ServiceLocator.ApplicationSchoolService.GetAnnouncementApplicationsByAnnId(lessonPlanTemplateId, true);
            var appIds  = annApps.Select(aa => aa.ApplicationRef).ToList();
            //get only simple apps
            var apps = ServiceLocator.ServiceLocatorMaster.ApplicationService.GetApplicationsByIds(appIds).Where(a => !a.IsAdvanced).ToList();

            annApps = annApps.Where(aa => apps.Any(a => a.Id == aa.ApplicationRef)).ToList();

            using (var u = Update())
            {
                var da = CreateLessonPlanDataAccess(u);
                var lp = da.GetLessonPlanTemplate(lessonPlanTemplateId, Context.PersonId.Value);
                if (lp.IsDraft)
                {
                    throw new ChalkableException("Current lesson plan in gallery is not submitted yet. You can't create lesson plan from not submitted template");
                }

                res = da.CreateFromTemplate(lessonPlanTemplateId, Context.PersonId.Value, classId);
                var teachers = new ClassTeacherDataAccess(u).GetClassTeachers(lp.ClassRef, null).Select(x => x.PersonRef).ToList();
                res.AnnouncementAttachments = AnnouncementAttachmentService.CopyAnnouncementAttachments(lessonPlanTemplateId, teachers, new List <int> {
                    res.Id
                }, u, ServiceLocator, ConnectorLocator);
                res.AnnouncementAttributes = AnnouncementAssignedAttributeService.CopyNonStiAttributes(lessonPlanTemplateId, new List <int> {
                    res.Id
                }, u, ServiceLocator, ConnectorLocator);
                res.AnnouncementApplications = ApplicationSchoolService.CopyAnnApplications(annApps, new List <int> {
                    res.Id
                }, u);
                u.Commit();
            }
            return(res);
        }
Beispiel #6
0
        /// <summary>
        /// Copies class announcements. First sends sis activities ids to iNow
        /// then copies data in our DB. Data in DB is default, because on feed we
        /// merge data from iNow.
        /// </summary>
        /// <returns>Copied ids. NOT NEW!</returns>
        public override IList <int> Copy(IList <int> classAnnouncementIds, int fromClassId, int toClassId, DateTime?startDate)
        {
            Trace.Assert(Context.PersonId.HasValue);
            BaseSecurity.EnsureAdminOrTeacher(Context);
            if (!ServiceLocator.ClassService.IsTeacherClasses(Context.PersonId.Value, fromClassId, toClassId))
            {
                throw new ChalkableSecurityException("You can copy announcements only between your classes");
            }

            if (classAnnouncementIds == null || classAnnouncementIds.Count == 0)
            {
                return(new List <int>());
            }

            startDate = startDate ?? CalculateStartDateForCopying(toClassId);
            var annt = DoRead(u => CreateClassAnnouncementDataAccess(u).GetByIds(classAnnouncementIds));
            var sisActivitiesIdsToCopy = annt
                                         .Where(x => !x.IsDraft && x.SisActivityId.HasValue).Select(x => x.SisActivityId.Value).ToList();

            var sisCopyResult = ConnectorLocator.ActivityConnector.CopyActivities(new ActivityCopyOptions
            {
                ActivityIds      = sisActivitiesIdsToCopy,
                StartDate        = startDate,
                CopyToSectionIds = new List <int> {
                    toClassId
                }
            });

            if (sisCopyResult == null || !sisCopyResult.Any(x => x.NewActivityId.HasValue))
            {
                return(new List <int>());
            }


            var announcementApps = ServiceLocator.ApplicationSchoolService.GetAnnouncementApplicationsByAnnIds(classAnnouncementIds, true);
            var applicationIds   = announcementApps.Select(x => x.ApplicationRef).ToList();
            //Only simple apps
            var applications = ServiceLocator.ServiceLocatorMaster.ApplicationService.GetApplicationsByIds(applicationIds)
                               .Where(x => !x.IsAdvanced).ToList();

            //Announcement apps. Only simple apps can be copied
            announcementApps = announcementApps.Where(x => applications.Any(y => y.Id == x.ApplicationRef)).ToList();

            IDictionary <int, int> fromToAnnouncementsIds;

            //IList<Pair<AnnouncementAttachment, AnnouncementAttachment>> annAttachmentsCopyResult;

            using (var u = Update())
            {
                var attachmentsOwners = new ClassTeacherDataAccess(u).GetClassTeachers(fromClassId, null).Select(x => x.PersonRef).ToList();

                var sisActivityCopyRes = sisCopyResult
                                         .Where(x => x.NewActivityId.HasValue)
                                         .Select(x => new SisActivityCopyResult
                {
                    FromActivityId = x.SourceActivityId,
                    ToActivityId   = x.NewActivityId.Value,
                    ToClassId      = x.CopyToSectionId
                }).ToList();

                //TODO change it from dictionaty to CopyAnnouncementResult later
                fromToAnnouncementsIds = CreateClassAnnouncementDataAccess(u)
                                         .CopyClassAnnouncementsToClass(sisActivityCopyRes, Context.NowSchoolTime)
                                         .ToDictionary(x => x.FromAnnouncementId, x => x.ToAnnouncementId);

                AnnouncementAttachmentService.CopyAnnouncementAttachments(fromToAnnouncementsIds, attachmentsOwners, u, ServiceLocator, ConnectorLocator);
                ApplicationSchoolService.CopyAnnApplications(announcementApps, fromToAnnouncementsIds.Select(x => x.Value).ToList(), u);

                u.Commit();
            }

            //Here we copy content
            //var attachmentsToCopy = annAttachmentsCopyResult.Transform(x => x.Attachment).ToList();
            //ServiceLocator.AttachementService.CopyContent(attachmentsToCopy);

            return(fromToAnnouncementsIds.Select(x => x.Value).ToList());
        }