public Book getSingleBook(BookViewWithISBN bookID) { Book foundBook = bookRepo.FindBy(b => b.ID == bookID.ID).FirstOrDefault(); Book foundBookISBN = bookRepo.FindBy(b => b.isbn == bookID.isbn).FirstOrDefault(); if (foundBook != null) { return(foundBook); } else { return(foundBookISBN); } }
public IEnumerable <Review> getReviewFilteredPaginated(BookViewWithISBN book, int currentPage, int pageSize, string filterAfter, string filterField, string sortMethod) { IEnumerable <Review> reviews = null; bool ok = filterAfter.Equals("null"); if (!ok) { var parameter = Expression.Parameter(typeof(Review), "b"); var predicate = Expression.Lambda <Func <Review, bool> >(Expression.Equal(Expression.PropertyOrField(parameter, filterAfter), Expression.Constant(filterField)), parameter); if (sortMethod.CompareTo("ASCENDING") == 0) { reviews = reviewRepo.GetSortOrFiltered(p => p.book.ID == book.ID || p.book.isbn == book.isbn, null, currentPage, pageSize, new SortExpression <Review>(p => p.ID, ListSortDirection.Ascending)); } else if (sortMethod.CompareTo("DESCENDING") == 0) { reviews = reviewRepo.GetSortOrFiltered(p => p.book.ID == book.ID || p.book.isbn == book.isbn, null, currentPage, pageSize, new SortExpression <Review>(p => p.ID, ListSortDirection.Descending)); } else { reviews = reviewRepo.GetSortOrFiltered(p => p.book.ID == book.ID || p.book.isbn == book.isbn, null, currentPage, pageSize, null); } } else { if (sortMethod.CompareTo("ASCENDING") == 0) { reviews = reviewRepo.GetSortOrFiltered(p => p.book.ID == book.ID || p.book.isbn == book.isbn, null, currentPage, pageSize, new SortExpression <Review>(p => p.ID, ListSortDirection.Ascending)); } else if (sortMethod.CompareTo("DESCENDING") == 0) { reviews = reviewRepo.GetSortOrFiltered(p => p.book.ID == book.ID || p.book.isbn == book.isbn, null, currentPage, pageSize, new SortExpression <Review>(p => p.ID, ListSortDirection.Descending)); } else { reviews = reviewRepo.GetSortOrFiltered(p => p.book.ID == book.ID || p.book.isbn == book.isbn, null, currentPage, pageSize, null); } } return(reviews); }
public HttpResponseMessage GetReviewPagined(HttpRequestMessage request, [FromUri] PagingParameterModel pagingparametermodel, [FromUri] string filterAfter, [FromUri] string filterField, [FromUri] string sortMethod, [FromUri] string IDURL, [FromUri] string isbn) { return(CreateHttpResponse(request, () => { int CurrentPage = pagingparametermodel.pageNumber; int PageSize = pagingparametermodel.pageSize; BookViewWithISBN bookID = new BookViewWithISBN(); if (IDURL.Equals("null")) { bookID.ID = 0; } else { bookID.ID = Int32.Parse(IDURL); } if (isbn.Equals("null")) { bookID.isbn = "0"; } else { bookID.isbn = isbn; } IEnumerable <Review> reviews = service.getReviewFilteredPaginated(bookID, CurrentPage, PageSize, filterAfter, filterField, sortMethod); List <ReviewView> reviewList = new List <ReviewView>(); foreach (Review b in reviews) { ReviewView obj = new ReviewView(); obj.reviewText = b.reviewText; obj.userID = b.userID; obj.bookID = b.bookID; obj.ID = b.ID; obj.ratingScore = 0; obj.addedTime = b.addedTime; UserDataNoPass usr = servUs.getUserAfterID(obj.userID); if (usr != null) { obj.user = usr; } else { obj.user = new UserDataNoPass(); } RatingView rati = servRat.getRating(obj.bookID, obj.userID); if (rati != null) { obj.ratingScore = rati.ratingScore; } else { obj.ratingScore = 0; } reviewList.Add(obj); } HttpResponseMessage response = null; response = request.CreateResponse(HttpStatusCode.OK, reviewList, JsonMediaTypeFormatter.DefaultMediaType); return response; })); }
public HttpResponseMessage GetASingleBook(HttpRequestMessage request, BookViewWithISBN bookID) { return(CreateHttpResponse(request, () => { Book b = service.getSingleBook(bookID); if (b != null) { BookViewDetail obj = new BookViewDetail(); obj.title = b.title; obj.bookPic = b.bookPic; obj.releaseDate = b.releaseDate; obj.series = b.series; obj.initialReleaseDate = b.initialReleaseDate; obj.ID = b.ID; obj.isbn = b.isbn; obj.noPage = b.noPage; obj.edition = b.edition; obj.bLanguage = b.bLanguage; obj.publisherSite = b.publisherSite; obj.bookFormat = b.bookFormat; obj.publisher = b.publisher; obj.overview = b.overview; UserDataViewID userViewID = new UserDataViewID(); List <GenreViewName> genreView = Mapper.Map <List <Genre>, List <GenreViewName> >(b.genre.ToList()); List <AuthorViewName> authorView = Mapper.Map <List <Author>, List <AuthorViewName> >(b.author.ToList()); double average = 0; int searchID = Int32.Parse(bookID.loggedUserID); BookXUser sol = b.bookXuser.FirstOrDefault(a => a.user.ID == searchID); if (sol != null) { UserData rez = sol.user; if (rez != null) { userViewID = Mapper.Map <UserData, UserDataViewID>(rez); } } if (b.rating.Select(x => x.ratingScore).Any()) { average = b.rating.Select(x => x.ratingScore).Average(); } obj.user = userViewID; obj.author = authorView; obj.genre = genreView; obj.rating = average; HttpResponseMessage response = null; response = request.CreateResponse(HttpStatusCode.OK, obj, JsonMediaTypeFormatter.DefaultMediaType); return response; } else { HttpResponseMessage response = null; BookViewDetail obj = new BookViewDetail(); response = request.CreateResponse(HttpStatusCode.OK, obj, JsonMediaTypeFormatter.DefaultMediaType); return response; } })); }