コード例 #1
0
        public async Task <IActionResult> UpdateBusiness(int id, ReviewView reviewView)
        {
            // if (id != businessView.BusinessId)
            // {
            // return BadRequest();
            // }

            var review = await _context.Reviews.FindAsync(id);

            if (review == null)
            {
                return(NotFound());
            }

            review.ReviewId = reviewView.ReviewId;
            review.Comment  = reviewView.Comment;
            review.Rating   = reviewView.Rating;



            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(NotFound());
            }

            return(Ok());
        }
コード例 #2
0
        public Either <string, ReviewView> Update(ReviewView reviewView)
        {
            try
            {
                var review = _dbContext.Reviews.Find(reviewView.Id);

                if (review == null)
                {
                    return("review not found");
                }

                review.Title      = reviewView.Title;
                review.Content    = reviewView.Content;
                review.ReviewDate = DateTime.Now;
                review.Stars      = reviewView.Stars;

                _dbContext.Reviews.Update(review);
                _dbContext.SaveChanges();

                return(ReviewMapper.ToView(review));
            }
            catch (Exception ex)
            {
                _logger.LogError("can't update review - ", ex);
                return("can't update review");
            }
        }
コード例 #3
0
        public void CorrectlyReturnTheDataOfView_WhenCalled()
        {
            const string username      = "******";
            const int    numberOfVotes = 92;
            const int    score         = 12;
            const int    reviewID      = 8;
            const double rating        = 2.3;
            const string text          = "the movie is the best lolz";
            //Arrange
            var sut = new ReviewView
            {
                ByUser        = username,
                NumberOfVotes = numberOfVotes,
                Rating        = rating,
                ReviewID      = reviewID,
                Score         = score,
                Text          = text
            };
            //Act
            var result = sut.ToString();

            //Assert
            Assert.IsTrue(result.Contains(username, StringComparison.CurrentCultureIgnoreCase));
            Assert.IsTrue(result.Contains(text, StringComparison.CurrentCultureIgnoreCase));
            Assert.IsTrue(result.Contains(numberOfVotes.ToString(), StringComparison.CurrentCultureIgnoreCase));
            Assert.IsTrue(result.Contains(score.ToString(), StringComparison.CurrentCultureIgnoreCase));
            Assert.IsTrue(result.Contains(reviewID.ToString(), StringComparison.CurrentCultureIgnoreCase));
            Assert.IsTrue(result.Contains(rating.ToString(), StringComparison.CurrentCultureIgnoreCase));
        }
コード例 #4
0
        private void ReviewFiles()
        {
            ReviewWindowViewModel viewModel = new ReviewWindowViewModel(Model, Results, ArtFile);
            ReviewView            view      = new ReviewView();

            view.DataContext = viewModel;
            view.ShowDialog();
        }
コード例 #5
0
 public IActionResult UpdateUsersBookReview(int userId, int bookId, [FromBody] ReviewView updatedReview)
 {
     try {
         _reviewsService.UpdateBooksUserReview(bookId, userId, updatedReview);
         return(NoContent());
     } catch (NotFoundException e) {
         return(NotFound(e.Message));
     }
 }
コード例 #6
0
        public bool addReview(ReviewView review)
        {
            Review reviewModel = Mapper.Map <ReviewView, Review>(review);

            reviewModel.reviewScore = review.ratingScore;
            reviewModel.addedTime   = DateTime.Today;
            reviewRepo.Add(reviewModel);
            return(true);
        }
コード例 #7
0
 public static Review ToModel(ReviewView reviewView)
 {
     return(new Review()
     {
         Id = reviewView.Id,
         ReviewDate = reviewView.ReviewDate,
         Content = reviewView.Content,
         ProductId = reviewView.ProductId,
         Title = reviewView.Title,
         Stars = reviewView.Stars
     });
 }
コード例 #8
0
        public async Task ViewReview(int reviewId, string userId)
        {
            var reviewView = new ReviewView
            {
                ReviewId = reviewId,
                UserId   = userId
            };

            await this.db.ReviewView.AddAsync(reviewView);

            await this.db.SaveChangesAsync();
        }
コード例 #9
0
        public HttpResponseMessage GetOneReview(HttpRequestMessage request, ReviewViewID reviewID)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                Review review = service.getOneReview(reviewID.ID, reviewID.userID);
                if (review != null)
                {
                    ReviewView obj = new ReviewView();
                    obj.reviewText = review.reviewText;
                    obj.userID = review.userID;
                    obj.bookID = review.bookID;
                    obj.ID = review.ID;
                    obj.ratingScore = 0;
                    obj.addedTime = review.addedTime;

                    UserDataNoPass usr = servUs.getUserAfterID(obj.userID);
                    if (usr != null)
                    {
                        obj.user = usr;
                    }
                    else
                    {
                        obj.user = new UserDataNoPass();
                    }

                    RatingView rati = servRat.getRating(obj.bookID, obj.userID);
                    if (rati != null)
                    {
                        obj.ratingScore = rati.ratingScore;
                        obj.rating = rati;
                    }
                    else
                    {
                        obj.ratingScore = 0;
                    }
                    response = request.CreateResponse(HttpStatusCode.OK, obj, JsonMediaTypeFormatter.DefaultMediaType);
                }

                else
                {
                    ReviewView rev = new ReviewView();
                    response = request.CreateResponse(HttpStatusCode.OK, rev, JsonMediaTypeFormatter.DefaultMediaType);
                }
                unitOfWork.Commit();

                return response;
            }));
        }
コード例 #10
0
 public IActionResult AddReviewToBook(int userId, int bookId, [FromBody] ReviewView review)
 {
     if (!ModelState.IsValid)
     {
         return(StatusCode(412, "modelstate is not valid"));
     }
     try {
         var newReview = _reviewsService.AddReviewToBook(userId, bookId, review);
         //FIXME: Create a createdAt path and return that instead.
         return(StatusCode(201));
     } catch (NotFoundException e) {
         return(NotFound(e.Message));
     }
 }
コード例 #11
0
        public async Task <ActionResult <ReviewView> > CreateReview(ReviewView reviewView)
        {
            var review = new Review
            {
                ReviewId = reviewView.ReviewId,
                Comment  = reviewView.Comment,
                Rating   = reviewView.Rating
            };

            _context.Reviews.Add(review);
            await _context.SaveChangesAsync();

            return(Ok(review));
        }
コード例 #12
0
        public Either <string, ReviewView> Add(ReviewView reviewView)
        {
            try
            {
                var review = ReviewMapper.ToModel(reviewView);

                _dbContext.Reviews.Add(review);
                _dbContext.SaveChanges();

                _textAnalysisService.SaveContentAnalysis(review.Content, review.Id);

                return(ReviewMapper.ToView(review));
            }
            catch (Exception ex)
            {
                _logger.LogError("can't add review - ", ex);
                return("can't add review");
            }
        }
コード例 #13
0
        public void NotMapFromView()
        {
            var reviewView = new ReviewView
            {
                Id         = Guid.NewGuid().ToString(),
                AuthorName = "Rodolpho C Alves",
                ReviewText = "Lorem ipsum dolor sit amet",
                Score      = 6d,
                Subject    = new GameList
                {
                    Id   = Guid.NewGuid().ToString(),
                    Name = "Lorem of Ipsum"
                }
            };

            Action act = new Action(() => _mapper.Map <Review>(reviewView));

            act.Should().Throw <Exception>(because: "no such mapping should exist");
        }
コード例 #14
0
        public HttpResponseMessage AddReview(HttpRequestMessage request, ReviewView review)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                RatingView rating = new RatingView();
                rating.bookID = review.bookID;
                rating.userID = review.userID;
                rating.ratingScore = review.ratingScore;

                bool getReview = service.getOneReviewCheck(review.bookID, review.userID);
                if (getReview)
                {
                    response = request.CreateResponse(HttpStatusCode.OK, false);
                    unitOfWork.Commit();
                    return response;
                }

                bool getRating = servRat.checkIfRatingExists(review.bookID, review.userID);
                if (getRating)
                {
                    response = request.CreateResponse(HttpStatusCode.OK, false);
                    unitOfWork.Commit();
                    return response;
                }

                bool wasAddedReview = service.addReview(review);
                bool wasAddedRating = servRat.addRating(rating);

                if (wasAddedReview && wasAddedRating)
                {
                    response = request.CreateResponse(HttpStatusCode.OK, true);
                }
                else
                {
                    response = request.CreateResponse(HttpStatusCode.InternalServerError);
                }
                unitOfWork.Commit();

                return response;
            }));
        }
コード例 #15
0
        public IActionResult AddReview(ReviewView model)
        {
            TryValidateModel(model);
            if (ModelState.IsValid)
            {
                Review newReview = new Review
                {
                    reviewer       = model.reviewer,
                    restaurantName = model.restaurantName,
                    review         = model.review,
                    rating         = model.rating,
                    created_at     = DateTime.Now
                };

                _context.Add(newReview);
                _context.SaveChanges();
                return(RedirectToAction("Reviews"));
            }
            return(View("Index", model));
        }
コード例 #16
0
        /// <summary>
        /// Adds a review to a book from a specific user.
        /// The User does not have to have a loan history for the book
        /// since he might have read it from somewhere else.
        /// </summary>
        /// <param name="userId">Id of the user giving the review</param>
        /// <param name="bookId">Id of the book being reviewed</param>
        /// <param name="review">ReviewText and Stars</param>
        /// <returns>ReviewDTO for the book review</returns>
        public ReviewDTO AddReviewToBook(int userId, int bookId, ReviewView review)
        {
            // Checking if user exists.
            var user = (from u in _db.Users where u.Id == userId && u.Deleted == false select u).SingleOrDefault();

            if (user == null)
            {
                throw new NotFoundException("User with id " + userId + " not found.");
            }

            // Check if book exists
            var book = (from b in _db.Books where b.Id == bookId &&
                        b.Deleted == false select b).SingleOrDefault();

            if (book == null)
            {
                throw new NotFoundException("Book with id " + bookId + " not found.");
            }

            _db.Reviews.Add(new Review {
                UserId     = userId,
                BookId     = bookId,
                ReviewText = review.ReviewText,
                Stars      = review.Stars.Value
            });
            try {
                _db.SaveChanges();
                return(new ReviewDTO {
                    UserId = userId,
                    BookTitle = book.Title,
                    BookId = bookId,
                    ReviewText = review.ReviewText,
                    Stars = review.Stars.Value
                });
            } catch (Exception e) {
                Console.WriteLine(e);
                return(null);
            }
        }
コード例 #17
0
        public void UpdateBooksUserReview(int bookId, int userId, ReviewView updatedReview)
        {
            var bookEntity = _db.Books.SingleOrDefault(b => (b.Id == bookId && b.Deleted == false));

            if (bookEntity == null)
            {
                throw new NotFoundException("Book with id " + bookId + " not found.");
            }
            var userEntity = _db.Users.SingleOrDefault(u => (u.Id == userId && u.Deleted == false));

            if (userEntity == null)
            {
                throw new NotFoundException("User with id " + userId + " not found.");
            }
            var reviewEntity = _db.Reviews.SingleOrDefault(r => (r.BookId == bookId && r.UserId == userId));

            if (reviewEntity == null)
            {
                throw new NotFoundException("Review for book with id " + bookId + " user with id " + userId + " not found.");
            }

            var oldReview = (from r in _db.Reviews where r.BookId == bookId && r.UserId == userId select r).SingleOrDefault();

            if (oldReview == null)
            {
                throw new NotFoundException("Review for book with id " + bookId + " user with id " + userId + " not found.");
            }

            oldReview.ReviewText = updatedReview.ReviewText;
            oldReview.Stars      = updatedReview.Stars.Value;

            try {
                _db.SaveChanges();
            } catch (Exception e) {
                Console.WriteLine(e);
            }
        }
コード例 #18
0
 public ReviewDTO AddReviewToBook(int userId, int bookId, ReviewView review)
 {
     return(_repo.AddReviewToBook(userId, bookId, review));
 }
コード例 #19
0
 public void UpdateBooksUserReview(int bookId, int userId, ReviewView updatedReview)
 {
     _repo.UpdateBooksUserReview(bookId, userId, updatedReview);
 }
コード例 #20
0
 public void RemoveReview(ReviewView Review)
 {
     RemoveReviewByID(Review.ID);
 }
コード例 #21
0
 public void EditReview(ReviewView Review)
 {
     throw new NotImplementedException();
 }
コード例 #22
0
        public HttpResponseMessage GetReviewPagined(HttpRequestMessage request, [FromUri] PagingParameterModel pagingparametermodel, [FromUri] string filterAfter, [FromUri] string filterField, [FromUri] string sortMethod, [FromUri] string IDURL, [FromUri] string isbn)
        {
            return(CreateHttpResponse(request, () =>
            {
                int CurrentPage = pagingparametermodel.pageNumber;
                int PageSize = pagingparametermodel.pageSize;

                BookViewWithISBN bookID = new BookViewWithISBN();

                if (IDURL.Equals("null"))
                {
                    bookID.ID = 0;
                }
                else
                {
                    bookID.ID = Int32.Parse(IDURL);
                }

                if (isbn.Equals("null"))
                {
                    bookID.isbn = "0";
                }
                else
                {
                    bookID.isbn = isbn;
                }

                IEnumerable <Review> reviews = service.getReviewFilteredPaginated(bookID, CurrentPage, PageSize, filterAfter, filterField, sortMethod);

                List <ReviewView> reviewList = new List <ReviewView>();

                foreach (Review b in reviews)
                {
                    ReviewView obj = new ReviewView();
                    obj.reviewText = b.reviewText;
                    obj.userID = b.userID;
                    obj.bookID = b.bookID;
                    obj.ID = b.ID;
                    obj.ratingScore = 0;
                    obj.addedTime = b.addedTime;

                    UserDataNoPass usr = servUs.getUserAfterID(obj.userID);
                    if (usr != null)
                    {
                        obj.user = usr;
                    }
                    else
                    {
                        obj.user = new UserDataNoPass();
                    }

                    RatingView rati = servRat.getRating(obj.bookID, obj.userID);
                    if (rati != null)
                    {
                        obj.ratingScore = rati.ratingScore;
                    }
                    else
                    {
                        obj.ratingScore = 0;
                    }

                    reviewList.Add(obj);
                }

                HttpResponseMessage response = null;

                response = request.CreateResponse(HttpStatusCode.OK, reviewList, JsonMediaTypeFormatter.DefaultMediaType);

                return response;
            }));
        }
コード例 #23
0
 protected void ShowEditModal(ReviewView reviewView)
 {
     ShowModal();
     ModifyModal = true;
     ReviewModel = reviewView;
 }
コード例 #24
0
 protected void ShowAddModal()
 {
     ShowModal();
     ReviewModel = new ReviewView();
 }