public void GetById_GivenReviewId_ReturnsCorrectReview()
        {
            var review = new Review
            {
                ReviewId       = Guid.NewGuid(),
                ReviewPublicId = Guid.NewGuid(),
                Restaurant     = _testContext.Restaurants.First()
            };

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

            var result = _reviewRepository.GetById(review.ReviewPublicId);

            Assert.AreEqual(review, result);
        }
Example #2
0
        public void TestGetByIdReview()
        {
            Review testReview = new Review()
            {
                Id      = 1,
                Comment = "Bueni",
                Score   = 5
            };
            List <Review> reviewsList = new List <Review>()
            {
                new Review()
                {
                    Id      = 5,
                    Comment = "Bueni",
                    Score   = 5
                },
            };

            reviewsList.Add(testReview);
            reviewsList.ForEach(r => _context.Add(r));
            _context.SaveChanges();
            var repository = new ReviewRepository(_context);

            var result = repository.GetById(1);

            Assert.AreEqual(testReview, result);
        }
Example #3
0
        public ActionResult Delete(int id)
        {
            Review review = reviewRepository.GetById(id);

            reviewRepository.Delete(review);
            return(RedirectToAction("Index"));
        }
Example #4
0
        public void GetById_SeededReview()
        {
            var review = _reviewRepositorySUT.GetById(Seed.Review1.Id);

            Assert.Equal(ReviewMapper.MapToDetailModel(Seed.Review1), review,
                         ReviewDetailModel.ReviewDetailModelComparer);
        }
        public ActionResult EditModify(int id)
        {
            var reviewRepository = new ReviewRepository();
            var reviewToModify   = reviewRepository.GetById(id);

            return(View(reviewToModify));
        }
        public ActionResult Delete(int id)
        {
            reviewRepository = new ReviewRepository();
            var review = reviewRepository.GetById(id);

            return(View(review));
        }
 public ReviewsEditVM(int reviewID, ReviewRepository newReviewRepository,
                      RestaurantRepository newRestaurantRepository)
 {
     restaurantRepository = newRestaurantRepository;
     reviewRepository     = newReviewRepository;
     MyReview             = reviewRepository.GetById(reviewID);
     MyRestaurants        = restaurantRepository.GetAll();
 }
 // GET: Reviews/Details/5
 public ActionResult Details(int id)
 {
     try
     {
         Review r = reviewRepository.GetById(id);
         if (r == null)
         {
             throw new ArgumentNullException("id");
         }
         return(View(r));
     }
     catch (Exception e)
     {
         log.Error($"[Reviews Controller] [Details] Exception thrown: {e.Message}");
         return(RedirectToAction("Index"));
     }
 }
Example #9
0
        public async Task <ActionResult <Review> > Get(int user_id, int review_id)
        {
            try
            {
                // Searching for record in the database
                var response = await _repository.GetById(user_id, review_id);

                return(response);
            }
            catch (Npgsql.PostgresException ex)
            {
                // Postgres threw an exception
                return(BadRequest(ex.Message.ToString()));
            }
            catch
            {
                // Unknown error
                return(NotFound("Review record you are searching for does not exist or the URL is wrong"));
            }
        }
 public IActionResult FlagReview(Guid ReviewId)
 {
     if (ModelState.IsValid)
     {
         var rev = reviewRepository.GetById(ReviewId);
         reviewRepository.MarkDeleted(rev);
         reviewRepository.CommitChanges();
         Guid          AdminId    = Guid.Parse(this.User.FindFirstValue(ClaimTypes.NameIdentifier));
         FlaggedReview flaggedRev = new FlaggedReview();
         flaggedRev.AdminUserId = AdminId;
         flaggedRev.ReviewId    = ReviewId;
         flaggedRev.Comments    = " ";
         flaggedReviewRepository.Insert(flaggedRev);
         flaggedReviewRepository.CommitChanges();
         return(RedirectToAction("ViewReviews"));
     }
     else
     {
         ModelState.AddModelError("Error", "Review couldnt be flagged.");
         return(RedirectToAction("Error", "AdminUser"));
     }
 }
        public void GetById_Returns_Created_Item()
        {
            var expectedReview = new Review()
            {
                Content = "Baby"
            };

            underTest.Create(expectedReview);

            var result = underTest.GetById(expectedReview.Id);  // The Id was set by EF when we call Create above.

            Assert.Equal(expectedReview.Coffee, result.Coffee);
        }
Example #12
0
        public ActionResult EditSubmit(Review review)
        {
            // missing PublishDate
            if (review.PublishDate == DateTime.MinValue)
            {
                TempData["Error"] = TempData["Error"] + " Publish Date was empty";
            }

            // missing Type
            if (String.IsNullOrEmpty(review.ReviewType))
            {
                TempData["Error"] = TempData["Error"] + " Review Type was empty";
            }

            // missing header
            if (String.IsNullOrEmpty(review.ReviewHeader))
            {
                TempData["Error"] = TempData["Error"] + " Title was empty";
            }


            // missing review
            if (String.IsNullOrEmpty(review.ReviewText))
            {
                TempData["Error"] = TempData["Error"] + " Review was empty";
            }

            // return with error
            if (TempData["Error"] != null)
            {
                var ReviewRepository = new ReviewRepository();
                return(View("EditModify", ReviewRepository.GetById(review.Id)));
            }

            // final catch if somehow there is an issue, but gets by other checks
            if (!ModelState.IsValid)
            {
                var ReviewRepository = new ReviewRepository();
                TempData["Error"] = "Unable to process, form data was missing";
                return(View("EditModify", ReviewRepository.GetById(review.Id)));
            }

            var reviewRepository = new ReviewRepository();
            int changedId        = reviewRepository.Update(review);

            TempData["Success"] = "Successfully Updated Review " + review.Id;
            return(View("Index"));
        }
Example #13
0
        public void GetById_Returns_Created_Item()
        {
            var expectedReview = new Review()
            {
                Content      = "I love this pony",
                ReviewerName = "Carl",
                Rating       = 5.0,
                ProductId    = 1,
            };

            underTest.Create(expectedReview);

            var result = underTest.GetById(expectedReview.ReviewId);  // The Id was set by EF when we call Create above.

            Assert.Equal(expectedReview.Content, result.Content);
        }
        public GraphQL4BooksQuery(
            BookRepository bookRepository,
            UserRepository userRepository,
            ReviewRepository reviewRepository,
            AuthorRepository authorRepository)
        {
            Field <ListGraphType <BookType> >(
                "books",
                resolve: context => bookRepository.GetAll()
                );

            //FieldAsync<ListGraphType<BookType>>(
            //    "books",
            //    resolve: async context => await bookRepository.GetAll()
            //);

            Field <BookType>(
                "book",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            }),
                resolve: context =>
            {
                var id = context.GetArgument <Guid>("id");
                return(bookRepository.GetById(id));
            }
                );

            Field <ListGraphType <UserType> >(
                "users",
                resolve: context => userRepository.GetAll()
                );

            Field <UserType>(
                "user",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            }),
                resolve: context =>
            {
                var id = context.GetArgument <Guid>("id");
                return(userRepository.GetById(id));
            }
                );

            Field <ListGraphType <ReviewType> >(
                "reviews",
                resolve: context => reviewRepository.GetAll()
                );

            Field <ReviewType>(
                "review",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            }),
                resolve: context =>
            {
                var id = context.GetArgument <Guid>("id");
                return(reviewRepository.GetById(id));
            }
                );

            Field <ListGraphType <AuthorType> >(
                "authors",
                resolve: context => authorRepository.GetAll()
                );

            Field <AuthorType>(
                "author",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            }),
                resolve: context =>
            {
                var id = context.GetArgument <Guid>("id");
                return(authorRepository.GetById(id));
            }
                );
        }
Example #15
0
        public ReviewModel GetById(int id)
        {
            var review = _reviewRepository.GetById(id);

            return(_reviewMapper.MapReviewEntityToReviewModel(review));
        }
        public async Task <Review> GetById(int id)
        {
            var entity = await _repository.GetById(id);

            return(entity);
        }
Example #17
0
 // This resolver is not in the official ApolloFederationDemo, but is
 // needed to create a valid schemema
 public Review GetReviewById(
     [Service] ReviewRepository reviewRepository,
     string id)
 {
     return(reviewRepository.GetById(id));
 }
        public ActionResult Details(int id)
        {
            reviewRepository = new ReviewRepository();

            return(View(reviewRepository.GetById(id)));
        }
Example #19
0
 public Review GetReviewById(object id)
 {
     return(revrepo.GetById(id));
 }
Example #20
0
 public static Review GetById(int ReviewId)
 {
     return(ReviewRepository.GetById(ReviewId));
 }