//post comments
        public async Task <CommentAC> CommentSection(int restaurantId, CommentAC commentac)
        {
            Comment comment = new Comment();
            var     x       = _dataRepository.Where <Restaurant>(r => r.ID == restaurantId);
            var     z       = await x.FirstAsync();

            var y = await _dataRepository.Where <Review>(r => r.ID == commentac.ReviewID).FirstAsync();

            _mapper.Map(commentac, comment);

            await _dataRepository.AddAsync <Comment>(comment);

            await _dataRepository.SaveChangesAsync();

            commentac.ID = comment.ID;
            return(commentac);
        }
예제 #2
0
        public async Task <IActionResult> CommentSection([FromRoute] int restaurantId, CommentAC commentac)
        {
            var c = await unitOfWork.Restaurant.CommentSection(restaurantId, commentac);

            return(Ok(c));
        }
예제 #3
0
        public async Task CommentSection_VerifyAdditionMultipleCommentsOnAReview()
        {
            List <Restaurant> restaurants = new List <Restaurant>
            {
                new Restaurant
                {
                    ID             = 1,
                    RestaurantName = "Domino's",
                    CuisineType    = "Italian",
                    Dishes         = new List <Dishes>
                    {
                        new Dishes
                        {
                            ID         = 1,
                            DishesName = "Pizza",
                            Costs      = 250
                        },
                        new Dishes
                        {
                            ID         = 2,
                            DishesName = "Taco",
                            Costs      = 150
                        }
                    }
                }
            };

            List <Review> reviews = new List <Review>
            {
                new Review
                {
                    ID          = 1,
                    ReviewTexts = "good",
                    Restaurant  = new Restaurant
                    {
                        ID = 1
                    },
                    User = new User
                    {
                        Id       = "dcbe1262-4be8-493a-8821-f4d52778d878",
                        FullName = "Nina Dobrev"
                    }
                }
            };

            CommentAC commentAC = new CommentAC
            {
                ID             = 1,
                UserID         = "dcbe1262-4be8-493a-8821-f4d52778d878",
                ReviewID       = 1,
                FullName       = "Nina Dobrev",
                CommentMessage = "Okay"
            };

            _dataRepository.Setup(s => s.Where(It.IsAny <Expression <Func <Restaurant, bool> > >())).Returns(restaurants.AsQueryable().BuildMock().Object);
            _dataRepository.Setup(s => s.Where(It.IsAny <Expression <Func <Review, bool> > >())).Returns(reviews.AsQueryable().BuildMock().Object);
            _dataRepository.Setup(s => s.AddAsync(It.IsAny <Expression <Func <Comment, bool> > >()));
            _dataRepository.Setup(s => s.SaveChangesAsync());

            await _unitOfWorkRepository.Restaurant.CommentSection(1, commentAC);

            _dataRepository.Verify(v => v.AddAsync(It.IsAny <Comment>()), Times.Once);
            _dataRepository.Verify(v => v.SaveChangesAsync());
        }