public ClassPanorama Panorama(int classId, IList <int> academicYears, IList <StandardizedTestFilter> standardizedTestFilters) { BaseSecurity.EnsureAdminOrTeacher(Context); if (!Context.Claims.HasPermission(ClaimInfo.VIEW_PANORAMA)) { throw new ChalkableSecurityException("You are not allowed to view class panorama"); } if (academicYears == null || academicYears.Count == 0) { throw new ChalkableException("School years is required parameter"); } standardizedTestFilters = standardizedTestFilters ?? new List <StandardizedTestFilter>(); var componentIds = standardizedTestFilters.Select(x => x.ComponentId); var scoreTypeIds = standardizedTestFilters.Select(x => x.ScoreTypeId); var schoolYears = ServiceLocator.SchoolYearService.GetSchoolYearsByAcadYears(academicYears); var c = ServiceLocator.ClassService.GetClassDetailsById(classId); if (c.SchoolYear != null) { schoolYears = schoolYears.Where(x => x.SchoolRef == c.SchoolYear.SchoolRef).ToList(); } var sectionPanorama = ConnectorLocator.PanoramaConnector.GetSectionPanorama(classId, schoolYears.Select(x => x.Id).ToList(), componentIds.ToList(), scoreTypeIds.ToList()); return(ClassPanorama.Create(sectionPanorama)); }
public void CopyStandardsToAnnouncement(int fromAnnouncementId, int toAnnouncementId, int announcementType) { BaseSecurity.EnsureAdminOrTeacher(Context); var annStandards = GetAnnouncementStandards(fromAnnouncementId); var service = ServiceLocator.GetAnnouncementService((AnnouncementTypeEnum?)announcementType); service.SubmitStandardsToAnnouncement(toAnnouncementId, annStandards.Select(x => x.Standard.Id).ToList()); }
/// <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()); }
public void Save <TSettings>(TSettings settings, int?classId) where TSettings : BaseSettingModel { BaseSecurity.EnsureAdminOrTeacher(Context); if (!Context.Claims.HasPermission(ClaimInfo.VIEW_PANORAMA)) { throw new ChalkableSecurityException("You are not allowed to change panorama settings"); } SetInternal(settings, Context.PersonId, classId); }
public LPGalleryCategory Add(string name) { if (!Context.PersonId.HasValue) { throw new UnassignedUserException(); } BaseSecurity.EnsureAdminOrTeacher(Context); ValidateParams(name); return(lpGalleryCategoryStorage.Add(new LPGalleryCategory { Name = name, OwnerRef = Context.PersonId.Value })); }
public AnnouncementDetails Create(int?classId, DateTime?startDate, DateTime?endDate) { Trace.Assert(Context.PersonId.HasValue); Trace.Assert(Context.SchoolYearId.HasValue); BaseSecurity.EnsureAdminOrTeacher(Context); using (var u = Update()) { var res = CreateLessonPlanDataAccess(u).Create(classId, Context.NowSchoolTime, startDate, endDate, Context.PersonId.Value, Context.SchoolYearId.Value, Context.RoleId); u.Commit(); return(res); } }
public async Task <LunchCountGrid> GetLunchCountGrid(int classId, DateTime date, bool includeGuests) { BaseSecurity.EnsureAdminOrTeacher(Context); var scheduledDate = GetNearestScheduledDate(classId, date); var lunchCountsTask = ConnectorLocator.LunchConnector.GetLunchCount(classId, scheduledDate); var students = ServiceLocator.StudentService.GetClassStudents(classId, null, true).OrderBy(x => x.LastName).ThenBy(x => x.FirstName).ToList(); var currentClass = ServiceLocator.ClassService.GetById(classId); var staffs = ServiceLocator.StaffService.SearchStaff(Context.SchoolYearId, classId, null, null, false, 0, int.MaxValue) .OrderBy(x => x.Id != currentClass.PrimaryTeacherRef).ToList(); //primary theacher should be on the TOP var mealTypes = ServiceLocator.MealTypeService.GetAll(); var studentsCustomAlertDetails = ServiceLocator.StudentCustomAlertDetailService.GetListByStudentIds(students.Select(x => x.Id).ToList()); return(LunchCountGrid.Create(classId, scheduledDate, students, staffs, mealTypes, studentsCustomAlertDetails, await lunchCountsTask, includeGuests)); }
public void UpdateLunchCount(int classId, DateTime date, IList <LunchCount> lunchCounts) { BaseSecurity.EnsureAdminOrTeacher(Context); var lunchCountsSti = lunchCounts.Select(x => new StiConnector.Connectors.Model.LunchCount { Date = x.Date, StudentId = x.StudentId, StaffId = x.StaffId, Count = x.Count, MealTypeId = x.MealTypeId }).ToList(); ConnectorLocator.LunchConnector.UpdateLunchCount(classId, date, lunchCountsSti); }
public TSettings Restore <TSettings>(int?classId) where TSettings : BaseSettingModel { BaseSecurity.EnsureAdminOrTeacher(Context); if (!Context.Claims.HasPermission(ClaimInfo.VIEW_PANORAMA)) { throw new ChalkableSecurityException("You are not allowed to change panorama settings"); } var handler = GetSettingHandler <TSettings>(); var res = handler.GetDefault(ServiceLocator, classId); handler.SetSettings(ServiceLocator, Context.PersonId, classId, res); return(res); }
public void Delete(int assignedAttributeId) { BaseSecurity.EnsureAdminOrTeacher(Context); Trace.Assert(Context.PersonId.HasValue); Trace.Assert(Context.SchoolLocalId.HasValue); DoUpdate(u => { var da = new AnnouncementAssignedAttributeDataAccess(u); var attribute = da.GetById(assignedAttributeId); if (attribute.SisActivityId.HasValue && attribute.SisActivityAssignedAttributeId.HasValue) { ConnectorLocator.ActivityAssignedAttributeConnector.Delete(attribute.SisActivityId.Value, attribute.SisActivityAssignedAttributeId.Value); } da.Delete(assignedAttributeId); }); }
public async Task VerifyStudentHealthForm(int studentId, int schoolYearId, int healthFormId) { Trace.Assert(Context.SchoolYearId.HasValue); Trace.Assert(Context.PersonId.HasValue); BaseSecurity.EnsureAdminOrTeacher(Context); if (!await CanVerifyHealthForm(studentId, schoolYearId)) { throw new ChalkableSecurityException("You have no access to verify health forms for this student"); } var formReadReceipts = new StudentHealthFormReadReceipt { AcadSessionId = Context.SchoolYearId.Value, StaffId = Context.PersonId.Value, StudentHealthFormId = healthFormId, VerifiedDate = Context.NowSchoolTime.Date, StudentId = studentId }; await ConnectorLocator.StudentConnector.SetStudentHealthFormReadReceipts(studentId, healthFormId, formReadReceipts); }
public LPGalleryCategory Add(string name) { Trace.Assert(Context.PersonId.HasValue); ValidateParams(name); BaseSecurity.EnsureAdminOrTeacher(Context); var res = new LPGalleryCategory { Name = name, OwnerRef = Context.PersonId.Value }; using (var u = Update()) { var da = new LPGalleryCategoryDataAccess(u); if (da.Exists(name, null)) { throw new ChalkableException("Category with such name already exists"); } da.Insert(res); res = da.GetAll().Last(); u.Commit(); return(res); } }
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); }
public void Delete(int commentId) { BaseSecurity.EnsureAdminOrTeacher(Context); var comment = GetById(commentId); EnsureInDeleteAccess(comment); comment.Deleted = true; var toUpdate = new List <AnnouncementComment> { comment }; var allSubComments = comment.AllSubComments; if (allSubComments != null) { foreach (var subComment in allSubComments) { subComment.Deleted = true; toUpdate.Add(subComment); } } DoUpdate(u => new AnnouncementCommentDataAccess(u).Update(toUpdate)); }
public async Task <StudentPanoramaInfo> Panorama(int studentId, IList <int> acadYears, IList <StandardizedTestFilter> standardizedTestFilters) { BaseSecurity.EnsureAdminOrTeacher(Context); if (!Context.Claims.HasPermission(ClaimInfo.VIEW_PANORAMA)) { throw new ChalkableSecurityException("You are not allowed to view class panorama"); } if (acadYears == null || acadYears.Count == 0) { throw new ChalkableException("Academic Years is required parameter"); } standardizedTestFilters = standardizedTestFilters ?? new List <StandardizedTestFilter>(); var componentIds = standardizedTestFilters.Select(x => x.ComponentId); var scoreTypeIds = standardizedTestFilters.Select(x => x.ScoreTypeId); var schoolYears = ServiceLocator.SchoolYearService.GetSchoolYearsByAcadYears(acadYears); var studentSchoolYears = ServiceLocator.SchoolYearService.GetSchoolYearsByStudent(studentId, StudentEnrollmentStatusEnum.CurrentlyEnrolled, null); schoolYears = schoolYears.Where(x => studentSchoolYears.Any(y => y.Id == x.Id)).ToList(); var schoolYearIds = schoolYears.Select(x => x.Id).ToList(); var tasks = schoolYearIds.Select(syId => Task.Run(() => ServiceLocator.CalendarDateService.GetLastDays(syId, true, null, Context.NowSchoolYearTime))).ToList(); StudentPanorama studentPanorama = null; if (schoolYearIds.Count > 0) { studentPanorama = ConnectorLocator.PanoramaConnector.GetStudentPanorama(studentId, schoolYearIds, componentIds.ToList(), scoreTypeIds.ToList()); } var days = (await Task.WhenAll(tasks)).SelectMany(x => x).OrderBy(x => x.Day).ToList(); return(StudentPanoramaInfo.Create(studentPanorama, days, schoolYears)); }
public void Edit(AnnouncementTypeEnum announcementType, int announcementId, IList <AssignedAttributeInputModel> inputAttributes) { BaseSecurity.EnsureAdminOrTeacher(Context); Trace.Assert(Context.PersonId.HasValue); Trace.Assert(Context.SchoolLocalId.HasValue); var annoncement = ServiceLocator.GetAnnouncementService(announcementType).GetAnnouncementById(announcementId); // security check if (inputAttributes != null) { DoUpdate(u => { var da = new AnnouncementAssignedAttributeDataAccess(u); var attributesForUpdate = da.GetAttributesByIds(inputAttributes.Select(x => x.Id).ToList()); foreach (var attribute in attributesForUpdate) { var inputAttr = inputAttributes.FirstOrDefault(x => x.Id == attribute.Id); if (inputAttr == null) { continue; } attribute.AnnouncementRef = inputAttr.AnnouncementId; attribute.Name = inputAttr.Name; attribute.Text = inputAttr.Text; attribute.VisibleForStudents = inputAttr.VisibleForStudents; attribute.AttributeTypeId = inputAttr.AttributeTypeId; attribute.AttachmentRef = inputAttr.AttachmentId; } if (!annoncement.IsDraft) { ValidateAttributes(attributesForUpdate); } da.Update(attributesForUpdate); }); } }
/// <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()); }