public IList <BookItem> GetSortedBooks(BookFilteringType filteringType, bool isAsc) { var books = Context.Books.GetSortedBooks(filteringType, isAsc); var bookItems = books.Select(w => Mapper.BookMapper.MapToItem(w)).ToList(); return(bookItems); }
public IList <BookEntity> GetSortedBooks(BookFilteringType filteringType, bool isAsc) { var query = GetSorted(DbSet.AsQueryable(), filteringType, isAsc) .Include(w => w.Author) .Include(w => w.LastUser) .Include(w => w.Publisher); return(query.ToList()); }
private IOrderedQueryable <BookEntity> GetSorted(IQueryable <BookEntity> query, BookFilteringType filteringType, bool isAsc) { switch (filteringType) { case BookFilteringType.ByName: { if (isAsc) { return(query.OrderBy(w => w.Name)); } return(query.OrderByDescending(w => w.Name)); } case BookFilteringType.ByRegNumber: { if (isAsc) { return(query.OrderBy(w => w.RegNumber)); } return(query.OrderByDescending(w => w.RegNumber)); } case BookFilteringType.ByNumberOfPages: { if (isAsc) { return(query.OrderBy(w => w.NumberOfPages)); } return(query.OrderByDescending(w => w.NumberOfPages)); } case BookFilteringType.ByPublicationYear: { if (isAsc) { return(query.OrderBy(w => w.PublicationYear)); } return(query.OrderByDescending(w => w.PublicationYear)); } case BookFilteringType.ByIsBookInLibrary: { if (isAsc) { return(query.OrderBy(w => w.IsBookInLibrary)); } return(query.OrderByDescending(w => w.IsBookInLibrary)); } case BookFilteringType.ByPublisherName: { if (isAsc) { return(query.OrderBy(w => w.Publisher.Name)); } return(query.OrderByDescending(w => w.Publisher.Name)); } case BookFilteringType.ByAuthorName: { if (isAsc) { return(query.OrderBy(w => w.Author.Surname) .ThenBy(w => w.Author.Name) .ThenBy(w => w.Author.Patronymic)); } return(query.OrderByDescending(w => w.Author.Surname) .ThenByDescending(w => w.Author.Name) .ThenByDescending(w => w.Author.Patronymic)); } case BookFilteringType.ByLastUserName: { if (isAsc) { return(query.OrderBy(w => w.LastUser.Login)); } return(query.OrderByDescending(w => w.LastUser.Login)); } } return(query.OrderByDescending(w => w.Id)); }