Exemple #1
0
        public bool HasMessagingSettgingsAccess(UserContext context, Guid?districtId)
        {
            var hasPermission = Context.Claims.HasPermission(ClaimInfo.MAINTAIN_CHALKABLE_DISTRICT_SETTINGS);

            return((!districtId.HasValue || districtId == Context.DistrictId) &&
                   (BaseSecurity.IsSysAdmin(context) || (BaseSecurity.IsDistrictAdmin(context) && hasPermission)));
        }
Exemple #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();
            }
        }
Exemple #3
0
        public override Announcement EditTitle(int announcementId, string title)
        {
            Trace.Assert(Context.PersonId.HasValue);
            var announcement = GetLessonPlanById(announcementId);

            if (announcement.Title != title)
            {
                using (var uow = Update())
                {
                    if (!announcement.IsOwner && !BaseSecurity.IsDistrictAdmin(Context) && announcement.GalleryOwnerRef != Context.PersonId)
                    {
                        throw new ChalkableSecurityException();
                    }
                    var da = CreateLessonPlanDataAccess(uow);
                    if (string.IsNullOrEmpty(title))
                    {
                        throw new ChalkableException("Title parameter is empty");
                    }
                    if (da.ExistsInGallery(title, announcement.Id) && announcement.InGallery)
                    {
                        throw new ChalkableException("The item with current title already exists in the gallery");
                    }
                    announcement.Title = title;
                    da.Update(announcement);
                    uow.Commit();
                }
            }
            return(announcement);
        }
Exemple #4
0
        public Developer Edit(Guid developerId, string name, string email, string webSite, string paypalLogin)
        {
            BaseSecurity.EnsureSysAdminOrCurrentUser(developerId, Context);

            var user     = ServiceLocator.UserService.GetById(developerId);
            var oldEmail = user.Login;

            user.Login = email;
            var developer = GetById(developerId);

            developer.Name        = name;
            developer.WebSite     = webSite;
            developer.PayPalLogin = paypalLogin;
            DoUpdate(u =>
            {
                var usda = new UserDataAccess(u);
                if (oldEmail != email && usda.GetUser(email, null, null) != null)
                {
                    throw new ChalkableException("User email already exists");
                }
                new DeveloperDataAccess(u).Update(developer);
                usda.Update(user);
                if (oldEmail != email)
                {
                    ServiceLocator.EmailService.SendChangeEmailToDeveloper(developer, oldEmail, email);
                }
            });
            developer.User = user;
            return(developer);
        }
Exemple #5
0
        public string BuildLESingOnUrl()
        {
            Trace.Assert(Context.PersonId.HasValue);
            Trace.Assert(Context.SchoolLocalId.HasValue);
            Trace.Assert(Context.SchoolYearId.HasValue);

            if (Context.LEEnabled && IsLELinkActive())
            {
                return(BuildIntegratedSingOnUrl());
            }

            if (Context.Role == CoreRoles.STUDENT_ROLE)
            {
                var person = ServiceLocator.StudentService.GetById(Context.PersonId.Value, Context.SchoolYearId.Value);
                return(BuildNonIntegratedSingOnUrl(Context.SchoolLocalId.Value, person.UserId, person.FirstName, person.LastName));
            }
            if (BaseSecurity.IsDistrictOrTeacher(Context))
            {
                var person = ServiceLocator.StaffService.GetStaff(Context.PersonId.Value);
                return(BuildNonIntegratedSingOnUrl(Context.SchoolLocalId.Value, person.UserId.Value, person.FirstName, person.LastName));
            }
            else
            {
                var person = ServiceLocator.PersonService.GetPerson(Context.PersonId.Value);
                return(BuildNonIntegratedSingOnUrl(Context.SchoolLocalId.Value, person.UserId.Value, person.FirstName, person.LastName));
            }
        }
Exemple #6
0
        public bool ApproveReject(Guid applicationId, bool isApprove)
        {
            if (!BaseSecurity.IsSysAdmin(Context) && !BaseSecurity.IsAppTester(Context) && !BaseSecurity.IsAssessmentAdmin(Context))
            {
                throw new ChalkableSecurityException();
            }
            Application application;

            using (var uow = Read())
            {
                var da = new ApplicationDataAccess(uow);
                application = da.GetApplicationById(applicationId);
            }
            if (application.State == ApplicationStateEnum.SubmitForApprove)
            {
                User person = application.Developer.User;
                person.ConfirmationKey = Guid.NewGuid().ToString().Replace("-", "");
                application.State      = isApprove ? ApplicationStateEnum.Approved : ApplicationStateEnum.Rejected;
                using (var uow = Update())
                {
                    new UserDataAccess(uow).Update(person);
                    var da = new ApplicationDataAccess(uow);
                    da.Update(application);
                    uow.Commit();
                }
                ServiceLocator.EmailService.SendApplicationEmailToDeveloper(application);
                return(true);
            }
            return(false);
        }
Exemple #7
0
        public Application GetApplicationById(Guid id)
        {
            if (id == InternalGetAssessmentId())
            {
                return(GetAssessmentApplication());
            }

            if (id == GetMiniQuizAppicationId())
            {
                return(GetMiniQuizAppication());
            }

            var q = new ApplicationQuery
            {
                Id   = id,
                Role = Context.Role.Id
            };

            if (!BaseSecurity.IsSysAdmin(Context))
            {
                q.SchoolId = Context.SchoolId;
            }

            using (var uow = Read())
            {
                return(new ApplicationDataAccess(uow)
                       .GetApplication(q));
            }
        }
Exemple #8
0
        public IList <AnnouncementDetails> GetAnnouncementDetailses(DateTime?fromDate, DateTime?toDate, int?classId, bool?complete, AnnouncementTypeEnum?announcementType)
        {
            var res = new List <AnnouncementDetails>();

            if (!BaseSecurity.IsTeacher(Context) && !classId.HasValue)
            {
                if (!announcementType.HasValue || announcementType == AnnouncementTypeEnum.Admin)
                {
                    res.AddRange(ServiceLocator.AdminAnnouncementService.GetAnnouncementDetailses(fromDate, toDate, null, complete, true));
                }
            }
            if (!BaseSecurity.IsDistrictAdmin(Context) || classId.HasValue)
            {
                var onlyOwners = !Context.Claims.HasPermission(ClaimInfo.VIEW_CLASSROOM_ADMIN);

                if (!announcementType.HasValue || announcementType == AnnouncementTypeEnum.Class)
                {
                    res.AddRange(ServiceLocator.ClassAnnouncementService.GetAnnouncementDetailses(fromDate, toDate, classId, complete, onlyOwners));
                }

                if (!announcementType.HasValue || announcementType == AnnouncementTypeEnum.LessonPlan)
                {
                    res.AddRange(ServiceLocator.LessonPlanService.GetAnnouncementDetailses(fromDate, toDate, classId, complete, onlyOwners));
                }

                if (!announcementType.HasValue || announcementType == AnnouncementTypeEnum.Supplemental)
                {
                    res.AddRange(ServiceLocator.SupplementalAnnouncementService.GetAnnouncementDetailses(fromDate, toDate, classId, complete, onlyOwners));
                }
            }
            return(res);
        }
        public ActionResult Edit(string id, string UserName, string TrueName, string Role, string Password, string Pic)
        {
            T_UserInfo model = userbll.GetById(id);

            model.PassWord   = BaseSecurity.Md5Hash(Password);
            model.UserName   = UserName;
            model.TrueName   = TrueName;
            model.CreateDate = DateTime.Now;
            model.Role       = Role;
            model.pic        = Pic;
            try
            {
                if (userbll.Update(model))
                {
                    return(Json(new { success = true, msg = "操作成功" }));
                }
                else
                {
                    return(Json(new { success = false, msg = "操作失败" }));
                }
            }
            catch
            {
                return(Json(new { success = false, msg = "操作失败" }));
            }
        }
Exemple #10
0
        public Group AddGroup(string name, IntList studentIds)
        {
            if (!Context.PersonId.HasValue)
            {
                throw new UnassignedUserException();
            }
            if (string.IsNullOrEmpty(name))
            {
                throw new ChalkableException(string.Format(ChlkResources.ERR_PARAM_IS_MISSING_TMP, "Name"));
            }

            BaseSecurity.EnsureDistrictAdmin(Context);

            using (var uow = Update())
            {
                var da      = new GroupDataAccess(uow);
                var groupId = da.InsertWithEntityId(new Group {
                    Name = name, OwnerRef = Context.PersonId.Value
                });
                AssignStudentsToGroup(groupId, studentIds, uow);
                uow.Commit();
                var group = da.GetById(groupId);
                group.StudentCount = studentIds?.Count ?? 0;
                return(group);
            }
        }
Exemple #11
0
        public override void AdjustDates(IList <int> ids, int shift, int classId)
        {
            BaseSecurity.EnsureTeacher(Context);

            using (var uow = Update())
            {
                var newDates      = CreateClassAnnouncementDataAccess(uow).AdjustDates(ids, shift, classId);
                var activityDates = ActivityDate.Create(newDates);

                try //Post new dates to iNow. If any conflicts terminate whole operation.
                {
                    ConnectorLocator.ActivityConnector.AdjustDates(activityDates);
                    uow.Commit();
                }
                catch (Exception e)
                {
                    uow.Rollback();
                    if (e.InnerException != null && e.InnerException.Message == InowErrors.ACTIVITY_SECTION_NAME_DATE_MUSTBEUNIQUE_ERROR)
                    {
                        throw new ChalkableException(ChlkResources.ERR_ADJUSTING_ACTIVITIES_DATE_CONFLICT);
                    }
                    throw;
                }
            }
        }
Exemple #12
0
        protected override void AfterSaveDelete()
        {
            Akun Ak = GetOriginal <Akun>();

            if (GetErrorString().Length == 0)
            {
                if (Ak._KelompokAkun == enKelompokAkun
                    .Laba__RugiTahunBerjalan)
                {
                    BaseGL.SetingPerusahaan
                    .IdAkunLabaRugiTahunBerjalan = string.Empty;
                }
                else if (Ak._KelompokAkun == enKelompokAkun
                         .Laba__RugiTahunLalu)
                {
                    BaseGL.SetingPerusahaan
                    .IdAkunLabaRugiTahunLalu = string.Empty;
                }
                BaseSecurity.DeleteDocument(GetType(), Ak._IdAkun);
                if (Ak._KelompokAkun == enKelompokAkun.Kas__Bank)
                {
                    KurangiJmlPengunci(Dp, Ak._IdAkun);
                }
            }
        }
        private void EnsureInModifyAccess(ClassroomOption inputOptions, StiConnector.Connectors.Model.ClassroomOption currentOptions)
        {
            if (inputOptions.AveragingMethod != currentOptions.AveragingMethod)
            {
                BaseSecurity.EnsureHavingClaim(ClaimInfo.MAINTAIN_GRADE_BOOK_AVG_METHOD, Context);
            }

            if (inputOptions.StandardsCalculationWeightMaximumValues != currentOptions.StandardsCalculationWeightMaximumValues)
            {
                BaseSecurity.EnsureHavingClaim(ClaimInfo.MAINTAIN_STANDARDS_OPTIONS, Context);
            }

            if (inputOptions.StandardsCalculationRule != currentOptions.StandardsCalculationRule)
            {
                BaseSecurity.EnsureHavingClaim(ClaimInfo.MAINTAIN_STANDARDS_OPTIONS, Context);
            }

            if (inputOptions.StandardsGradingScaleRef != currentOptions.StandardsGradingScaleId)
            {
                BaseSecurity.EnsureHavingClaim(ClaimInfo.MAINTAIN_STANDARDS_OPTIONS, Context);
            }

            if (inputOptions.StandardsCalculationMethod != currentOptions.StandardsCalculationMethod)
            {
                BaseSecurity.EnsureHavingClaim(ClaimInfo.MAINTAIN_STANDARDS_OPTIONS, Context);
            }
        }
Exemple #14
0
 private void EnsureIsDistrictAdminOrCurrentTeacher(int teacherId)
 {
     if (!(BaseSecurity.IsDistrictAdmin(Context) || (Context.Role == CoreRoles.TEACHER_ROLE && Context.PersonId == teacherId)))
     {
         throw new ChalkableSecurityException();
     }
 }
Exemple #15
0
        public void ReplaceLessonPlanInGallery(int oldLessonPlanId, int newLessonPlanId)
        {
            BaseSecurity.EnsureStudyCenterEnabled(Context); // only study center customers can use lesson plan gallery

            var newLessonPlan = GetLessonPlanById(newLessonPlanId);

            DoUpdate(u =>
            {
                var da            = CreateLessonPlanDataAccess(u);
                var oldLessonPlan = da.GetLessonPlanTemplate(oldLessonPlanId, Context.PersonId.Value);

                if (!oldLessonPlan.LpGalleryCategoryRef.HasValue)
                {
                    throw new ChalkableException($@"'{oldLessonPlan.Title}' was deleted from Gallery.");
                }

                if (!BaseSecurity.IsDistrictAdmin(Context) && oldLessonPlan.GalleryOwnerRef != Context.PersonId)
                {
                    throw new ChalkableException("Current user has no access to replace lesson plan in gallery!");
                }

                newLessonPlan.LpGalleryCategoryRef = oldLessonPlan.LpGalleryCategoryRef;
                oldLessonPlan.LpGalleryCategoryRef = null;
                CreateLessonPlanDataAccess(u).Update(new[] { oldLessonPlan, newLessonPlan });
            });
        }
        public Preference Set(string key, object value, bool isPublic)
        {
            if (!BaseSecurity.IsSysAdmin(Context))
            {
                throw new ChalkableSecurityException(ChlkResources.ERR_PREFERENCE_INVALID_RIGHTS);
            }

            using (var uow = Update())
            {
                var da         = new PreferenceDataAccess(uow);
                var preference = da.GetPreferenceOrNull(key);
                if (preference == null)
                {
                    preference = CreatePreference(isPublic, key, new PreferenceInfo
                    {
                        Category = cache[key].Category,
                        Type     = cache[key].Type,
                        Value    = value.ToString(),
                        Hint     = cache[key].Hint
                    });
                    da.Insert(preference);
                }
                else
                {
                    preference.Value    = value.ToString();
                    preference.IsPublic = isPublic;
                    da.Update(preference);
                }
                cache[key] = preference;
                uow.Commit();
                return(preference);
            }
        }
Exemple #17
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();
            }
        }
 public void UpdateReportCardsLogo(int?schoolId, byte[] logoIcon)
 {
     BaseSecurity.EnsureDistrictAdmin(Context);
     DoUpdate(u =>
     {
         var da  = new DataAccessBase <ReportCardsLogo, int>(u);
         var res = da.GetAll(new AndQueryCondition {
             { nameof(ReportCardsLogo.SchoolRef), schoolId }
         })
                   .FirstOrDefault();
         var logoAddress = UploadLogo(schoolId, logoIcon);
         if (res == null)
         {
             res = new ReportCardsLogo {
                 SchoolRef = schoolId, LogoAddress = logoAddress
             };
             da.Insert(res);
         }
         else if (logoIcon == null)
         {
             da.Delete(res.Id);
         }
         else
         {
             res.SchoolRef   = schoolId;
             res.LogoAddress = logoAddress;
             da.Update(res);
         }
     });
 }
Exemple #19
0
        public void SetApplicationInternalData(Guid applicationId, int?internalScore, string internalDescription)
        {
            if (!BaseSecurity.IsSysAdmin(Context))
            {
                throw new ChalkableSecurityException();
            }

            if (internalScore.HasValue && (internalScore.Value < 0 || internalScore.Value > 100))
            {
                throw new ChalkableException("Internal score out of range. Internal score should be in range [0,100]");
            }

            using (var uow = Update())
            {
                var da  = new ApplicationDataAccess(uow);
                var app = da.GetApplicationById(applicationId);
                if (!app.IsLive)
                {
                    throw new ChalkableException("Only live application can have internal data");
                }
                app.InternalScore       = internalScore;
                app.InternalDescription = internalDescription;
                da.Update(app);
                uow.Commit();
            }
        }
 private bool CanEditAnswer(AnnouncementQnAComplex announcementQnA)
 {
     return(BaseSecurity.IsSysAdmin(Context) || announcementQnA.AnswererRef == Context.PersonId ||
            (Context.PersonId.HasValue && Context.Role == CoreRoles.TEACHER_ROLE &&
             string.IsNullOrEmpty(announcementQnA.Answer) && announcementQnA.ClassRef.HasValue &&
             ((DemoClassService)ServiceLocator.ClassService).ClassTeacherExists(announcementQnA.ClassRef.Value, Context.SchoolLocalId.Value)));
 }
Exemple #21
0
        public PaginatedList <Application> GetApplicationsWithLive(Guid?developerId, ApplicationStateEnum?state, string filter, int start = 0, int count = Int32.MaxValue)
        {
            var onlyWithLive = state == ApplicationStateEnum.Live;
            var query        = new ApplicationQuery
            {
                DeveloperId = developerId,
                State       = onlyWithLive ? null : state,
                Filter      = filter,
                Ban         = !BaseSecurity.IsSysAdminOrDeveloper(Context) ? false : (bool?)null
            };

            var apps = GetApplications(query).Where(x => x.State != ApplicationStateEnum.Live).ToList();

            if (onlyWithLive)
            {
                apps = apps.Where(a => a.OriginalRef.HasValue).ToList();
            }
            var appsLiveIds = apps.Where(x => x.OriginalRef.HasValue).Select(x => x.OriginalRef.Value).ToList();

            if (appsLiveIds.Count > 0)
            {
                var liveApps = GetApplicationsByIds(appsLiveIds);
                foreach (var app in apps)
                {
                    if (app.OriginalRef.HasValue)
                    {
                        app.LiveApplication = liveApps.First(x => x.Id == app.OriginalRef);
                    }
                }
            }
            return(new PaginatedList <Application>(apps, start / count, count));
        }
Exemple #22
0
        public PaginatedList <LessonPlan> GetLessonPlansTemplates(int?lpGalleryCategoryId, string title, int?classId, AttachmentSortTypeEnum sortType, int start, int count, AnnouncementState?state = AnnouncementState.Created)
        {
            Trace.Assert(Context.PersonId.HasValue);
            BaseSecurity.EnsureStudyCenterEnabled(Context);

            var lessonPlans = DoRead(u => CreateLessonPlanDataAccess(u).GetLessonPlanTemplates(lpGalleryCategoryId, title, classId, state, Context.PersonId.Value));

            switch (sortType)
            {
            case AttachmentSortTypeEnum.NewestUploaded:
                lessonPlans = lessonPlans.OrderByDescending(x => x.Created).ToList();
                break;

            case AttachmentSortTypeEnum.RecentlySent:
                lessonPlans = lessonPlans.OrderByDescending(x => x.Created).ToList();
                break;

            case AttachmentSortTypeEnum.OldestUploaded:
                lessonPlans = lessonPlans.OrderBy(x => x.Created).ToList();
                break;
            }

            var totalCount = lessonPlans.Count;
            var res        = lessonPlans.Skip(start).Take(count).ToList();

            return(new PaginatedList <LessonPlan>(res, start / count, count, totalCount));
        }
        public ActionResult MiniQuizInfo(int standardId)
        {
            if (!Context.PersonId.HasValue)
            {
                throw new UnassignedUserException();
            }
            var standard    = SchoolLocator.StandardService.GetStandardById(standardId);
            var miniQuizApp = MasterLocator.ApplicationService.GetMiniQuizAppication();

            var allApps = MasterLocator.ApplicationService.GetApplications(live: true)
                          .Select(BaseApplicationViewData.Create).ToList();

            IList <Application> suggestedApps = new List <Application>();

            if (standard.AcademicBenchmarkId.HasValue)
            {
                suggestedApps = MasterLocator.ApplicationService.GetSuggestedApplications(
                    new List <Guid> {
                    standard.AcademicBenchmarkId.Value
                }, 0, int.MaxValue);
            }

            //filter banned suggestedApps
            if (!BaseSecurity.IsSysAdminOrDeveloper(Context))
            {
                suggestedApps = suggestedApps?.Where(x => allApps.Any(y => x.Id == y.Id)).ToList();
            }

            var hasMyAppDic = suggestedApps.ToDictionary(x => x.Id, x => MasterLocator.ApplicationService.HasMyApps(x));
            var userInfo    = OAuthUserIdentityInfo.Create(Context.Login, Context.Role, Context.SchoolYearId, ChalkableAuthentication.GetSessionKey());
            var token       = MasterLocator.ApplicationService.GetAccessToken(miniQuizApp.Id, ChalkableAuthentication.GetSessionKey());

            return(Json(MiniQuizAppInfoViewData.Create(miniQuizApp, suggestedApps.Select(BaseApplicationViewData.Create).ToList(), allApps,
                                                       hasMyAppDic, Context.PersonId, token)));
        }
        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);
            }
        }
        public ActionResult Me()
        {
            if (!Context.PersonId.HasValue)
            {
                throw new UnassignedUserException();
            }
            var person = SchoolLocator.PersonService.GetPersonDetails(Context.PersonId.Value);

            if (!Context.SchoolYearId.HasValue)
            {
                throw new ChalkableException("User has no valid school year id");
            }
            if (!Context.DistrictId.HasValue || !Context.SchoolLocalId.HasValue)
            {
                throw new UnassignedUserException("User is not assigned to any school");
            }

            var district   = MasterLocator.DistrictService.GetByIdOrNull(Context.DistrictId.Value);
            var school     = MasterLocator.SchoolService.GetById(Context.DistrictId.Value, Context.SchoolLocalId.Value);
            var schoolYear = SchoolLocator.SchoolYearService.GetSchoolYearById(Context.SchoolYearId.Value);
            var user       = MasterLocator.UserService.GetBySisUserId(person.UserId.Value, Context.DistrictId);

            if (BaseSecurity.IsDistrictOrTeacher(Context))
            {
                person.Email = user.Login;
            }
            else
            {
                person.Email = user.Id + "@chalkable.com";
            }

            return(Json(CurrentPersonViewData.Create(person, district, school, schoolYear, Context.Claims)));
        }
        private PaginatedList <StudentSchoolsInfo> SearchStudents(string query)
        {
            var teacherId = BaseSecurity.IsTeacher(Context) && !Context.Claims.HasPermission(ClaimInfo.VIEW_STUDENT) ? Context.PersonId : null;
            var studentId = Context.Role == CoreRoles.STUDENT_ROLE ? Context.PersonId : null;

            return(SchoolLocator.StudentService.SearchStudents(Context.SchoolYearId.Value, null, null, null, null, teacherId, studentId, query, true, 0, 15, null, true));
        }
Exemple #27
0
        public IList <ClassStatsInfo> GetClassesStatsForStudent(int studentId, int gradingPeriodId, ClassSortType?sortType)
        {
            Trace.Assert(Context.SchoolYearId.HasValue);
            if (!(BaseSecurity.IsDistrictOrTeacher(Context) || studentId == Context.PersonId))
            {
                throw new ChalkableSecurityException();
            }

            IList <SectionSummaryForStudent> iNowRes;

            try
            {
                iNowRes = ConnectorLocator.ClassesDashboardConnector.GetSectionSummaryForStudent(Context.SchoolYearId.Value, studentId, gradingPeriodId);
            }
            catch (ChalkableSisNotSupportVersionException)
            {
                var gp           = ServiceLocator.GradingPeriodService.GetGradingPeriodById(gradingPeriodId);
                var chalkableRes = DoRead(u => new ClassDataAccess(u).GetStudentClasses(Context.SchoolYearId.Value, studentId, gp.MarkingPeriodRef));
                return(SortClassesStats(chalkableRes.Select(ClassStatsInfo.Create), sortType).ToList());
            }
            using (var u = Read())
            {
                var classesIds    = iNowRes.Select(x => x.SectionId).ToList();
                var classes       = new ClassDataAccess(u).GetByIds(classesIds);
                var classTeachers = new ClassTeacherDataAccess(u).GetClassTeachers(classesIds);
                var res           = ClassStatsInfo.Create(iNowRes, classes, classTeachers);
                return(SortClassesStats(res, sortType).ToList());
            }
        }
Exemple #28
0
        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));
        }
Exemple #29
0
        public PaginatedList <BackgroundTaskLogItem> GetLogItems(Guid backgroundTaskId, int start, int count)
        {
            BaseSecurity.EnsureSysAdmin(Context);
            var helper = new TableHelper <BackgroundTaskLogItem>();
            var items  = helper.GetByPartKey(backgroundTaskId.ToString(), start, count);

            return(items);
        }
Exemple #30
0
 public void DeletePicture(Guid districtId, int personId)
 {
     if (!(BaseSecurity.IsDistrictAdmin(Context)))
     {
         throw new ChalkableSecurityException();
     }
     base.DeletePicture(GenerateKeyForBlob(districtId, personId));
 }