/// <summary> /// 検索 /// </summary> /// <param name="searchKey">検索条件</param> /// <returns>処理結果</returns> public IActionResult GetBookItems(BookItemSearchKey searchKey) { var data = this._dbContext.Book .WhereIf(searchKey.From.HasValue, x => x.Date >= searchKey.From) .WhereIf(searchKey.To.HasValue, x => x.Date <= searchKey.To) .WhereIf(!string.IsNullOrEmpty(searchKey.Title), x => x.Title.Contains(searchKey.Title)) .WhereIf(!string.IsNullOrEmpty(searchKey.PublishYear), x => x.PublishYear == searchKey.PublishYear) .WhereIf(searchKey.RecommendFlg != 0, x => x.RecommendFlg == searchKey.RecommendFlg.ToString()) .Join(this._dbContext.Author , b => b.AuthorCd , a => a.AuthorCd , (b, a) => new { Book = b, Author = a }) .WhereIf(!string.IsNullOrEmpty(searchKey.Author), x => x.Author.AuthorName.Contains(searchKey.Author)) .Join(this._dbContext.Publisher , b => b.Book.PublisherCd , p => p.PublisherCd , (b, p) => new { b.Book, b.Author, Publisher = p }) .WhereIf(!string.IsNullOrEmpty(searchKey.Publisher), x => x.Publisher.PublisherName.Contains(searchKey.Publisher)) .Join(this._dbContext.Class , b => b.Book.ClassCd , c => c.ClassCd , (b, c) => new { b.Book, b.Author, b.Publisher, Class = c }) .WhereIf(!string.IsNullOrEmpty(searchKey.Class), x => x.Class.ClassName.Contains(searchKey.Class)) .OrderBy(x => x.Book.Date) .Select(x => new BookItem { Autonumber = x.Book.Autonumber, DateTime = x.Book.Date.Value, Title = x.Book.Title ?? string.Empty, AuthorCd = x.Book.AuthorCd, Author = x.Author.AuthorName ?? string.Empty, PublisherCd = x.Book.PublisherCd, Publisher = x.Publisher.PublisherName ?? string.Empty, ClassCd = x.Book.ClassCd, Class = x.Class.ClassName ?? string.Empty, PublishYear = x.Book.PublishYear ?? string.Empty, PageCount = x.Book.PageCount, RecommendFlg = x.Book.RecommendFlg ?? string.Empty, }) .ToArray(); return(new OkObjectResult(data)); }
public IActionResult GetBookItems([FromQuery] BookItemSearchKey searchKey) => _bookService.GetBookItems(searchKey);