/// <summary>
        /// Gets the EdFiGridWatchListModel; the structure will be determined
        /// by the logged in user.
        /// </summary>
        /// <param name="staffUSI">The staff USI.</param>
        /// <param name="schoolId">The school identifier.</param>
        /// <param name="localEducationAgencyId">The local education agency identifier.</param>
        /// <param name="sectionId">The section identifier.</param>
        /// <param name="watchListSelections">The watch list selections.</param>
        /// <returns>
        /// An <see cref="EdFiGridWatchListModel" /> loaded with data for the currently logged in user.
        /// </returns>
        public virtual EdFiGridWatchListModel GetEdFiGridWatchListModel(long staffUSI, int? schoolId, int? localEducationAgencyId = null, long? sectionId = null, List<NameValuesType> watchListSelections = null)
        {
            var watchListDataState = new WatchListDataState();

            var defaultStudentMetricsProviderOptions = new StudentMetricsProviderQueryOptions
            {
                StaffUSI = staffUSI,
                SchoolId = schoolId,
                LocalEducationAgencyId = localEducationAgencyId,
                GetAllMetrics = true
            };

            watchListDataState.Students = GetStudentList(defaultStudentMetricsProviderOptions);
            watchListDataState.Metrics = GetStudentMetrics(defaultStudentMetricsProviderOptions);

            var grades = watchListDataState.Students.Select(data => new { data.GradeLevel, data.GradeLevelSortOrder }).Distinct().OrderBy(order => order.GradeLevelSortOrder).ToList();
            watchListDataState.Grades = grades.Select(data => new EdFiGridWatchListSelectionItemModel { DisplayValue = data.GradeLevel, Name = data.GradeLevel }).ToList();

            watchListDataState.MetricIds = watchListDataState.Metrics.Select(data => data.MetricId).Distinct().ToList();

            var results = new List<TeacherSection>();

            if (schoolId.HasUsableValue())
            {
                results = (TeacherSectionRepository.GetAll()
                    .Where(data => data.StaffUSI == staffUSI && data.SchoolId == schoolId)
                    .OrderBy(data => data.SubjectArea).ThenBy(data => data.CourseTitle)
                    .ThenBy(data => data.ClassPeriod).ThenBy(data => data.LocalCourseCode)
                    .ThenBy(data => data.TeacherSectionId)).ToList();
            }

            if (sectionId.HasUsableValue())
            {
                watchListDataState.CurrentSectionId = sectionId.Value;
            }

            watchListDataState.Sections = results.ToDictionary(
                key => key.TeacherSectionId,
                value => String.Format(SectionDescriptionFormat, value.SubjectArea, value.LocalCourseCode, value.CourseTitle, value.ClassPeriod, value.TermType)
            );

            // determine if the section id has a value and if that value is
            // contained in the sections dictionary above; if not the section
            // id is really a watch list id
            var isWatchListSection = sectionId.HasUsableValue() && (!(sectionId.Value <= int.MaxValue ? (int?) sectionId.Value : null).HasValue || !watchListDataState.Sections.ContainsKey((int) sectionId.Value));

            MetricBasedWatchList watchList = null;
            List<NameValuesType> watchListSelectedOptions = null;

            if (isWatchListSection)
            {
                watchList = GetWatchListData(sectionId.Value);
                watchListSelectedOptions = GetWatchListSelectionData(sectionId.Value);
            }

            var isWatchListChanged = false;
            // if this parameter is set then we are coming back from a watch
            // list and need to reset to the last values selected
            if (watchListSelections != null)
            {
                isWatchListChanged = IsWatchListChanged(watchListSelections, watchListSelectedOptions);
                watchListSelectedOptions = watchListSelections;
            }

            var searchLinkRequest = new WatchListLinkRequest
            {
                LocalEducationAgencyId = localEducationAgencyId,
                SchoolId = schoolId,
                StaffUSI = staffUSI,
                MetricBasedWatchListId = (int?)sectionId,
                ResourceName = "MetricsBasedWatchListSearch"
            };

            // create the watch list model
            var watchListModel = new EdFiGridWatchListModel
            {
                WatchListName = (watchList != null && watchList.WatchListName != string.Empty ? watchList.WatchListName : "New Dynamic List"),
                WatchListDescription = (watchList != null ? watchList.WatchListDescription : string.Empty),
                WatchListUrl = GeneralLinks.MetricsBasedWatchList("MetricsBasedWatchList"),
                WatchListSearchUrl = WatchListLinkProvider.GenerateLink(searchLinkRequest),
                IsWatchListChanged = isWatchListChanged,
                IsWatchListShared = watchList != null && watchList.IsWatchListShared,
                Tabs = TabFactory.CreateAllTabs(watchListDataState)
            };

            // load any available selections into the model
            if (watchListSelectedOptions != null)
            {
                LoadWatchListSelections(watchListModel, watchListSelectedOptions);
            }

            return watchListModel;
        }
        /// <summary>
        /// Generates the return link based upon the location the link is for.
        /// </summary>
        /// <param name="request">The request containing the location data.</param>
        /// <returns>A string representing the return link.</returns>
        public string GenerateReturnLink(MetricsBasedWatchListSearchRequest request)
        {
            var returnUrl = string.Empty;

            var pageOptions = MetricBasedWatchListOptionRepository.GetAll()
                .Where(option => option.MetricBasedWatchListId == request.MetricsBasedWatchListId)
                .ToList();

            var schoolIdOption = pageOptions.SingleOrDefault(data => data.Name == "SchoolId");

            var leaIdOption = pageOptions.SingleOrDefault(data => data.Name == "LocalEducationAgencyId");

            if (schoolIdOption != null)
            {
                var watchListStaffUSI = pageOptions.Any(data => data.Name == "StaffUSI")
                    ? long.Parse(pageOptions.Single(data => data.Name == "StaffUSI").Value)
                    : request.StaffUSI;

                var resourceName =
                    pageOptions.SingleOrDefault(data => data.Name == "PageController");
                var demographic =
                    pageOptions.SingleOrDefault(data => data.Name == "PageDemographic");
                var schoolCategory =
                    pageOptions.SingleOrDefault(data => data.Name == "PageSchoolCategory");
                var grade =
                    pageOptions.SingleOrDefault(data => data.Name == "PageGrade");

                var watchListLink = new WatchListLinkRequest
                {
                    SchoolId = int.Parse(schoolIdOption.Value),
                    StaffUSI = watchListStaffUSI,
                    MetricBasedWatchListId = request.MetricsBasedWatchListId,
                    ResourceName = resourceName != null ? resourceName.Value : string.Empty,
                    Demographic = demographic != null ? demographic.Value : string.Empty,
                    SchoolCategory = schoolCategory != null ? schoolCategory.Value : string.Empty,
                    Grade = grade != null ? grade.Value : string.Empty
                };

                returnUrl = WatchListLinkProvider.GenerateLink(watchListLink);
            }
            else if (leaIdOption != null)
            {
                return MetricsBasedWatchListMenuService.Get(new MetricsBasedWatchListMenuRequest
                {
                    StaffUSI = request.StaffUSI.GetValueOrDefault(),
                    LocalEducationAgencyId = int.Parse(leaIdOption.Value),
                }).Single(mbwl => mbwl.SectionId == request.MetricsBasedWatchListId).Href;
            }

            return returnUrl;
        }
Пример #3
0
        /// <summary>
        /// Determines which link generator to use based upon the values passed
        /// to the method.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>A Url for a resource.</returns>
        public string GenerateLink(WatchListLinkRequest request)
        {
            var link = string.Empty;

            if (!request.SchoolId.HasUsableValue() && !request.LocalEducationAgencyId.HasUsableValue())
                return link;

            //TODO: Start using this again after the staff USI issue is fixed
            //if (!request.StaffUSI.HasUsableValue())
            //    return link;

            var educationOrganizationId = request.SchoolId.HasUsableValue() ? request.SchoolId.Value : request.LocalEducationAgencyId.Value;

            // this will be the case in a delete situation
            var metricsBasedWatchListId = request.MetricBasedWatchListId.HasUsableValue()
                ? request.MetricBasedWatchListId
                : null;
            var studentListType = metricsBasedWatchListId.HasValue
                ? StudentListType.MetricsBasedWatchList.ToString()
                : null;

            switch (request.ResourceName)
            {
                case "GeneralOverview":
                    var staffUSIToUse = request.PageStaffUSI.HasUsableValue() &&
                                        (request.StaffUSI.GetValueOrDefault() !=
                                         request.PageStaffUSI.GetValueOrDefault())
                        ? request.PageStaffUSI.GetValueOrDefault()
                        : request.StaffUSI.GetValueOrDefault();

                    link = StaffAreaLinks.CustomMetricsBasedWatchList(educationOrganizationId, staffUSIToUse,
                        request.ResourceName, metricsBasedWatchListId, null, studentListType);
                    break;
                case "StudentDemographicList":
                    if (request.SchoolId.HasUsableValue())
                        link = SchoolAreaLinks.CustomMetricsBasedWatchListDemographic(educationOrganizationId,
                            request.ResourceName, request.Demographic, metricsBasedWatchListId, studentListType);
                    else if (request.LocalEducationAgencyId.HasUsableValue())
                        link = LocalEducationAgencyAreaLinks.CustomMetricsBasedWatchListDemographic(educationOrganizationId,
                            request.StaffUSI.GetValueOrDefault(), request.ResourceName, request.Demographic, metricsBasedWatchListId, studentListType);
                    break;
                case "StudentSchoolCategoryList":
                    link = LocalEducationAgencyAreaLinks.CustomMetricsBasedWatchListSchoolCategory(educationOrganizationId,
                            request.StaffUSI.GetValueOrDefault(), request.ResourceName, request.SchoolCategory,
                            metricsBasedWatchListId, studentListType);
                    break;
                case "StudentGradeList":
                    link = SchoolAreaLinks.CustomMetricsBasedWatchListGrade(educationOrganizationId,
                        request.ResourceName, request.Grade, metricsBasedWatchListId, studentListType);
                    break;
                case "MetricsBasedWatchListSearch":
                    if (request.SchoolId.HasUsableValue())
                    {
                        link = SchoolAreaLinks.Resource(request.SchoolId.GetValueOrDefault(),
                            "MetricsBasedWatchListSearch");
                    }
                    else if (request.LocalEducationAgencyId.HasUsableValue())
                    {
                        link = LocalEducationAgencyAreaLinks.Resource(
                            request.LocalEducationAgencyId.GetValueOrDefault(), "MetricsBasedWatchListSearch");
                    }
                    break;
            }

            return link;
        }