public IActionResult AccountReviews(ReviewSearchModel reviewSearchModel)
        {
            var ratings = reviewSearchModel.Rating.HasValue
                ? new List <int>()
            {
                reviewSearchModel.Rating.Value
            }
                : new List <int>()
            {
                1, 2, 3, 4, 5
            };

            var reviews = _reviewService.Get(out var totalMatches,
                                             x => x.UserId == CurrentUser.Id && ratings.Contains(x.Rating) && x.Published, page: reviewSearchModel.Page, count: reviewSearchModel.Count).ToList();

            var reviewModels = reviews.Select(_reviewModelFactory.Create).ToList();

            var reviewsSummaryModel = new AllReviewsSummaryModel()
            {
                TotalReviews = totalMatches
            };

            //find best and worst review
            if (reviews.Count > 1 && reviews.Count < reviewSearchModel.Count)
            {
                reviewsSummaryModel.FiveStarCount  = reviews.Count(x => x.Rating == 5);
                reviewsSummaryModel.FourStarCount  = reviews.Count(x => x.Rating == 4);
                reviewsSummaryModel.ThreeStarCount = reviews.Count(x => x.Rating == 3);
                reviewsSummaryModel.TwoStarCount   = reviews.Count(x => x.Rating == 2);
                reviewsSummaryModel.OneStarCount   = reviews.Count(x => x.Rating == 1);
            }
            else
            {
                if (reviews.Count > 1)
                {
                    reviewsSummaryModel.FiveStarCount  = _reviewService.Count(x => x.Rating == 5 && x.UserId == CurrentUser.Id && x.Published);
                    reviewsSummaryModel.FourStarCount  = _reviewService.Count(x => x.Rating == 4 && x.UserId == CurrentUser.Id && x.Published);
                    reviewsSummaryModel.ThreeStarCount = _reviewService.Count(x => x.Rating == 3 && x.UserId == CurrentUser.Id && x.Published);
                    reviewsSummaryModel.TwoStarCount   = _reviewService.Count(x => x.Rating == 2 && x.UserId == CurrentUser.Id && x.Published);
                    reviewsSummaryModel.OneStarCount   = _reviewService.Count(x => x.Rating == 1 && x.UserId == CurrentUser.Id && x.Published);
                }
            }
            //set breadcrumb nodes
            SetBreadcrumbToRoute("Account", RouteNames.AccountProfile);
            SetBreadcrumbToRoute("Review Center", RouteNames.AccountReviews);

            return(R.Success
                   .With("reviews", reviewModels)
                   .WithGridResponse(totalMatches, reviewSearchModel.Page, reviewSearchModel.Count)
                   .With("summary", reviewsSummaryModel).Result);
        }
        public IActionResult ReviewsList(ReviewSearchModel reviewSearchModel)
        {
            reviewSearchModel = reviewSearchModel ?? new ReviewSearchModel()
            {
                Current  = 1,
                RowCount = 15
            };
            var reviews = _reviewService.GetReviews(out var totalResults, reviewSearchModel.SearchPhrase, reviewSearchModel.ProductSearch,
                                                    reviewSearchModel.Published, reviewSearchModel.ProductId, reviewSearchModel.Current,
                                                    reviewSearchModel.RowCount);

            var reviewModels = reviews.Select(_reviewModelFactory.Create).ToList();

            return(R.Success.With("reviews", reviewModels)
                   .WithGridResponse(totalResults, reviewSearchModel.Current, reviewModels.Count)
                   .Result);
        }
 public IActionResult ReviewsList(ReviewSearchModel reviewSearchModel)
 {
     return(ReviewsListApi(reviewSearchModel));
 }
        public IActionResult ReviewsListApi(ReviewSearchModel reviewSearchModel)
        {
            //check if the product is valid
            var product = _productService.Get(reviewSearchModel.ProductId);

            if (!product.IsPublic(CurrentStore.Id))
            {
                return(NotFound());
            }

            IList <Review> reviews;
            var            ratings = reviewSearchModel.Rating.HasValue
                ? new List <int>()
            {
                reviewSearchModel.Rating.Value
            }
                : new List <int>()
            {
                1, 2, 3, 4, 5
            };
            int totalMatches;

            if (reviewSearchModel.VerifiedPurchase)
            {
                reviews = _reviewService.Get(out totalMatches,
                                             x => x.ProductId == reviewSearchModel.ProductId && ratings.Contains(x.Rating) &&
                                             x.VerifiedPurchase == true && x.Published, page: reviewSearchModel.Page,
                                             count: reviewSearchModel.Count).ToList();
            }
            else
            {
                reviews = _reviewService.Get(out totalMatches,
                                             x => x.ProductId == reviewSearchModel.ProductId && ratings.Contains(x.Rating) && x.Published,
                                             page: reviewSearchModel.Page,
                                             count: reviewSearchModel.Count).ToList();
            }

            var reviewModels = reviews.Select(_reviewModelFactory.Create).ToList();

            var reviewsSummaryModel = new AllReviewsSummaryModel()
            {
                TotalReviews = totalMatches
            };
            //find best and worst review
            ReviewModel bestReview = null, worstReview = null;

            if (reviews.Count > 1 && reviews.Count < reviewSearchModel.Count)
            {
                bestReview  = reviewModels.OrderByDescending(x => x.Rating).First();
                worstReview = reviewModels.OrderBy(x => x.Rating).First();
                reviewsSummaryModel.FiveStarCount  = reviews.Count(x => x.Rating == 5);
                reviewsSummaryModel.FourStarCount  = reviews.Count(x => x.Rating == 4);
                reviewsSummaryModel.ThreeStarCount = reviews.Count(x => x.Rating == 3);
                reviewsSummaryModel.TwoStarCount   = reviews.Count(x => x.Rating == 2);
                reviewsSummaryModel.OneStarCount   = reviews.Count(x => x.Rating == 1);
            }
            else
            {
                if (reviews.Count > 1)
                {
                    bestReview  = _reviewModelFactory.Create(_reviewService.GetBestReview(product.Id));
                    worstReview = _reviewModelFactory.Create(_reviewService.GetWorstReview(product.Id));
                    reviewsSummaryModel.FiveStarCount  = _reviewService.Count(x => x.Rating == 5 && x.ProductId == product.Id && x.Published);
                    reviewsSummaryModel.FourStarCount  = _reviewService.Count(x => x.Rating == 4 && x.ProductId == product.Id && x.Published);
                    reviewsSummaryModel.ThreeStarCount = _reviewService.Count(x => x.Rating == 3 && x.ProductId == product.Id && x.Published);
                    reviewsSummaryModel.TwoStarCount   = _reviewService.Count(x => x.Rating == 2 && x.ProductId == product.Id && x.Published);
                    reviewsSummaryModel.OneStarCount   = _reviewService.Count(x => x.Rating == 1 && x.ProductId == product.Id && x.Published);
                }
            }

            var productModel = _productModelFactory.Create(product);

            //breadcrumbs
            //set breadcrumb nodes
            SetBreadcrumbToRoute(product.Name, RouteNames.SingleProduct,
                                 new { seName = product.SeoMeta.Slug, id = product.Id }, localize: false);
            SetBreadcrumbToUrl("Reviews", "");

            return(R.Success
                   .With("product", productModel)
                   .With("reviews", reviewModels)
                   .With("bestReview", bestReview)
                   .With("worstReview", worstReview)
                   .WithGridResponse(totalMatches, reviewSearchModel.Page, reviewSearchModel.Count)
                   .With("summary", reviewsSummaryModel).Result);
        }
Example #5
0
        public static IList <OapPreviousProtocolsFlatModel> ToPreviousProtocolsModel(this IEnumerable <RigOapChecklist> rigChecklistList, ReviewSearchModel model, OapAuditClient auditClient, OapChecklistFindingClient checklistFindingClient)
        {
            var layoutList = new List <OapPreviousProtocolsFlatModel>();

            foreach (var item in rigChecklistList)
            {
                var protocol = auditClient.GetCompleteProtocolAsync(item.Id).Result?.Result?.Data;

                if (protocol == null)
                {
                    continue;
                }


                var count    = 0;
                var question = protocol.Questions.ToList();

                question.ForEach((q) =>
                {
                    var v = q.Answers.Where(a => a.RigOapChecklistQuestionId == q.Id).FirstOrDefault().Value;

                    if (v == "N" || v == "NA")
                    {
                        count++;
                    }
                });

                var previousProtocols = new OapPreviousProtocolsFlatModel(protocol.Id, protocol.RigChecklistUniqueId, protocol.OapChecklist.OapType.Name, protocol.Title, protocol.Assessors?.Where(a => a.IsLead == true)?.FirstOrDefault()?.User?.Name, protocol.ChecklistDateTime.ToString("dd-MMM-yyyy"), count.ToString(), protocol.Status, "Review");

                if (!layoutList.Any(l => l.ChecklistId == previousProtocols.ChecklistId))
                {
                    layoutList.Add(previousProtocols);
                }
            }

            return(layoutList);
        }