Exemplo n.º 1
0
        public IHttpActionResult GetAllProductReviewsOrderByDesc(string order)
        {
            List <ReviewProductShopView> listReviewProductShopView = new List <ReviewProductShopView>();

            var allReviews = reviewRepository.GetAll().ToList();

            if (order == "desc")
            {
                allReviews = reviewRepository.GetProductReviewsOrderByDesc().ToList();
            }
            foreach (var item in allReviews)
            {
                ReviewProductShopView reviewProductShopView = new ReviewProductShopView();
                reviewProductShopView.ProductId = item.productId;
                reviewProductShopView.UserId    = item.userId;
                reviewProductShopView.Review    = item.review;
                reviewProductShopView.Rating    = (int)item.rating;

                var productDetails = productRepository.Get(item.productId);
                reviewProductShopView.ProductName = productDetails.name;

                var shopDetails = shopRepository.Get(productDetails.shopId);
                reviewProductShopView.ShopName = shopDetails.name;

                listReviewProductShopView.Add(reviewProductShopView);
            }
            return(Ok(listReviewProductShopView));
        }
Exemplo n.º 2
0
        public IHttpActionResult SerachProduct(string searchKey)
        {
            var allProducts = productRepository.SerachProduct(searchKey);
            List <ReviewProductShopView> allcategoryProductShopWithAverageRatingView = new List <ReviewProductShopView>();

            foreach (var productDetails in allProducts)
            {
                ReviewProductShopView categoryProductShopView = new ReviewProductShopView();
                categoryProductShopView.ProductId        = productDetails.productId;
                categoryProductShopView.ProductName      = productDetails.name;
                categoryProductShopView.UnitPrice        = (double)productDetails.unitPrice;
                categoryProductShopView.Quantity         = (int)productDetails.quantity;
                categoryProductShopView.ProductStatus    = (int)productDetails.productStatus;
                categoryProductShopView.ProductImage     = productDetails.image;
                categoryProductShopView.ProductAddedDate = productDetails.date;

                var categoryDetails = categoryRepository.Get((int)productDetails.categoryId);
                categoryProductShopView.CategoryName = categoryDetails.name;

                var shopDetails = shopRepository.Get((int)productDetails.shopId);
                categoryProductShopView.ShopName = shopDetails.name;

                //avg rating
                int totalRating   = 0;
                int count         = 0;
                var reviewDetails = reviewRepository.GetProductReviews(productDetails.productId);
                foreach (var item in reviewDetails)
                {
                    count++;
                    totalRating += Convert.ToInt32(item.rating);
                }
                double avgRating;
                if (reviewDetails.Any())
                {
                    avgRating = (totalRating / count);
                }
                else
                {
                    avgRating = 0;
                }

                categoryProductShopView.Rating = Convert.ToInt32(Math.Ceiling(avgRating));
                //avg rating

                allcategoryProductShopWithAverageRatingView.Add(categoryProductShopView);
            }

            return(Ok(allcategoryProductShopWithAverageRatingView));
        }
Exemplo n.º 3
0
        public IHttpActionResult GetProductDetailsWithCategoryShopName(int id)
        {
            var productDetails = productRepository.Get(id);
            ReviewProductShopView categoryProductShopView = new ReviewProductShopView();

            categoryProductShopView.ProductId        = id;
            categoryProductShopView.ProductName      = productDetails.name;
            categoryProductShopView.UnitPrice        = (double)productDetails.unitPrice;
            categoryProductShopView.Quantity         = (int)productDetails.quantity;
            categoryProductShopView.ProductStatus    = (int)productDetails.productStatus;
            categoryProductShopView.ProductImage     = productDetails.image;
            categoryProductShopView.ProductAddedDate = productDetails.date;

            var categoryDetails = categoryRepository.Get((int)productDetails.categoryId);

            categoryProductShopView.CategoryName = categoryDetails.name;

            var shopDetails = shopRepository.Get((int)productDetails.shopId);

            categoryProductShopView.ShopName = shopDetails.name;

            return(Ok(categoryProductShopView));
        }