コード例 #1
0
        public IActionResult All(int id, int page = 1)
        {
            if (this.productsService.GetProductById(id) == null)
            {
                return(this.BadRequest());
            }

            this.ViewBag.ProductName = this.productsService.GetProductById(id).Name;
            var viewModel = new AllReviewsViewModel
            {
                ProductId = id,
                Reviews   = this.reviewsService.GetAllReviewsByProductId(id, ItemsPerPage, (page - 1) * ItemsPerPage),
            };

            var count = this.reviewsService.GetAllReviewsCountByProductId(id);

            viewModel.PagesCount = (int)Math.Ceiling((double)count / ItemsPerPage);
            if (viewModel.PagesCount == 0)
            {
                viewModel.PagesCount = 1;
            }

            viewModel.CurrentPage  = page;
            viewModel.ReviewsCount = count;

            return(this.View(viewModel));
        }
コード例 #2
0
        public async Task <IViewComponentResult> InvokeAsync(string dessertId)
        {
            var model = new AllReviewsViewModel()
            {
                Reviews = await this.reviewsService.GetReviewsCurrentDessertAsync <ReviewViewModel>(dessertId),
            };

            return(this.View(model));
        }
コード例 #3
0
 public ActionResult All(int? page, string sort, bool? desc)
 {
     if (desc == null) desc = false;
     if (String.IsNullOrEmpty(sort)) sort = "ID";
     if (page == null || page.Value <= 0) page = 1;
     var vm = new AllReviewsViewModel
     {
         SortBy = sort,
         SortDesc = desc.Value,
         CurrentPage = page.Value,
         ItemsPerPage = 20,
         DataSource = _reviewRepository.All
     };
     return View("All", vm);
 }
コード例 #4
0
        public JsonResult CreateCommentToReview(AllReviewsViewModel allReviewsViewModel)
        {
            var succeeded = false;

            if (!ModelState.IsValid)
            {
                return(Json(allReviewsViewModel));
            }

            try
            {
                using (var context = new rkDBContext())
                {
                    var userId = (Guid)Session["userId"];

                    if (context.Users.Any(x => x.Id == userId))
                    {
                        var user = context.Users.SingleOrDefault(x => x.Id == userId);

                        var newCommentToReview = new CommentToReview
                        {
                            Id          = Guid.NewGuid(),
                            ReviewId    = allReviewsViewModel.ReviewId,
                            UserId      = (Guid)userId,
                            Comment     = allReviewsViewModel.CommentToAdd,
                            CreatedDate = DateTime.Now
                        };
                        allReviewsViewModel.CreatedBy   = user?.Username;
                        allReviewsViewModel.CreatedDate = DateTime.Now.ToShortDateString();

                        context.CommentToReviews.Add(newCommentToReview);
                        succeeded = true;
                        context.SaveChanges();
                    }
                    else
                    {
                        return(Json(new { succeeded }));
                    }
                }
            }
            catch
            {
                return(Json(new { succeeded }));
            }
            return(Json(new { succeeded, allReviewsViewModel }));
        }
コード例 #5
0
        public IActionResult All(int?id, string reviewType)
        {
            if (id == null)
            {
                this.TempData["Error"] = string.Format(GenericMessages.CouldntDoSomething, "find the album you were looking for");
                return(this.RedirectToAction("Index", "Home"));
            }

            var album = this.albumsService.GetById(id.Value);

            if (album == null)
            {
                this.TempData["Error"] = string.Format(GenericMessages.CouldntDoSomething, "find the album you were looking for");
                return(this.RedirectToAction("Index", "Home"));
            }

            bool reviewTypeIsValid = Enum.TryParse(reviewType, true, out ReviewType parsedReviewType);
            IEnumerable <RatedReviewDto> relevantReviews = new List <RatedReviewDto>();
            string selectedFilter = string.Empty;

            if (reviewTypeIsValid)
            {
                relevantReviews = album.Reviews.Where(r => r.ReviewType == parsedReviewType).ToList().Select(r => r.ToDto(this.User.Identity.Name));
                selectedFilter  = parsedReviewType.ToString();
            }
            else
            {
                relevantReviews = album.Reviews.ToList().Select(r => r.ToDto(this.User.Identity.Name));
                selectedFilter  = "All";
            }

            var mappedReviews = this.mapper.Map <DisplayReviewViewModel[]>(relevantReviews);

            var model = new AllReviewsViewModel()
            {
                AlbumId        = id.Value,
                AlbumName      = album.Name,
                SelectedFilter = selectedFilter,
                Reviews        = mappedReviews
            };

            return(this.View(model));
        }
コード例 #6
0
        public ActionResult Reviews()
        {
            if (Session["userId"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var currentUserId = (Guid)Session["userId"];

            try
            {
                using (var context = new rkDBContext())
                {
                    var allReviews = context.Reviews.ToList();

                    if (allReviews.Count <= 0)
                    {
                        return(View());
                    }
                    var allReviewsViewModelList = new List <AllReviewsViewModel>();
                    foreach (var review in allReviews)
                    {
                        // Fetch userinfo
                        var reviewAuthor = context.Users.FirstOrDefault(x => x.Id == review.CreatorUserId);

                        // Calculate totalRating
                        var userToReviewList = context.UserToReviews.Where(x => x.ReviewId == review.Id).ToList();

                        var calculateReviewRating = CalculateReviewRating(userToReviewList);
                        if (calculateReviewRating == null)
                        {
                            continue;
                        }
                        var totalRating = (decimal)calculateReviewRating;

                        // Fill AllReviewsViewModel with reviewValue to send it to the view
                        if (reviewAuthor == null)
                        {
                            return(View(allReviewsViewModelList));
                        }
                        var reviewToAdd = new AllReviewsViewModel
                        {
                            ReviewId          = review.Id,
                            CreatorUserId     = reviewAuthor.Id,
                            CreatedBy         = reviewAuthor.Username,
                            Title             = review.Title,
                            CreatedDate       = review.CreatedDate.ToShortDateString(),
                            Description       = review.Description,
                            DisLikes          = review.DislikeCount,
                            Likes             = review.LikeCount,
                            TotalRating       = totalRating,
                            UserRating        = review.UserRating,
                            HasProfilePicture = ConfirmProfilePicture(reviewAuthor.Id),
                            Type = review.Type
                        };

                        allReviewsViewModelList.Add(reviewToAdd);
                    }
                    return(View(allReviewsViewModelList));
                }
            }
            catch
            {
                return(RedirectToAction("Error", "Home"));
            }
        }