Exemplo n.º 1
0
        public async Task AddReview(ReviewAC review)
        {
            /// review.Review.RestaurantId = restaurantId;
            await _context.Review.AddAsync(review.Review);

            await AverageRatingOfResaturant(review.Review.RestaurantId);
        }
Exemplo n.º 2
0
        //private bool LikeExists(int reviewId, int userId)
        //{
        //    var = _context
        //         .ReviewLike
        //         .Where(l => l.UserId==userId)

        //}

        public async Task AddRating(int restaurantId, ReviewAC reviewRating)
        {
            reviewRating.Review.RestaurantId = restaurantId;
            await _context.Review.AddAsync(reviewRating.Review);

            //AverageRatingOfResaturant(restaurantId);
        }
Exemplo n.º 3
0
        public async Task AddLike(int reviewId, ReviewAC reviewLike)
        {
            reviewLike.Review = await _context.Review.FindAsync(reviewId);

            reviewLike.ReviewLike.ReviewId = reviewId;
            await _context.ReviewLike.AddAsync(reviewLike.ReviewLike);

            reviewLike.Review.Likes = reviewLike.Review.Likes + 1;
        }
Exemplo n.º 4
0
        public async Task <ReviewAC> GetReview(int reviewId)
        {
            var review = await _context
                         .Review
                         .Include(r => r.Restaurant)
                         .ThenInclude(c => c.City)
                         .Include(r => r.User)
                         .Where(r => r.Id == reviewId)
                         .SingleOrDefaultAsync();

            var reviewComments = await _context
                                 .ReviewComment
                                 .Include(r => r.User)
                                 .Where(rc => rc.ReviewId == review.Id)
                                 .ToListAsync();

            var reviewLikes = _context
                              .ReviewLike
                              .Where(rl => rl.ReviewId == review.Id)
                              .Count();

            List <ReviewCommentAC> ListOfComments = new List <ReviewCommentAC>();

            foreach (var reviewCommnet in reviewComments)
            {
                ReviewCommentAC reviewCommentAC = new ReviewCommentAC();
                reviewCommentAC.ReviewCommentId   = reviewCommnet.Id;
                reviewCommentAC.ReviewCommentText = reviewCommnet.CommentText;
                reviewCommentAC.UserId            = reviewCommnet.UserId;
                reviewCommentAC.UserName          = reviewCommnet.User.UserName;

                ListOfComments.Add(reviewCommentAC);
            }

            ReviewAC reviewAC = new ReviewAC();
            UserAC   user     = new UserAC();

            user.Id      = review.User.Id;
            user.Name    = review.User.UserName;
            user.Phone   = review.User.PhoneNumber;
            user.Email   = review.User.Email;
            user.Address = review.User.Address;

            reviewAC.ReviewId       = review.Id;
            reviewAC.Rating         = review.Rating;
            reviewAC.ReviewText     = review.ReviewText;
            reviewAC.userAC         = user;
            reviewAC.ReviewCommnets = ListOfComments;
            reviewAC.TotalLike      = reviewLikes;
            reviewAC.RestaurantId   = review.RestaurantId;

            return(reviewAC);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> AddReviw([FromBody] Review review)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            ReviewAC reviewAc = new ReviewAC();

            reviewAc.Review = review;
            await _unitOfWork.Review.AddReview(reviewAc);

            await _unitOfWork.Save();

            return(Ok(review));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> AddRating([FromRoute] int restaurantId,
                                                    [FromBody] Review reviewRating)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            ReviewAC reviewAc = new ReviewAC();

            reviewAc.Review = reviewRating;
            await _unitOfWork.Review.AddRating(restaurantId, reviewAc);

            await _unitOfWork.Save();

            return(Ok(reviewRating));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> AddComment([FromRoute] int reviewId
                                                     , [FromBody] ReviewComment reviewComment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ReviewAC reviewAC = new ReviewAC();

            reviewAC.Comment = reviewComment;
            await _unitOfWork.Review.AddReviewComment(reviewId, reviewAC);

            await _unitOfWork.Save();

            return(Ok(reviewComment));
        }
Exemplo n.º 8
0
        public async Task <IEnumerable <ReviewAC> > GetAllReviewOfRestaurant(int restaurantId)
        {
            var reviews = await _context
                          .Review
                          .Include(r => r.Restaurant)
                          .ThenInclude(c => c.City)
                          .Include(r => r.User)
                          .Where(r => r.RestaurantId == restaurantId && r.ReviewText != null)
                          .ToListAsync();

            foreach (var review in reviews)
            {
                var reviewComments = await _context
                                     .ReviewComment
                                     .Where(rc => rc.ReviewId == review.Id)
                                     .ToListAsync();

                var totalReviewComments = _context
                                          .ReviewComment
                                          .Where(r => r.ReviewId == review.Id)
                                          .Count();
                var reviewLikes = _context
                                  .ReviewLike
                                  .Where(rl => rl.ReviewId == review.Id)
                                  .Count();

                List <ReviewCommentAC> ListOfComment = new List <ReviewCommentAC>();

                foreach (var reviewCommnet in reviewComments)
                {
                    ReviewCommentAC reviewCommentAC = new ReviewCommentAC();
                    reviewCommentAC.ReviewCommentId   = reviewCommnet.Id;
                    reviewCommentAC.ReviewCommentText = reviewCommnet.CommentText;
                    reviewCommentAC.UserId            = reviewCommnet.UserId;
                    reviewCommentAC.UserName          = reviewCommnet.User.UserName;

                    ListOfComment.Add(reviewCommentAC);
                }

                ReviewAC reviewAC = new ReviewAC();
                UserAC   user     = new UserAC();
                user.Id      = review.User.Id;
                user.Name    = review.User.UserName;
                user.Phone   = review.User.PhoneNumber;
                user.Email   = review.User.Email;
                user.Address = review.User.Address;

                reviewAC.ReviewId       = review.Id;
                reviewAC.Rating         = review.Rating;
                reviewAC.ReviewText     = review.ReviewText;
                reviewAC.userAC         = user;
                reviewAC.ReviewCommnets = ListOfComment;
                reviewAC.TotalLike      = reviewLikes;
                reviewAC.TotalComment   = totalReviewComments;
                reviewAC.RestaurantId   = restaurantId;

                AllReviews.Add(reviewAC);
            }

            return(AllReviews);
        }
Exemplo n.º 9
0
 public async Task AddReviewComment(int reviewId, ReviewAC reviewComment)
 {
     reviewComment.Comment.ReviewId = reviewId;
     await _context.ReviewComment.AddAsync(reviewComment.Comment);
 }