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 #2
0
        private void AssignStudentsToGroup(int groupId, IntList studentIds, UnitOfWork uow)
        {
            EnsureInGroupModifyPermission(new GroupDataAccess(uow).GetById(groupId));
            var da            = new DataAccessBase <StudentGroup>(uow);
            var groupStudents = da.GetAll(new AndQueryCondition {
                { StudentGroup.GROUP_REF_FIELD, groupId }
            }).Select(x => x.StudentRef).ToList();

            if (groupStudents.Count > 0)
            {
                da.Delete(BuildStudentGroups(groupId, groupStudents));
            }
            if (studentIds != null)
            {
                da.Insert(BuildStudentGroups(groupId, studentIds));
            }
        }
        public PracticeGrade Add(int standardId, int studentId, Guid applicationId, string score)
        {
            Trace.Assert(Context.SchoolYearId.HasValue);
            //TODO: add security
            if (Context.PersonId != studentId)
            {
                throw new ChalkableSecurityException();
            }
            var classes = ServiceLocator.ClassService.GetStudentClasses(Context.SchoolYearId.Value, studentId);

            using (var uow = Update())
            {
                var classStandards = new DataAccessBase <ClassStandard, int>(uow)
                                     .GetAll(new AndQueryCondition {
                    { ClassStandard.STANDARD_REF_FIELD, standardId }
                });

                if (!classes.Any(c => classStandards.Any(cs => cs.ClassRef == c.Id || cs.ClassRef == c.CourseRef)))
                {
                    throw new ChalkableSecurityException();
                }

                var da   = new DataAccessBase <PracticeGrade>(uow);
                var date = Context.NowSchoolYearTime;
                da.Insert(new PracticeGrade
                {
                    Score          = score,
                    StandardId     = standardId,
                    StudentId      = studentId,
                    ApplicationRef = applicationId,
                    Date           = date
                });
                uow.Commit();
                var res = da.GetAll(new AndQueryCondition
                {
                    { PracticeGrade.STANDARD_ID_FIELD, standardId },
                    { PracticeGrade.STUDENT_ID_FIELD, studentId },
                    { PracticeGrade.APPLICATION_REF_FIELD, applicationId },
                    { PracticeGrade.DATE_FIELD, date },
                });
                return(res.Last());
            }
        }
Exemple #4
0
        private void SubmitAnnouncementStudents(int announcementId, IEnumerable <int> studentIds, UnitOfWork uow)
        {
            var da          = new DataAccessBase <AdminAnnouncementStudent, int>(uow);
            var annStudents = da.GetAll(new AndQueryCondition {
                { nameof(AdminAnnouncementStudent.AdminAnnouncementRef), announcementId }
            });

            da.Delete(annStudents);
            if (studentIds == null)
            {
                return;
            }
            studentIds = studentIds.Distinct();
            var annRecipients = studentIds.Select(studentId => new AdminAnnouncementStudent()
            {
                AdminAnnouncementRef = announcementId,
                StudentRef           = studentId
            }).ToList();

            da.Insert(annRecipients);
        }
Exemple #5
0
        private void SubmitAnnouncementGroups(int announcementId, IEnumerable <int> groupsIds, UnitOfWork uow)
        {
            var da        = new DataAccessBase <AnnouncementGroup, int>(uow);
            var annGroups = da.GetAll(new AndQueryCondition {
                { AnnouncementGroup.ANNOUNCEMENT_REF_FIELD, announcementId }
            });

            da.Delete(annGroups);
            if (groupsIds == null)
            {
                return;
            }
            groupsIds = groupsIds.Distinct();
            var annRecipients = groupsIds.Select(gId => new AnnouncementGroup
            {
                AnnouncementRef = announcementId,
                GroupRef        = gId
            }).ToList();

            da.Insert(annRecipients);
        }