Esempio n. 1
0
        [AuthorizationFilter("DistrictAdmin, Teacher, Student", true, new[] { AppPermissionType.User })]  // - System Admin
        public ActionResult Search(string query, IntList includedSearchType)
        {
            Trace.Assert(Context.PersonId.HasValue);

            IDictionary <SearchTypeEnum, Func <string, object> > searchActionRegister = new Dictionary <SearchTypeEnum, Func <string, object> >
            {
                { SearchTypeEnum.Student, SearchStudents },
                { SearchTypeEnum.Staff, SearchStaffs },
                { SearchTypeEnum.Announcements, SchoolLocator.AnnouncementFetchService.GetAnnouncementsByFilter },
                { SearchTypeEnum.Attachments, SearchAttachments },
                { SearchTypeEnum.Classes, SchoolLocator.ClassService.SearchClasses }
            };

            if (Context.Role == CoreRoles.DISTRICT_ADMIN_ROLE)
            {
                searchActionRegister.Add(SearchTypeEnum.Group, q => SchoolLocator.GroupService.GetGroups(Context.PersonId.Value, q));
            }

            IDictionary <SearchTypeEnum, object> searchRes = new Dictionary <SearchTypeEnum, object>();

            query = query.ToLower();
            foreach (var keyAction in searchActionRegister.Where(keyAction => IsTypeIncluded(includedSearchType, keyAction.Key)))
            {
                searchRes.Add(keyAction.Key, keyAction.Value(query));
            }
            return(Json(SearchViewData.Create(searchRes)));
        }
        public string searchClasses(string searchquery)
        {
            ClassDbHandler        handler = new ClassDbHandler();
            List <Class>          classes = handler.getSearchClasses(searchquery);
            List <SearchViewData> cl      = new List <SearchViewData>();

            foreach (var c in classes)
            {
                SearchViewData s = new SearchViewData();
                s.className    = c.name;
                s.classDesc    = c.desc;
                s.classCreator = c.User.fname + " " + c.User.lname;

                if (handler.IsUserJoined(1, c.Id))
                {
                    s.joined = true;
                }
                else
                {
                    s.joined = false;
                }
                cl.Add(s);
            }
            var scr  = new JavaScriptSerializer();
            var data = scr.Serialize(cl);

            return(data);
        }
Esempio n. 3
0
        public async Task <ActionResult> Search(long?categoryId, string keyword)
        {
            var cats = new List <CategoryUiModel>();

            if (categoryId.HasValue)
            {
                cats = await _categoryService.GetParents(categoryId.Value);
            }

            var model = new SearchViewData
            {
                Keyword    = keyword,
                Categories = cats
            };

            return(View(model));
        }
        public void GetIndexableFields_GivenSearchViewData_ReturnTitleField()
        {
            var data = new SearchViewData
                {
                    Identifier       = "00000000-0000-0000-0000-000000000001",
                    Title    = "P7 MIX",
                    Type     = "Radio",
                    FreeText = "test text",
                    PubStartDate = "2012-02-21T16:03:00",
                    PubEndDate = "2012-02-22T00:03:00"
                };

            var result = data.GetIndexableFields().ToList();

            Assert.AreEqual(result.Any(item => item.Key == "Id" && item.Value == "00000000-0000-0000-0000-000000000001"), true);
            Assert.AreEqual(result.Any(item => item.Key == "Title" && item.Value == "P7 MIX"), true);
            Assert.AreEqual(result.Any(item => item.Key == "Type" && item.Value == "Radio"), true);
            Assert.AreEqual(result.First(item => item.Key == "FreeText").Value, ("test text "));
            Assert.AreEqual(result.First(item => item.Key == "PubStartDate").Value, ("2012-02-21T16:03:00"));
            Assert.AreEqual(result.First(item => item.Key == "PubEndDate").Value, ("2012-02-22T00:03:00"));
        }