コード例 #1
0
        public SearchModel Result(string searchKey)
        {
            SearchModel model = new SearchModel();
            List <AuthorSearchModel> authors    = new List <AuthorSearchModel>();
            List <BookSearchModel>   books      = new List <BookSearchModel>();
            List <PublisherModel>    publishers = new List <PublisherModel>();

            List <CategoryTagAssigment> entity = _categoryTagAssignment.Search(searchKey);

            foreach (var item in entity)
            {
                AuthorSearchModel author    = new AuthorSearchModel();
                BookSearchModel   book      = new BookSearchModel();
                PublisherModel    publisher = new PublisherModel();

                author.Id   = item.AuthorId;
                author.Name = item.AuthorName + " " + item.AuthorSurname;

                book.Id   = item.BookId;
                book.Name = item.BookName;

                publisher.Id   = item.PublisherId;
                publisher.Name = item.PublisherName;

                authors.Add(author);
                books.Add(book);
                publishers.Add(publisher);
            }

            model.Authors    = authors.GroupBy(x => x.Id).Select(x => x.First()).ToList();
            model.Books      = books.GroupBy(x => x.Id).Select(x => x.First()).ToList();
            model.Publishers = publishers.GroupBy(x => x.Name).Select(x => x.First()).ToList();

            return(model);
        }
コード例 #2
0
        /*
         * This controls searching for an author feature.
         * It will return a list of authors.
         */
        public ActionResult SearchForAuthor(string txtNameSearch)
        {
            BookContext b = new BookContext();

            var authorSearch = new AuthorSearchModel();

            authorSearch.authorNameSearch = txtNameSearch;

            authorSearch.authorsList = (from book in b.Books
                                        where book.authors.Contains(txtNameSearch)
                                        select book.authors).Distinct().ToList();

            return(View(authorSearch));
        }