// ..................................................................................Get Reviews..................................................................... public async Task <IEnumerable <ProductReviewDTO> > GetReviews(string productId, string sortBy, int page) { ProductReviewDTO productReviewDTO = new ProductReviewDTO(sortBy); return(await context.ProductReviews .AsNoTracking() .SortBy(productReviewDTO) .ThenByDescending(x => x.Date) .Where(x => x.ProductId == productId) .Select(productReviewDTO) .Skip((page - 1) * productReviewDTO.GetReviewsPerPage()) .Take(productReviewDTO.GetReviewsPerPage()) .ToListAsync()); }
public async Task <ActionResult> GetProductDetail(string id, string sortBy) { ProductReviewDTO productReviewDTO = new ProductReviewDTO(); // Get the product based on the id ProductDetailDTO product = await unitOfWork.Products.Get(x => x.Id == id, new ProductDetailDTO()); // If the product is found in the database, return the product with other product details if (product != null) { var response = new { product, media = await unitOfWork.Media.GetCollection(x => x.ProductId == product.Id, new ProductMediaDTO()), content = await unitOfWork.ProductContent.GetCollection(x => x.ProductId == product.Id, x => new { Type = new { x.ProductContentType.Name, x.ProductContentType.Image }, x.Title, PriceIndices = x.PriceIndices.Select(y => y.Index).ToList() }), pricePoints = await unitOfWork.PricePoints.GetCollection(x => x.ProductId == product.Id, x => string.Format(x.Description, x.Price)), reviews = await unitOfWork.ProductReviews.GetReviews(product.Id, sortBy, 1), sortOptions = productReviewDTO.GetSortOptions(), reviewsPerPage = productReviewDTO.GetReviewsPerPage() }; return(Ok(response)); } return(NotFound()); }
public async Task <ActionResult> GetReviewsDetail(string productId, string sortBy, int page = 1) { ProductReviewDTO productReviewDTO = new ProductReviewDTO(); // Get the product that is in review var product = await unitOfWork.Products.Get(x => x.Id == productId, x => new { id = x.Id, title = x.Title, urlTitle = x.UrlTitle, rating = x.Rating, totalReviews = x.TotalReviews, minPrice = x.MinPrice, maxPrice = x.MaxPrice, image = x.Image, shareImage = x.ShareImage, oneStar = x.OneStar, twoStars = x.TwoStars, threeStars = x.ThreeStars, fourStars = x.FourStars, fiveStars = x.FiveStars }); // If product is not null if (product != null) { return(Ok(new { product, positiveReview = await unitOfWork.ProductReviews.GetPositiveReview(product.id), negativeReview = await unitOfWork.ProductReviews.GetNegativeReview(product.id), reviews = await unitOfWork.ProductReviews.GetReviews(product.id, sortBy, page), sortOptions = productReviewDTO.GetSortOptions(), reviewsPerPage = productReviewDTO.GetReviewsPerPage() })); } return(BadRequest()); }