예제 #1
0
 public SearchBooksResult GetBooksForTiles(TilesSearchModel searchModel)
 {
     using (var db = new Entities.LibraryContext())
     {
         var query = db.Books.AsQueryable();
         if (searchModel.SubCategoryId > 0)
         {
             query = query.Where(a => a.SubCategoryId == searchModel.SubCategoryId);
         }
         if (searchModel.ParentCategoryId > 0)
         {
             query = query.Where(a => a.Categories.ParentCategoryId == searchModel.ParentCategoryId);
         }
         if (!string.IsNullOrEmpty(searchModel.Title))
         {
             query = query.Where(a => a.Title.ToLower().Contains(searchModel.Title.ToLower()));
         }
         var result = new SearchBooksResult
         {
             Success = true,
             Books   = query
                       .Select(a => new BookForSearchViewModel
             {
                 description = a.Description,
                 img_title   = a.Title,
                 tags        = new List <string> {
                     a.Categories.EnglishName
                 },
                 title = a.Title
             }).ToList()
         };
         return(result);
     }
 }
예제 #2
0
 public static SearchBooksResult GetBooks(TilesSearchModel SearchModel)
 {
     return(new BooksManager().GetBooksForTiles(SearchModel, UserId));
 }