public async Task <AllRecipients> GetAllParentRecipients(int?studentUsi, string recipientUniqueId, int recipientTypeId, int rowsToSkip, int rowsToRetrieve)
        {
            var validLeadersDescriptors = _customParametersProvider.GetParameters().descriptors.validCampusLeaderDescriptors;
            var model = await _communicationsRepository.GetAllParentRecipients(studentUsi, recipientUniqueId, recipientTypeId, rowsToSkip, rowsToRetrieve, validLeadersDescriptors, _dateProvider.Today());

            return(model);
        }
Exemplo n.º 2
0
        public async Task <StudentAttendance> GetStudentAttendanceAsync(int studentUsi)
        {
            var attendanceEvents = await _studentRepository.GetStudentAttendanceEventsAsync(studentUsi);

            var absenceThresholdDays = _customParametersProvider.GetParameters().attendance.ADA.maxAbsencesCountThreshold;
            var descriptors          = _customParametersProvider.GetParameters().descriptors;

            var excusedEvents   = attendanceEvents.Where(ae => !string.IsNullOrEmpty(ae.EventCategory) && ae.EventCategory.Contains(descriptors.excusedAbsenceDescriptorCodeValue)).ToList();
            var unexcusedEvents = attendanceEvents.Where(ae => !string.IsNullOrEmpty(ae.EventCategory) && ae.EventCategory.Contains(descriptors.unexcusedAbsenceDescriptorCodeValue)).ToList();
            var tardyEvents     = attendanceEvents.Where(ae => !string.IsNullOrEmpty(ae.EventCategory) && ae.EventCategory.Contains(descriptors.tardyDescriptorCodeValue)).ToList();
            var abscentEvents   = attendanceEvents.Where(ae => !string.IsNullOrEmpty(ae.EventCategory) && ae.EventCategory.Contains(descriptors.absentDescriptorCodeValue)).ToList();

            return(new StudentAttendance
            {
                AbsenceThresholdDays = absenceThresholdDays,
                ExcusedInterpretation = InterpretExcusedAbsencesCount(excusedEvents.Count()),
                UnexcusedInterpretation = InterpretUnexcusedAbsencesCount(unexcusedEvents.Count()),
                TardyInterpretation = InterpretTardiesCount(tardyEvents.Count()),
                AbsentInterpretation = InterpretUnexcusedAbsencesCount(abscentEvents.Count()),
                YearToDateAbsenceCount = abscentEvents.Count(),
                ExcusedAttendanceEvents = excusedEvents,
                UnexcusedAttendanceEvents = unexcusedEvents,
                TardyAttendanceEvents = tardyEvents,
                AbsentAttendanceEvents = abscentEvents
            });
        }
        public async Task <StudentMissingAssignments> GetStudentMissingAssignments(int studentUsi)
        {
            var descriptors        = _customParametersProvider.GetParameters().descriptors;
            var missingAssignments = await _studentRepository.GetStudentMissingAssignments(studentUsi, descriptors.gradeBookMissingAssignmentTypeDescriptors, descriptors.missingAssignmentLetterGrade);

            var externalLink          = _customParametersProvider.GetParameters().assignments.linkToSystemWithDetails;
            var missingAssignmentLink = new LinkModel {
                Title = externalLink.title, LinkText = externalLink.linkText, Url = externalLink.url
            };

            missingAssignments.Interpretation = Interpret(missingAssignments.MissingAssignmentCount);
            missingAssignments.ExternalLink   = missingAssignmentLink;
            return(missingAssignments);
        }
Exemplo n.º 4
0
        public async Task <List <StudentBriefModel> > GetStudentsAssociatedWithParentAsync(int parentUsi, string recipientUniqueId, int recipientTypeId)
        {
            var studentsAssociatedWithParent = await _parentRepository.GetStudentsAssociatedWithParent(parentUsi, recipientUniqueId, recipientTypeId);

            var studentsSummary = await _studentsService.GetStudentsSummary(studentsAssociatedWithParent.Select(x => x.StudentUsi).ToList());

            // Get other calculated fields.
            foreach (var student in studentsAssociatedWithParent)
            {
                var summary = studentsSummary.Find(x => x.StudentUsi == student.StudentUsi);

                student.StudentUniqueId             = summary.StudentUniqueId;
                student.FirstName                   = summary.FirstName;
                student.MiddleName                  = summary.MiddleName;
                student.LastSurname                 = summary.LastSurname;
                student.GradeLevel                  = summary.GradeLevel;
                student.SexType                     = summary.SexType;
                student.YTDGPA                      = summary.Gpa;
                student.GPAInterpretation           = summary.GpaInterpretation;
                student.AbsenceThresholdDays        = _customParametersProvider.GetParameters().attendance.ADA.maxAbsencesCountThreshold;
                student.AdaAbsences                 = summary.AbsenceCount;
                student.AdaAbsentInterpretation     = summary.AbsenceInterpretation;
                student.YTDDisciplineIncidentCount  = summary.DisciplineIncidentCount;
                student.YTDDisciplineInterpretation = summary.DisciplineIncidentInterpretation;

                //student.ExcusedAbsences = attendance.ExcusedAttendanceEvents.Count();
                //student.ExcusedInterpretation = attendance.ExcusedInterpretation;
                //student.UnexcusedAbsences = attendance.UnexcusedAttendanceEvents.Count();
                //student.UnexcusedInterpretation = attendance.UnexcusedInterpretation;
                //student.TardyAbsences = attendance.TardyAttendanceEvents.Count();
                //student.TardyInterpretation = attendance.TardyInterpretation;

                student.MissingAssignments = summary.MissingassignmentCount;
                student.MissingAssignmentsInterpretation = summary.MissingAssigmentInterpretation;

                student.CourseAverage = new StudentCurrentGradeAverage {
                    Evaluation = summary.CourseAverageInterpretation, GradeAverage = summary.CourseAverage
                };
                student.ImageUrl = await _imageProvider.GetStudentImageUrlAsync(student.StudentUniqueId);

                student.CourseAverage = new StudentCurrentGradeAverage {
                    Evaluation = summary.CourseAverageInterpretation, GradeAverage = summary.CourseAverage
                };
                student.Alerts = await _alertService.GetParentStudentUnreadAlerts(recipientUniqueId, student.StudentUniqueId);
            }

            return(studentsAssociatedWithParent);
        }
        public async Task <PersonIdentityModel> GetIdentity(string email)
        {
            // Because this code is used in the authentication middle ware we need to resolve db dependency in here.
            var parentRepo = _container.GetInstance <IParentRepository>();

            var validParentDescriptors = _customParametersProvider.GetParameters().descriptors.validParentDescriptors;

            var parentIdentity = await parentRepo.GetParentIdentityByEmailAsync(email, validParentDescriptors);


            // If email is not found on edfi emails it will try to find it on profile emails.
            if (parentIdentity == null || !parentIdentity.Any())
            {
                parentIdentity = await parentRepo.GetParentIdentityByProfileEmailAsync(email, validParentDescriptors);
            }


            // If email doesnt exist on edfi emails or profile emails it isn't a parent, it can't handle so it returns null.
            if (parentIdentity == null || !parentIdentity.Any())
            {
                return(null);
            }


            // TODO: handle case where there are duplicates
            var parentInfo = parentIdentity.FirstOrDefault();

            parentInfo.PersonType = "Parent";

            return(parentInfo);
        }
        public async Task <PersonIdentityModel> GetIdentity(string email)
        {
            var staffRepo = _container.GetInstance <IStaffRepository>();

            var validCampusLeaderDescriptors = _customParametersProvider.GetParameters().descriptors.validCampusLeaderDescriptors;

            var staffIdentity = await staffRepo.GetStaffPrincipalIdentityByEmailAsync(email, validCampusLeaderDescriptors, _dateProvider.Today());

            if (staffIdentity == null || !staffIdentity.Any())
            {
                staffIdentity = await staffRepo.GetStaffPrincipalIdentityByProfileEmailAsync(email, validCampusLeaderDescriptors, _dateProvider.Today());
            }

            // If email doesnt exist on edfi emails or profile emails it isn't a staff, it can't handle so it returns null.
            if (staffIdentity == null || !staffIdentity.Any())
            {
                return(null);
            }

            // TODO: handle case where there are duplicates
            var personInfo = staffIdentity.FirstOrDefault();

            personInfo.PersonType = "CampusLeader";

            return(personInfo);
        }
Exemplo n.º 7
0
        public async Task <ParentAlertTypeModel> GetParentAlertTypes(int usi)
        {
            var customParams     = _customParametersProvider.GetParameters();
            var parentTypeAlerts = await _alertRepository.GetParentAlertTypes(usi);

            return(featureToggleFilter(customParams, parentTypeAlerts));
        }
        private string InterpretOnTrackToGraduate(bool?onTrack)
        {
            if (onTrack == null)
            {
                return(null);
            }

            return(_customParametersProvider.GetParameters().graduationReadiness.thresholdRules.GetRuleThatApplies(onTrack.Value).interpretation);
        }
        private async Task <List <StudentSuccessTeamMember> > GetPrincipals(int studentUSI, string recipientUniqueId, int recipientTypeId)
        {
            var validLeadersDescriptors = _customParametersProvider.GetParameters().descriptors.validCampusLeaderDescriptors;
            var principals = await _studentRepository.GetPrincipals(studentUSI, validLeadersDescriptors, recipientUniqueId, recipientTypeId);

            foreach (var p in principals)
            {
                p.ImageUrl = await _imageUrlProvider.GetStaffImageUrlAsync(p.UniqueId);
            }

            return(principals);
        }
        public async Task <StudentBehavior> GetStudentBehaviorAsync(int studentUsi)
        {
            var incidents = await _studentRepository.GetStudentDisciplineIncidentsAsync(studentUsi, _customParametersProvider.GetParameters().descriptors.disciplineIncidentDescriptor, _dateProvider.Today());

            var externalLink = _customParametersProvider.GetParameters().behavior.linkToSystemWithDetails;
            var behaviorLink = new LinkModel {
                Title = externalLink.title, LinkText = externalLink.linkText, Url = externalLink.url
            };

            var model = new StudentBehavior
            {
                DateAsOf = DateTime.Now,
                YearToDateDisciplineIncidentCount = incidents.Count,
                Interpretation      = InterpretIncidentCount(incidents.Count),
                DisciplineIncidents = incidents,
                ExternalLink        = behaviorLink
            };


            return(model);
        }
        public async Task <PersonBriefModel> GetPersonBriefModelAsync(int studentUsi)
        {
            var student = await _studentRepository.GetStudentBriefModelAsync(studentUsi);

            student.ImageUrl = await _imageUrlProvider.GetStudentImageUrlAsync(student.UniqueId);

            student.FeedbackExternalUrl = _customParametersProvider.GetParameters().feedbackExternalUrl;
            return(student);
        }
        public async Task <StudentCourseGrades> GetStudentCourseGradesAsync(int studentUsi, bool withStaffPictures = true)
        {
            var gpa = await GetStudentGPAAsync(studentUsi);

            var currentCourses = await GetStudentGradesByGradingPeriod(studentUsi, withStaffPictures);

            var externalLink     = _customParametersProvider.GetParameters().courseGrades.linkToSystemWithDetails;
            var courseGradesLink = new LinkModel {
                Title = externalLink.title, LinkText = externalLink.linkText, Url = externalLink.url
            };

            currentCourses.ForEach(x =>
            {
                x.ClassPeriodName = _classPeriodNameProvider.ParseClassPeriodName(x.ClassPeriodName);
                interpretCourseGrades(x.GradesByGradingPeriod);
                interpretCourseGrades(x.GradesByExam);
                interpretCourseGrades(x.GradesBySemester);
                interpretCourseGrades(x.GradesByFinal);
                x.GradesByGradingPeriod = mapGradingPeriodGrades(x.GradesByGradingPeriod);
                x.GradesByExam          = mapGradingPeriodExam(x.GradesByExam);
                x.GradesBySemester      = mapGradingPeriodExam(x.GradesBySemester);
            });

            var model = new StudentCourseGrades
            {
                GPA = new StudentGPA
                {
                    GPA                = gpa,
                    Interpretation     = gpa.HasValue ? InterpretGPA(gpa.Value) : "",
                    NationalAverageGPA = _customParametersProvider.GetParameters().courseGrades.gpa.nationalAverage
                },
                CurrentCourses      = currentCourses,
                CurrentGradeAverage = GetStudentCurrentGradeAverage(currentCourses),
                Transcript          = await GetStudentTranscriptAsync(studentUsi),
            };

            model.ExternalLink = courseGradesLink;

            return(model);
        }
        public async Task <StudentCalendar> GetStudentCalendar(int studentUsi)
        {
            StudentAttendance studentAttendance = await _studentAtttendanceRepository.GetStudentAttendanceAsync(studentUsi);

            var descriptors = _customParametersProvider.GetParameters().descriptors;
            var days        = await _studentRepository.GetStudentCalendarDays(studentUsi);

            var calendar = new StudentCalendar();

            calendar.InstructionalDays    = days.Where(x => x.Event.Description.Contains(descriptors.instructionalDayDescriptorCodeValue)).ToList();
            calendar.NonInstructionalDays = days.Where(x => x.Event.Description.Contains(descriptors.nonInstrunctionalDayDescriptorCodeValue)).ToList();
            calendar.Holidays             = days.Where(x => x.Event.Description.Contains(descriptors.holiDayDescriptorCodeValue)).ToList();
            calendar.TeacherOnlyDays      = days.Where(x => x.Event.Description.Contains(descriptors.teacherOnlyDayDescriptorCodeValue)).ToList();
            calendar.AttendanceEventDays  = new List <StudentCalendarDay>();
            calendar.AttendanceEventDays.AddRange(studentAttendance.ExcusedAttendanceEvents.Select(x => new StudentCalendarDay
            {
                Date  = x.DateOfEvent,
                Event = new StudentCalendarEvent {
                    Name = x.EventCategory, Description = string.Format("{0}{1}", x.EventDescription, x.Reason != null ? ": " + x.Reason : "")
                }
            }).ToList());
            calendar.AttendanceEventDays.AddRange(studentAttendance.UnexcusedAttendanceEvents.Select(x => new StudentCalendarDay
            {
                Date  = x.DateOfEvent,
                Event = new StudentCalendarEvent {
                    Name = x.EventCategory, Description = x.EventDescription
                }
            }).ToList());
            calendar.AttendanceEventDays.AddRange(studentAttendance.TardyAttendanceEvents.Select(x => new StudentCalendarDay
            {
                Date  = x.DateOfEvent,
                Event = new StudentCalendarEvent {
                    Name = x.EventCategory, Description = x.EventDescription
                }
            }).ToList());

            return(calendar);
        }
        public IHttpActionResult Get()
        {
            var model = _customParametersProvider.GetParameters();

            return(Ok(model));
        }
Exemplo n.º 15
0
        public async Task <int> SendAlerts()
        {
            var timeToSend = DateTime.Today.AddHours(Double.Parse(_applicationSettingsProvider.GetSetting("unread.message.alert.hour")));

            var wasSentBefore = await _alertRepository.unreadMessageAlertWasSentBefore();

            if (DateTime.UtcNow < timeToSend.ToUniversalTime() || wasSentBefore)
            {
                return(0);
            }

            var customParameters = _customParametersProvider.GetParameters();

            var alertTypes = await _typesRepository.GetAlertTypes();

            var alertAssignment = alertTypes.Where(x => x.AlertTypeId == AlertTypeEnum.Message.Value).FirstOrDefault();

            var currentSchoolYear = await _alertRepository.getCurrentSchoolYear();

            // Find students that have surpassed the threshold.
            var parentsAndStaffWithUnreadMessages = await _alertRepository.ParentsAndStaffWithUnreadMessages();

            var alertCountSent = 0;

            // Send alerts to the parents of these students.
            foreach (var p in parentsAndStaffWithUnreadMessages)
            {
                if (p.AlertTypeIds == null || !p.AlertTypeIds.Contains(AlertTypeEnum.Message.Value))
                {
                    continue;
                }

                string to;
                string template;
                string subjectTemplate = "Family Portal: Unread Messages Alert";

                if (p.PreferredMethodOfContactTypeId == MethodOfContactTypeEnum.SMS.Value && p.Telephone != null)
                {
                    to = p.Telephone;
                    subjectTemplate = await TranslateText(p.LanguageCode, subjectTemplate);

                    template = FillSMSTemplate(p);
                    template = await TranslateText(p.LanguageCode, template);

                    await _smsProvider.SendMessageAsync(to, subjectTemplate, template);

                    alertCountSent++;
                }
                else if (p.PreferredMethodOfContactTypeId == MethodOfContactTypeEnum.Email.Value && p.Email != null)
                {
                    to = p.Email;
                    subjectTemplate = await TranslateText(p.LanguageCode, subjectTemplate);

                    template = FillEmailTemplate(p);
                    template = await TranslateText(p.LanguageCode, template);

                    await _messagingProvider.SendMessageAsync(to, null, null, subjectTemplate, template);

                    alertCountSent++;
                }
                else if (p.PreferredMethodOfContactTypeId == MethodOfContactTypeEnum.Notification.Value)
                {
                    string pushNoSubjectTemplate = $"Unread Messages Alert";
                    string pushNoBodyTemplate    = $"You have {p.UnreadMessageCount} unread messages";
                    pushNoSubjectTemplate = await TranslateText(p.LanguageCode, pushNoSubjectTemplate);

                    pushNoBodyTemplate = await TranslateText(p.LanguageCode, pushNoBodyTemplate);


                    await _pushNotificationProvider.SendNotificationAsync(new NotificationItemModel
                    {
                        personUniqueId = p.PersonUniqueId,
                        personType     = p.PersonType,
                        notification   = new Notification
                        {
                            title = pushNoSubjectTemplate,
                            body  = pushNoBodyTemplate
                        }
                    });

                    alertCountSent++;
                }
            }
            await _alertRepository.AddAlertLog(currentSchoolYear, AlertTypeEnum.Message.Value, "0", "0", alertCountSent.ToString());

            // Commit all log entries.
            await _alertRepository.SaveChanges();

            return(alertCountSent);
        }
Exemplo n.º 16
0
        public async Task <int> SendAlerts()
        {
            var customParameters = _customParametersProvider.GetParameters();
            var enabledFeauter   = customParameters.featureToggle.Select(x => x.features.Where(i => i.enabled && i.studentAbc != null)).FirstOrDefault().FirstOrDefault().studentAbc.missingAssignments;

            if (!enabledFeauter)
            {
                return(0);
            }

            var alertTypes = await _typesRepository.GetAlertTypes();

            var alertAssignment = alertTypes.Where(x => x.AlertTypeId == AlertTypeEnum.Assignment.Value).FirstOrDefault();

            var assignmentThreshold = alertAssignment.Thresholds.Where(x => x.ThresholdTypeId == ThresholdTypeEnum.Assignment.Value).FirstOrDefault();

            var currentSchoolYear = await _alertRepository.getCurrentSchoolYear();

            // Find students that have surpassed the threshold.
            var studentsOverThreshold = await _alertRepository.studentsOverThresholdAssignment(assignmentThreshold.ThresholdValue, customParameters.descriptors.gradeBookMissingAssignmentTypeDescriptors, customParameters.descriptors.missingAssignmentLetterGrade);

            var alertCountSent = 0;

            // Send alerts to the parents of these students.
            foreach (var s in studentsOverThreshold)
            {
                var imageUrl = await _imageProvider.GetStudentImageUrlForAlertsAsync(s.StudentUniqueId);

                // For each parent that wants to receive alerts
                foreach (var p in s.StudentParentAssociations)
                {
                    var parentAlert   = p.Parent.ParentAlert;
                    var wasSentBefore = await _alertRepository.wasSentBefore(p.Parent.ParentUniqueId, s.StudentUniqueId, s.ValueCount.ToString(), currentSchoolYear, AlertTypeEnum.Assignment.Value);

                    if (parentAlert == null || parentAlert.AlertTypeIds == null || !parentAlert.AlertTypeIds.Contains(AlertTypeEnum.Assignment.Value) || wasSentBefore)
                    {
                        continue;
                    }

                    string to;
                    string template;
                    string subjectTemplate = "Family Portal: Missing Assignment Alert";

                    if (parentAlert.PreferredMethodOfContactTypeId == MethodOfContactTypeEnum.SMS.Value && p.Parent.Telephone != null)
                    {
                        to = p.Parent.Telephone;
                        subjectTemplate = await TranslateText(p.Parent.LanguageCode, subjectTemplate);

                        template = FillSMSTemplate(s);
                        template = await TranslateText(p.Parent.LanguageCode, template);

                        await _smsProvider.SendMessageAsync(to, subjectTemplate, template);

                        alertCountSent++;
                    }
                    else if (parentAlert.PreferredMethodOfContactTypeId == MethodOfContactTypeEnum.Email.Value && p.Parent.Email != null)
                    {
                        to = p.Parent.Email;
                        subjectTemplate = await TranslateText(p.Parent.LanguageCode, subjectTemplate);

                        template = FillEmailTemplate(s, assignmentThreshold, imageUrl);
                        template = await TranslateText(p.Parent.LanguageCode, template);

                        await _messagingProvider.SendMessageAsync(to, null, null, subjectTemplate, template);

                        alertCountSent++;
                    }
                    else if (parentAlert.PreferredMethodOfContactTypeId == MethodOfContactTypeEnum.Notification.Value)
                    {
                        string pushNoSubjectTemplate = $"Missing Assignment Alert: {s.FirstName} {s.LastSurname}";
                        string pushNoBodyTemplate    = $"Has a new missing assignment, for a total of {s.ValueCount}";
                        pushNoSubjectTemplate = await TranslateText(p.Parent.LanguageCode, pushNoSubjectTemplate);

                        pushNoBodyTemplate = await TranslateText(p.Parent.LanguageCode, pushNoBodyTemplate);

                        await _pushNotificationProvider.SendNotificationAsync(new NotificationItemModel
                        {
                            personUniqueId = p.Parent.ParentUniqueId,
                            personType     = "Parent",
                            notification   = new Notification
                            {
                                title = pushNoSubjectTemplate, //Grade Alert: {s.FirstName} {s.LastSurname}
                                body  = pushNoBodyTemplate     //Has one or more grades below 70
                            }
                        });

                        alertCountSent++;
                    }

                    // Save in log
                    await _alertRepository.AddAlertLog(currentSchoolYear, AlertTypeEnum.Assignment.Value, p.Parent.ParentUniqueId, s.StudentUniqueId, s.ValueCount.ToString());
                }
            }

            // Commit all log entries.
            await _alertRepository.SaveChanges();

            return(alertCountSent);
        }
        public async Task <int> SendAlerts()
        {
            return(0); //  Disabled for now since we are using Ada Absences

            var customParameters = _customParametersProvider.GetParameters();

            var alertTypes = await _typesRepository.GetAlertTypes();

            var alertAbsence = alertTypes.Where(x => x.AlertTypeId == AlertTypeEnum.Absence.Value).FirstOrDefault();

            var excusedThreshold   = alertAbsence.Thresholds.Where(x => x.ThresholdTypeId == ThresholdTypeEnum.ExcusedAbsence.Value).FirstOrDefault();
            var tardyThreshold     = alertAbsence.Thresholds.Where(x => x.ThresholdTypeId == ThresholdTypeEnum.Tardy.Value).FirstOrDefault();
            var unexcusedThreshold = alertAbsence.Thresholds.Where(x => x.ThresholdTypeId == ThresholdTypeEnum.UnexcusedAbsence.Value).FirstOrDefault();

            var currentSchoolYear = await _alertRepository.getCurrentSchoolYear();

            // Find students that have surpassed the threshold.
            var studentsOverThreshold = await _alertRepository.studentsOverThresholdAbsence(excusedThreshold.ThresholdValue, unexcusedThreshold.ThresholdValue, tardyThreshold.ThresholdValue, customParameters.descriptors.excusedAbsenceDescriptorCodeValue, customParameters.descriptors.unexcusedAbsenceDescriptorCodeValue, customParameters.descriptors.tardyDescriptorCodeValue);


            var alertCountSent = 0;

            // Send alerts to the parents of these students.
            foreach (var s in studentsOverThreshold)
            {
                var imageUrl = await _imageProvider.GetStudentImageUrlForAlertsAsync(s.StudentUniqueId);

                // For each parent that wants to receive alerts
                foreach (var p in s.StudentParentAssociations)
                {
                    var parentAlert   = p.Parent.ParentAlert;
                    var wasSentBefore = await _alertRepository.wasSentBefore(p.Parent.ParentUniqueId, s.StudentUniqueId, s.AbsenceCount.ToString(), currentSchoolYear, AlertTypeEnum.Absence.Value);

                    if (parentAlert == null || parentAlert.AlertTypeIds == null || !parentAlert.AlertTypeIds.Contains(AlertTypeEnum.Absence.Value) || wasSentBefore)
                    {
                        continue;
                    }

                    string to;
                    string template;


                    if (parentAlert.PreferredMethodOfContactTypeId == MethodOfContactTypeEnum.SMS.Value && p.Parent.Telephone != null && p.Parent.SMSDomain != null)
                    {
                        to       = p.Parent.Telephone + p.Parent.SMSDomain;
                        template = FillSMSTemplate(s);
                        await _smsProvider.SendMessageAsync(to, "Parent Portal: Attendance Alert", template);

                        alertCountSent++;
                    }
                    else if (p.Parent.Email != null)
                    {
                        to       = p.Parent.Email;
                        template = FillEmailTemplate(s, excusedThreshold, unexcusedThreshold, tardyThreshold, imageUrl);
                        await _messagingProvider.SendMessageAsync(to, null, null, "Parent Portal: Attendance Alert", template);

                        alertCountSent++;
                    }

                    // Save in log
                    await _alertRepository.AddAlertLog(currentSchoolYear, AlertTypeEnum.Absence.Value, p.Parent.ParentUniqueId, s.StudentUniqueId, s.AbsenceCount.ToString());
                }
            }

            // Commit all log entries.
            await _alertRepository.SaveChanges();

            return(alertCountSent);
        }
        public async Task <StudentAssessment> GetStudentAssessmentsAsync(int studentUsi)
        {
            var model = new StudentAssessment();

            foreach (var assessmentParam in _customParametersProvider.GetParameters().assessments)
            {
                var assessment = await GetStudentAssessmentAsync(studentUsi, assessmentParam.assessmentReportingMethodTypeDescriptor, assessmentParam.title, assessmentParam.assessmentIdentifiers, assessmentParam.shortDescription);

                if (assessment != null)
                {
                    assessment.SubSections = FillNotTakenSubsections(assessmentParam.assessmentIdentifiers, assessment.SubSections);
                }
                else // Add default empty ones
                {
                    // Student hasnt taken assessment
                    assessment = FillNotTakenassessment(assessmentParam.title, assessmentParam.assessmentIdentifiers, assessmentParam.shortDescription);
                }
                assessment.ExternalLink = assessmentParam.externalLink;
                model.Assessments.Add(assessment);
            }

            var customparams = _customParametersProvider.GetParameters();

            model.AssessmentIndicators = new List <Assessment>();
            model.StarAssessments      = new List <Assessment>();
            model.AccessAssessments    = new List <Assessment>();

            foreach (var assessment in customparams.arcAssessments)
            {
                if (assessment.assessmentReportingMethodTypeDescriptor == "ARC Power Goal Abbreviation")
                {
                    var performanceLevel = await _studentRepository.GetStudentAssesmentPerformanceLevel(studentUsi, assessment.assessmentReportingMethodTypeDescriptor, assessment.title);

                    if (performanceLevel == null)
                    {
                        performanceLevel        = new Assessment();
                        performanceLevel.Title  = assessment.title;
                        performanceLevel.Result = "-";
                        performanceLevel.PerformanceLevelMet      = "Not Yet Taken";
                        performanceLevel.ReportingMethodCodeValue = assessment.assessmentReportingMethodTypeDescriptor;
                    }
                    else
                    {
                        performanceLevel.Result = performanceLevel.PerformanceLevelMet;
                    }
                    model.ArcAssessments.Add(performanceLevel);
                }
                else
                {
                    var newAssessment = await _studentRepository.GetStudentAssesmentScore(studentUsi, assessment.assessmentReportingMethodTypeDescriptor, assessment.title);

                    var objectivesAssessments = await _studentRepository.GetStudentObjectiveAssessments(studentUsi);

                    if (newAssessment == null)
                    {
                        newAssessment        = new Assessment();
                        newAssessment.Title  = assessment.title;
                        newAssessment.Result = "-";
                        newAssessment.PerformanceLevelMet      = "Not Yet Taken";
                        newAssessment.ReportingMethodCodeValue = assessment.assessmentReportingMethodTypeDescriptor;
                    }
                    else
                    {
                        newAssessment.ObjectiveAssessments = objectivesAssessments.Where(x => x.AssessmentIdentifier == newAssessment.Identifier).ToList();
                    }
                    model.ArcAssessments.Add(newAssessment);
                }
            }

            foreach (var assessment in customparams.assessmentIndicators)
            {
                var newAssessment = new Assessment();
                if (assessment.getPerformanceLevel)
                {
                    newAssessment = await _studentRepository.GetStudentAssesmentPerformanceLevel(studentUsi, assessment.assessmentReportingMethodTypeDescriptor, assessment.title);
                }
                else
                {
                    newAssessment = await _studentRepository.GetStudentAssesmentScore(studentUsi, assessment.assessmentReportingMethodTypeDescriptor, assessment.title);
                }

                if (newAssessment == null)
                {
                    newAssessment        = new Assessment();
                    newAssessment.Title  = assessment.title;
                    newAssessment.Result = "0";
                    newAssessment.PerformanceLevelMet      = "Not Yet Taken";
                    newAssessment.ReportingMethodCodeValue = assessment.assessmentReportingMethodTypeDescriptor;
                    newAssessment.Interpretation           = "";
                }
                else if (assessment.getPerformanceLevel)
                {
                    newAssessment.Interpretation = InterpretAssessmentPerformanceLevel(newAssessment.PerformanceLevelMet);
                }
                else
                {
                    newAssessment.Interpretation = "";
                }

                model.AssessmentIndicators.Add(newAssessment);
            }

            foreach (var assessment in customparams.starAssessments)
            {
                var newAssessment = await _studentRepository.GetStudentAssesmentScore(studentUsi, assessment.assessmentReportingMethodTypeDescriptor, assessment.title);

                var performanceLevel = await _studentRepository.GetStudentAssesmentPerformanceLevel(studentUsi, assessment.assessmentReportingMethodTypeDescriptor, assessment.title);

                if (newAssessment == null)
                {
                    newAssessment        = new Assessment();
                    newAssessment.Title  = assessment.title;
                    newAssessment.Result = "0";
                    newAssessment.PerformanceLevelMet      = "Not Yet Taken";
                    newAssessment.ReportingMethodCodeValue = assessment.assessmentReportingMethodTypeDescriptor;
                    newAssessment.Interpretation           = "";
                }
                if (performanceLevel != null)
                {
                    newAssessment.Interpretation      = InterpretAssessmentPerformanceLevel(performanceLevel.PerformanceLevelMet);
                    newAssessment.PerformanceLevelMet = performanceLevel.PerformanceLevelMet;
                }



                model.StarAssessments.Add(newAssessment);
            }

            foreach (var assessment in customparams.accessAssessments)
            {
                var assessments = await _studentRepository.GetACCESSStudentAssesmentScore(studentUsi, assessment.assessmentReportingMethodTypeDescriptor, assessment.title);

                var objectivesAssessments = await _studentRepository.GetStudentObjectiveAssessments(studentUsi);

                var proficiencyAssessments = await _studentRepository.GetACCESSStudentAssesmentScore(studentUsi, assessment.assessmentReportingMethodTypeDescriptorProficiency, assessment.title);

                //if (assessments.Count == proficiencyAssessments.Count)
                //    foreach (var a in assessments)
                //        a.ProficiencyLevel = proficiencyAssessments[assessments.FindIndex(x => x.Title == a.Title && x.ReportingMethodCodeValue == a.ReportingMethodCodeValue && x.Version == a.Version)].Result;

                foreach (var item in assessments)
                {
                    item.ObjectiveAssessments = objectivesAssessments.Where(x => x.AssessmentIdentifier == item.Identifier).ToList();
                }

                model.AccessAssessments.AddRange(assessments);
            }

            return(model);
        }