コード例 #1
0
        public void TestSearchGradeLevel()
        {
            var parameters = new ItemsSearchParams(null, GradeLevels.High, null, new string[] { }, new string[] { }, false);
            var cards      = SampleItemsSearchRepo.GetItemCards(parameters);
            var cardsCheck = Context.ItemCards.Where(c => GradeLevelsUtils.Contains(GradeLevels.High, c.Grade)).ToList();

            Assert.NotNull(cards);
            Assert.Equal(cards.Count, cardsCheck.Count);
            Assert.Equal(Sort(cards), Sort(cardsCheck));
        }
コード例 #2
0
        public IList <ItemCardViewModel> GetItemCards(ItemsSearchParams parms)
        {
            var query = context.ItemCards.Where(i => i.Grade != GradeLevels.NA && !i.BrailleOnlyItem);

            if (parms == null)
            {
                return(query.ToList());
            }

            int itemId;

            if (int.TryParse(parms.ItemId, out itemId))
            {
                query = query.Where(i => i.ItemKey.ToString().StartsWith(itemId.ToString()));
            }

            if (parms.Grades != GradeLevels.All && parms.Grades != GradeLevels.NA)
            {
                query = query.Where(i => GradeLevelsUtils.Contains(parms.Grades, i.Grade));
            }

            if (parms.Subjects != null && parms.Subjects.Any())
            {
                query = query.Where(i => parms.Subjects.Contains(i.SubjectCode));
                if (parms.InteractionTypes.Any())
                {
                    query = query.Where(i => parms.InteractionTypes.Contains(i.InteractionTypeCode));
                }
                if (parms.ClaimIds.Any())
                {
                    query = query.Where(i => parms.ClaimIds.Contains(i.ClaimCode));
                }
            }

            if (parms.PerformanceOnly)
            {
                query = query.Where(i => i.IsPerformanceItem);
            }

            return(query.OrderBy(i => i.SubjectCode).ThenBy(i => i.Grade).ThenBy(i => i.ClaimCode).ToList());
        }