public async Task <IActionResult> HotelReview(long hotelId, IndexViewModel newReview, QueryParam queryParam)
        {
            var currentUser = await userManager.GetUserAsync(HttpContext.User);

            if (ModelState.IsValid)
            {
                await reviewService.AddReviewAsync(hotelId, newReview, currentUser.Id);

                return(RedirectToAction(nameof(HotelController.HotelInfo), "Hotel", new { hotelId }));
            }
            var blobsUri = await imageService.ListAsync(hotelId);

            var hotel = await hotelService.FindHotelByIdAsync(hotelId);

            var property = await hotelPropertyTypeService.FindPropertyByHotelIdAsync(hotelId);

            var roomBeds = roomBedService.GetRoomBeds();

            ViewData["propertyType"]  = property.PropertyType.Type;
            ViewData["averageRating"] = hotelService.AverageRating(hotel.Reviews);
            var reviewsPaging = hotelService.ReviewsList(hotel.Reviews, queryParam);

            newReview.User              = currentUser;
            newReview.Hotel             = hotel;
            newReview.RoomBeds          = roomBeds;
            newReview.FolderList        = blobsUri;
            newReview.ReviewsPagingList = reviewsPaging;
            return(View("HotelInfo", newReview));
        }
Пример #2
0
 protected override async Task Handle(AddReviewCommand request, CancellationToken cancellationToken)
 {
     var userId = uint.Parse(request.UserId);
     await _reviewService.AddReviewAsync(userId,
                                         request.ReviewMsg,
                                         request.ReviewFile,
                                         request.Rating,
                                         request.ScientificWorkId);
 }
Пример #3
0
        public async Task <IActionResult> CreateReview(string recipeId, [FromBody] ReviewForm review)
        {
            var authHeaderContents = Request.Headers["Authorization"];
            var accessToken        = authHeaderContents.ToString().Split(' ')[1];
            var uid = await _authClient.GetUid(accessToken);

            await _reviewClient.AddReviewAsync(uid, recipeId, review);

            return(NoContent());
        }
Пример #4
0
        public async Task <IActionResult> PlaceReview(ReviewViewModel newReview, long placeId)
        {
            var currentUser = await userManager.GetUserAsync(HttpContext.User);

            if (ModelState.IsValid)
            {
                await reviewService.AddReviewAsync(newReview, currentUser.Id, placeId);

                return(RedirectToAction(nameof(PlaceController.PlaceInfo), "Place", new { placeId }));
            }

            return(View("PlaceInfo", newReview));
        }
Пример #5
0
        public async Task <IActionResult> PostAsync(string id, [FromBody] AddReviewResource input)
        {
            try
            {
                if (input == null)
                {
                    return(BadRequest("Invalid input!"));
                }

                await _reviewService.AddReviewAsync(id, input);

                return(StatusCode(StatusCodes.Status201Created));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Пример #6
0
        public async Task <IActionResult> PostReview([FromBody] ReviewViewModel model)
        {
            try
            {
                var newReview = await reviewService.AddReviewAsync(model.UserName, model.BeerName,
                                                                   model.Rating, model.RMessage);

                var newReviewModel = new ReviewViewModel(newReview.RMessage, newReview.Rating,
                                                         newReview.User, newReview.UserId, newReview.Beer,
                                                         newReview.BeerId, newReview.ReviewedOn);

                return(Ok(newReviewModel));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public async Task AddReviewAsyncUserIsNotReviewerOfWorkDoNothing()
        {
            var reviewerId       = 1u;
            var scientificWorkId = 2u;
            var reviewMsg        = _faker.Rant.Review();
            var rating           = _faker.Random.Byte(1, 3);
            var reviewFile       = new FormFile(null, _faker.Random.Long(), _faker.Random.Long(), _faker.Internet.UserName(), _faker.System.FileName("pdf"));

            _reviewersWorkRepositoryMock.Setup(x => x.IsReviewerOfScientificWorkAsync(reviewerId, scientificWorkId)).ReturnsAsync(false);

            var err = await Record.ExceptionAsync(async
                                                      () => await _service.AddReviewAsync(reviewerId, reviewMsg, reviewFile, rating, scientificWorkId));

            err.Should().BeNull();

            _reviewRepositoryMock.Verify(x => x.AddReviewAsync(It.IsAny <Review>()), Times.Never);
            _emailSenderMock.VerifyNoOtherCalls();
        }
Пример #8
0
        public async Task <IActionResult> CreateNewReview()
        {
            try
            {
                var httpRequest = HttpContext.Request;
                var reviewModel = httpRequest.Form["entityData"];
                var item        = JsonConvert.DeserializeObject <ReviewCreateModel>(reviewModel);
                var result      = await SaveImage(FolderPath.Review);

                if (result.FileIsThere)
                {
                    item.ReviewImage = result.FileNames[0];
                }
                var res = await reviewService.AddReviewAsync(item);

                return(Created(string.Empty, res));
            }

            catch (Exception ex)
            {
                return(HandleExcpetion(ex));
            }
        }
Пример #9
0
        public async Task AddReviewAsyncUserIsNotReviewerOfWorkDoNothing()
        {
            var reviewerId       = 1u;
            var reviewMsg        = "This is my review!";
            var reviewFile       = new FormFile(null, 42534, 2345, "NameHaHa", "FileNameHueHue");
            var rating           = (byte)3;
            var scientificWorkId = 2u;

            _scientificWorkRepositoryMock.Reset();
            _scientificWorkRepositoryMock.Setup(x => x.IsReviewerOfScientificWorkAsync(reviewerId, scientificWorkId)).ReturnsAsync(false);

            _scientificWorkFileRepositoryMock.Reset();
            _userStoreMock.Reset();
            _fileManagerMock.Reset();
            _reviewRepositoryMock.Reset();
            _emailSenderMock.Reset();
            _reviewersWorkRepositoryMock.Reset();

            var err = await Record.ExceptionAsync(async
                                                      () => await _service.AddReviewAsync(reviewerId, reviewMsg, reviewFile, rating, scientificWorkId));

            err.Should().BeNull();

            _scientificWorkRepositoryMock.Verify(x => x.IsReviewerOfScientificWorkAsync(reviewerId, scientificWorkId), Times.Once);
            _scientificWorkRepositoryMock.Verify(x => x.GetEmailOfAuthorByWorkIdAsync(It.IsAny <uint>()), Times.Never);
            _scientificWorkRepositoryMock.Verify(x => x.ChangeStatusAsync(It.IsAny <ScientificWork>()), Times.Never);
            _scientificWorkRepositoryMock.Verify(x => x.GetWorkByIdAsync(It.IsAny <uint>()), Times.Never);
            _scientificWorkFileRepositoryMock.Verify(x => x.GetNewestVersionWithReviewsAsync(It.IsAny <uint>()), Times.Never);
            _scientificWorkFileRepositoryMock.Verify(x => x.GetReviewsCountInNewestVersion(It.IsAny <uint>()), Times.Never);
            _scientificWorkFileRepositoryMock.Verify(x => x.GetRatingSumFromVersion(It.IsAny <uint>()), Times.Never);
            _scientificWorkFileRepositoryMock.Verify(x => x.AddRatingAsync(It.IsAny <ScientificWorkFile>()), Times.Never);
            _userStoreMock.Verify(x => x.FindByIdAsync(It.IsAny <string>(), CancellationToken.None), Times.Never);
            _fileManagerMock.Verify(x => x.SaveFileAsync(It.IsAny <IFormFile>()), Times.Never);
            _reviewRepositoryMock.Verify(x => x.AddReviewAsync(It.IsAny <Review>()), Times.Never);
            _reviewersWorkRepositoryMock.Verify(x => x.GetReviewersCount(It.IsAny <uint>()), Times.Never);
            _emailSenderMock.Verify(x => x.SendToAuthorWorkGotRejectedAsync(It.IsAny <string>(), It.IsAny <uint>()), Times.Never);
            _emailSenderMock.Verify(x => x.SendNewVersionEnabledEmailAsync(It.IsAny <string>(), It.IsAny <uint>()), Times.Never);
            _emailSenderMock.Verify(x => x.SendToAuthorWorkGotAcceptedAsync(It.IsAny <string>(), It.IsAny <uint>()), Times.Never);
            _emailSenderMock.Verify(x => x.SendReceiveReviewEmailAsync(It.IsAny <string>(), It.IsAny <uint>()), Times.Never);
        }
Пример #10
0
        public async Task <IActionResult> PostReview(Review review, string name)
        {
            await reviewService.AddReviewAsync(review);

            return(RedirectToAction("Movie", new { id = review.ImdbId }));
        }