public async Task CreateReviewsWorksCorrectly() { var ratingList = this.GetRatings(); var reviewList = this.GetReviews(); var ratingMock = this.GetRatingMock(ratingList); var reviewMock = this.GetReviewMock(reviewList); var expectedReviewCount = reviewList.Count + 1; var reviewService = new ReviewsService(reviewMock.Object, ratingMock.Object, this.mediaRepo); var inputModel = new ReviewInputModel() { CurrentUserRating = 0, MediaId = "1", ReviewText = "Da", Title = "Da", }; // Act await reviewService.CreateReview("2", inputModel); // Assert Assert.Equal(expectedReviewCount, reviewMock.Object.All().Count()); Assert.Contains(reviewMock.Object.All(), x => x.Title == inputModel.Title && x.ReviewText == inputModel.ReviewText); }
public async Task CreatingSecondReviewThrowsError() { // Arrange var ratingList = this.GetRatings(); var reviewList = this.GetReviews(); var ratingMock = this.GetRatingMock(ratingList); var reviewMock = this.GetReviewMock(reviewList); var reviewService = new ReviewsService(reviewMock.Object, ratingMock.Object, this.mediaRepo); var inputModel = new ReviewInputModel() { CurrentUserRating = 0, MediaId = "2", ReviewText = "Da", Title = "Da", }; // Act Func <Task> act = () => reviewService.CreateReview("2", inputModel); // Assert Exception ex = await Assert.ThrowsAsync <Exception>(act); Assert.Contains("You have already created a review. Delete it to create new one.", ex.Message); }
public ReviewDto UpdateReview(int?friendId, int?tapeId, ReviewInputModel review) { CheckIfUserOrTapeExist(tapeId, friendId); var reviewEntity = (from r in _dataBaseContext.Reviews where tapeId == r.TapeId && friendId == r.FriendId select r).FirstOrDefault(); if (reviewEntity == null) { throw new ResourceNotFoundException(); } ; // make the changes reviewEntity.Rating = review.Rating; reviewEntity.ReviewInput = review.ReviewInput; // database specific reviewEntity.DateModified = DateTime.Now; _dataBaseContext.SaveChanges(); // return the updated friend var reviewDto = Mapper.Map <ReviewDto>(reviewEntity); updateTapeRating(tapeId); return(reviewDto); }
public async Task CreatingReviewWithoutRatingThrowsError() { // Arrange var ratingList = this.GetRatings(); var reviewList = this.GetReviews(); var ratingMock = this.GetRatingMock(ratingList); var reviewMock = this.GetReviewMock(reviewList); var reviewService = new ReviewsService(reviewMock.Object, ratingMock.Object, this.mediaRepo); var inputModel = new ReviewInputModel() { CurrentUserRating = 0, MediaId = "1", ReviewText = "Da", Title = "Da", }; // Act Func <Task> act = () => reviewService.CreateReview("1", inputModel); // Assert Exception ex = await Assert.ThrowsAsync <Exception>(act); Assert.Contains("You need to rate the media to submit a review.", ex.Message); }
public void ProcessReview(ReviewInputModel review) { if (review.Rating < 1 || 5 < review.Rating) { throw new Exception("Rating is invalid!"); } }
public async Task CreateReview(string userId, ReviewInputModel inputModel) { var ratingDb = await this.ratingRepository.All() .Include(x => x.Review) .Where(x => x.CreatorId == userId && x.MediaId == inputModel.MediaId) .FirstOrDefaultAsync(); if (ratingDb == null) { throw new Exception("You need to rate the media to submit a review."); } if (ratingDb.Review != null) { throw new Exception("You have already created a review. Delete it to create new one."); } var newReview = new Review() { Rating = ratingDb, Title = inputModel.Title, ReviewText = inputModel.ReviewText, MediaId = inputModel.MediaId, CreatorId = userId, }; await this.reviewRepository.AddAsync(newReview); await this.reviewRepository.SaveChangesAsync(); }
public async Task <ActionResult> SubmitReview(ReviewInputModel inputModel) { var userId = userManager.GetUserId(User); if (string.IsNullOrEmpty(userId) || userId == Guid.Empty.ToString()) { return(BadRequest("User could not be found.")); } inputModel.AuthorId = userId; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var reviewId = reviewsService.GetIdByUserAndGame(userId, inputModel.GameId); if (reviewId.HasValue) { inputModel.Id = reviewId.Value; await reviewsService.Update(inputModel); } else { await reviewsService.Create(inputModel); } return(Ok()); }
public void SetBookReview(ReviewInputModel inputFromUser, string user) { var reviewForBook = _reviewRepo.GetReviewByBookId(inputFromUser.bookId); double sumOfAllReview = inputFromUser.Ratings; for (int i = 0; i < reviewForBook.Count; i++) { sumOfAllReview += reviewForBook[i].Ratings; } double newRating = sumOfAllReview / (reviewForBook.Count + 1); ReviewTwo newReview = new ReviewTwo { reviewBookId = inputFromUser.bookId, Ratings = inputFromUser.Ratings, Description = inputFromUser.Description, reviewFromUserName = _bookRepo.getUserName(user) }; _reviewRepo.SetReview(newReview); var updatedBook = _bookRepo.getBookEntityModel(inputFromUser.bookId); updatedBook.rating = newRating; _bookRepo.UpdateABook(updatedBook, inputFromUser.bookId); }
public async Task SetRevewAsync(ReviewInputModel reviewsViewModel) { var review = this.reviewRepository.All().FirstOrDefault(x => x.CigarId == reviewsViewModel.CigarId && x.Name == reviewsViewModel.Name); if (review == null) { review = new Review { CigarId = reviewsViewModel.CigarId, Name = reviewsViewModel.Name, ReviewText = reviewsViewModel.Review, Email = reviewsViewModel.Email, Score = reviewsViewModel.Score, CreatedOn = DateTime.UtcNow, }; } try { await this.reviewRepository.AddAsync(review); await this.reviewRepository.SaveChangesAsync(); } catch (Exception ex) { Console.WriteLine(ex); } }
public IActionResult UpdateUserReviewForTape([FromBody] ReviewInputModel review, int userId, int tapeId) { if (!ModelState.IsValid) { throw new ModelFormatException("Review was not properly formatted"); } _reviewService.UpdateUserReviewForTape(review, userId, tapeId); return(NoContent()); }
public BookListViewModel GetBookByReview(ReviewInputModel review) { var books = GetAllBooks(); var book = (from b in books where b.Id == review.BookId select b).FirstOrDefault(); return(book); }
public IActionResult AddNewReview([FromBody] ReviewInputModel review, int friendId, int tapeId) { if (!ModelState.IsValid) { throw new ModelFormatException(); } return(StatusCode(201, _friendReviewService.AddNewReview((int)friendId, (int)tapeId, review))); }
private Review ToDomainModel(ReviewInputModel inputModel) { return(new Review { Id = inputModel.Id, Reviewer = inputModel.Reviewer, Comments = inputModel.Comments, MovieId = inputModel.MovieId }); }
public IActionResult UpdateReview(int userId, int publicationId, [FromBody] ReviewInputModel body) { if (!ModelState.IsValid) { throw new ModelFormatException("Model not properly formatted"); } var entity = _reviewService.UpdateReview(userId, publicationId, body); return(Ok(entity)); }
public IActionResult CreateUserReview([FromBody] ReviewInputModel review, int userId, int tapeId) { if (!ModelState.IsValid) { throw new ModelFormatException("Review was not properly formatted"); } var newId = _reviewService.CreateUserReview(review, userId, tapeId); return(CreatedAtRoute("GetUserReviewForTape", new { userId, tapeId }, null)); }
public void AddReview(string review, int rating, int productId, int userId) { ReviewInputModel newReview = new ReviewInputModel(); newReview.Review = review; newReview.Rating = rating; newReview.ProductId = productId; newReview.CustomerId = userId; _reviewRepo.AddReviewToProduct(newReview); }
/// <summary> /// Adds review to system by given user for a given tape /// </summary> /// <param name="UserId">Id associated with user within the system</param> /// <param name="TapeId">Id associated with tape within the system</param> /// <param name="Review">The review input model including tape rating</param> public void CreateUserReview(int UserId, int TapeId, ReviewInputModel Review) { ValidateUser(UserId); ValidateTape(TapeId); var reviewExists = _reviewRepository.GetAllReviews().FirstOrDefault(r => r.UserId == UserId && r.TapeId == TapeId); if (reviewExists != null) { throw new InputFormatException($"Review already exists for user with id {UserId} for tape with id {TapeId}. Use PUT to edit reviews"); } _reviewRepository.CreateReview(UserId, TapeId, Review); }
/// <summary> /// Updates review by user for a given tape /// </summary> /// <param name="UserId">Id associated with user within the system</param> /// <param name="TapeId">Id associated with tape within the system</param> /// <param name="Review">The review input model including tape rating</param> public void EditUserReview(int UserId, int TapeId, ReviewInputModel Review) { ValidateUser(UserId); ValidateTape(TapeId); var toUpdate = _reviewRepository.GetAllReviews().FirstOrDefault(r => r.UserId == UserId && r.TapeId == TapeId); if (toUpdate == null) { throw new ResourceNotFoundException($"Cannot edit non-existing review: no review was found by user with id {UserId} for tape with id {TapeId}."); } _reviewRepository.EditReview(UserId, TapeId, Review); }
public async Task <IActionResult> AddReview(ReviewInputModel input) { if (!this.ModelState.IsValid) { return(this.View()); } await this.informationService.AddRewievAsync(input); return(this.RedirectToAction("ThankYou")); }
public async Task <IActionResult> Create(ReviewInputModel inputModel) { if (!ModelState.IsValid) { return(RedirectToAction(nameof(Create), new { orderId = inputModel.OrderId })); } await this.reviewsService.CreateReview(inputModel.OrderId, inputModel.Rating, inputModel.Comment); return(RedirectToAction("MyOrders", "Orders")); }
public IActionResult UpdateUserReviewForTape(int tapeId, int userId, [FromBody] ReviewInputModel Review) { // Check if input model is valid, output all errors if not if (!ModelState.IsValid) { IEnumerable <string> errorList = ModelState.Values.SelectMany(v => v.Errors).Select(x => x.ErrorMessage); throw new InputFormatException("Review input model improperly formatted.", errorList); } _reviewService.EditUserReview(userId, tapeId, Review); return(NoContent()); }
public async Task <ActionResult> AddReview(ReviewInputModel reviewInputModel) { if (!this.ModelState.IsValid) { return(this.View()); } await this.reviewService.SetRevewAsync(reviewInputModel); return(this.Redirect($"/Brands/CigarById/{reviewInputModel.CigarId}")); }
public void AddReview(ReviewInputModel model) { var review = new Review { Comment = model.Comment, Rating = model.Rating, UserId = model.UserId, BookId = model.BookId }; _reviewRepo.AddReview(review, model.BookAverageRating, model.AmountOfRatings); }
public ActionResult ContinueReview(int rcid) { var userid = (int)Membership.GetUser().ProviderUserKey; var reviewComplesion = _db.ReviewCompletions.Find(rcid); if (reviewComplesion == null || reviewComplesion.Status != "Current" || reviewComplesion.PaperQualities.Count(pq => pq.Status == "Current") == 0 || reviewComplesion.UserID != userid) { return(View("Error")); } var reviewIM = new ReviewInputModel { RecordID = reviewComplesion.RecordRecordID, Species = _db.Species.ToList(), SpeciesIDs = reviewComplesion.Record.LinkRecordUserSpecies.Where(l => l.Status == "Current" && l.ReviewCompletionID == reviewComplesion.ReviewCompletionID).Select(l => l.SpecieID).ToArray(), ReviewCompleteID = reviewComplesion.ReviewCompletionID, Files = reviewComplesion.Record.PaperDocuments.Where(pd => pd.DeletePaperDocument == false).Select(pd => new ReadViewModel { TrainingDocumentID = pd.PaperDocumentsID, FileName = pd.FileName, FileType = pd.FileType, FileUrl = pd.FileUrl, }).ToList(), COI = reviewComplesion.Record.ConflicOfIntest, Funding = reviewComplesion.Record.Funding, ReviewItems = reviewComplesion.PaperQualities.Select(pq => new ReviewItemInputModel() { ReviewItemID = pq.PaperQualityID, PublicationID = pq.RecordRecordID, CheckListID = pq.CheckListCheckListID, OptionID = pq.OptionOptionID, Comments = pq.Comments, Section = pq.CheckList.Section, Item = pq.CheckList.Item, ItemNumber = pq.CheckList.ItemNumber, CheckListName = pq.CheckList.CheckListName, CheckListNumber = pq.CheckList.CheckListNumber, Criteria = pq.CheckList.Criteria, Critical = pq.CheckList.Critical, Options = pq.CheckList.ChecklistOptionLinks.Where(o => o.Status == "Current").Select(o => o.Option).ToList(), }).ToList().OrderBy(c => float.Parse(c.ItemNumber, CultureInfo.InvariantCulture.NumberFormat)).ThenBy(c => c.CheckListNumber).ToList(), }; return(View(reviewIM)); }
public async Task <IActionResult> AddReview(ReviewInputModel review) { if (ModelState.IsValid) { var user = await _userManager.GetUserAsync(HttpContext.User); var reviewer = user.FirstName + " " + user.LastName; _bookService.AddReview(review, user.Id, reviewer); return(Ok()); } return(BadRequest()); }
//Updates a user review for a tape //Throws exception if either user id or tape id are invalid public void UpdateUserReviewForTape(ReviewInputModel review, int userId, int tapeId) { var user = _userService.IsValidId(userId); var tape = _tapeService.IsValidId(tapeId); var oldReview = _repository.GetUserReviewForTape(userId, tapeId); if (oldReview == null) { throw new ResourceNotFoundException($"Review for user {userId} and tape {tapeId} does not exist!"); } _repository.UpdateUserReviewForTape(Mapper.Map <Review>(review), userId, tapeId); }
public async Task <IActionResult> Create(ReviewInputModel input) { if (!ModelState.IsValid) { return(this.View(input)); } var userId = this.userManager.GetUserId(this.User); int id = await reviewsService.Create(input.BookId, input.BookRating, input.Content, userId); return(RedirectToAction("Details", "Books", new { bookId = id })); }
public void AddUserReviewForPublication_WhenCalledWithExistingIds_ReturnsCreatedResult() { var review = new ReviewInputModel() { Rating = 5 }; var createdResult = _controller.AddUserReviewForPublication(1, 1, review); var result = Assert.IsType <CreatedAtRouteResult>(createdResult); Assert.Equal(201, result.StatusCode); }
public void UpdateReview_WhenUpdatesWithExistingId_ReturnsOkResult() { var review = new ReviewInputModel() { Rating = 5, }; var okResult = _controller.UpdateReview(1, 1, review); var result = Assert.IsType <OkObjectResult>(okResult); Assert.Equal(200, result.StatusCode); }
public async Task <IActionResult> UpdateReviewForTape( [FromRoute] int friendId, [FromRoute] int tapeId, [FromBody] ReviewInputModel inputModel ) { var review = await ReviewsService.GetSingle(friendId, tapeId); review.Rating = inputModel.Rating; ReviewsService.Update(review); return(NoContent()); }
public void SaveReview(ReviewInputModel input) { //logic }