コード例 #1
0
        public IActionResult SearchWith(string keyword)
        {
            var resultsList = new List <SearchResult>();

            if (keyword is null || keyword == "")
            {
                return(Json(resultsList));
            }

            var blogResults = searchService.BlogsWithKeyword(keyword).Take(3);

            foreach (var blg in blogResults)
            {
                var owner     = blogService.Owner(blg.Id);
                var newResult = new BlogSearchResult(keyword, blg, owner);
                resultsList.Add(newResult);
            }

            var userResults = searchService.UsersWithKeyword(keyword).Take(3);

            foreach (var usr in userResults)
            {
                var blogs = userBlogService.GetBlogsForUser(usr.Id);
                resultsList.Add(new UserSearchResult(keyword, new UserNoPass(usr), blogs));
            }

            var sectionResults = searchService.SectionsWithKeyword(keyword).Take(3);

            foreach (var sect in sectionResults)
            {
                var blogs = sectionsService.BlogsUsingSectId(sect.Id);
                resultsList.Add(new SectionSearchResult(keyword, sect, blogs));
            }

            return(Json(resultsList));
        }
コード例 #2
0
        public IActionResult SectionDetails(long sectId)
        {
            var section = sectionsService.GetSectionWithId(sectId);

            if (section is null)
            {
                return(NotFound("The Section you are looking for has been deleted or is unaccessible"));
            }

            var posts = sectionsService.AllPosts(sectId).ToList();
            var blogs = sectionsService.BlogsUsingSectId(sectId);

            return(View("SectionDetails", new DetailedSectionVm()
            {
                Id = sectId,
                BlogId = (section.IsSystemCreated)? -1 : blogs.FirstOrDefault().Id,
                // daca nu este systemCreated, tin minte la ce blog apartine cand afisez sectiunea
                OwnerId = (section.IsSystemCreated) ? -1 : blogs.FirstOrDefault().UserId,
                Name = section.Name,
                Posts = posts,
                PhotoId = section.PhotoId,
                IsSystemCreated = section.IsSystemCreated
            }));
        }