Example #1
0
        public async Task <IActionResult> AddReview(NewReviewDto dto)
        {
            dto.AuthorId = User.Claims.FirstOrDefault(c => c.Type.Contains("nameidentifier")).Value;
            var result = await _solutionApiClient.AddReviewAsync(dto);

            return(Redirect($"~/Product/{dto.SolutionId}"));
        }
Example #2
0
        public void Add(NewReviewDto review)
        {
            ValidateRating(review.Rating);
            var newReview = new Review
            {
                Content      = review.Content, Title = review.Title, Rating = review.Rating,
                EscapeRoomId = review.EscapeRoomId, UserId = review.UserId
            };

            _reviewRepository.Add(newReview);
        }
Example #3
0
        public async Task <ActionResult> Post(int id, NewReviewDto review)
        {
            var product = await productRepository.GetProductAsync(id);

            var result = product.AddReview(User.Identity.Name ?? "Unknown User", review.ReviewText, review.Stars);

            if (result.IsSuccess)
            {
                await productRepository.SaveChangesAsync();

                return(Ok());
            }
            return(BadRequest(result.ValidationResults));
        }
Example #4
0
        /// <summary>
        /// Добавление отзыва
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <ReviewDto> AddReviewAsync(NewReviewDto dto)
        {
            var sol = await _solutionRepository.GetAsync(dto.SolutionId);

            var review = _mapper.Map <Review>(dto);

            sol.Reviews.Add(review);
            if (sol.Rate == 0)
            {
                sol.Rate = review.Rate;
            }
            else
            {
                byte temp = (byte)(sol.Rate + dto.Rate);
                temp     = (byte)(temp / 2);
                sol.Rate = temp;
            }
            await _solutionRepository.SaveChangesAsync();

            return(_mapper.Map <ReviewDto>(review));
        }
Example #5
0
 public Task <ApiResponse <ReviewDto> > AddReviewAsync(NewReviewDto dto)
 {
     return(PostAsync <NewReviewDto, ApiResponse <ReviewDto> >(_clientOptions.AddReviewUrl, dto));
 }
        public async Task Common_Scenario_EscapeRooms_Reviews_And_Statistic()
        {
            var users = Client.GetAsync("api/users").Result.Content.ReadAsAsync <ICollection <UserDto> >().Result;

            Assert.AreEqual(1, users.Count);
            var userId     = users.First().Id;
            var escapeRoom = new NewEscapeRoomDto
            {
                BuildingNumber = 30, Category = Category.Abstract, City = "Kraków", Time = 80, Name = "StrasznyDwor",
                Email          = "*****@*****.**", Description = "Super hard escape room", Price = 150,
                ForAdult       = true, PhoneNumber = "433256643", MaxPeopleNumber = 5, Street = "BakerStreet"
            };
            await Client.PostAsJsonAsync("api/escaperooms", escapeRoom);

            var allEscapeRooms = await Client.GetAsync("api/escaperooms").Result.Content.ReadAsAsync <ICollection <EscapeRoomDto> >();

            Assert.AreEqual(1, allEscapeRooms.Count);
            var actualEscapeRoom = allEscapeRooms.First();

            Assert.AreEqual(escapeRoom.Category, actualEscapeRoom.Category);
            Assert.AreEqual(escapeRoom.Description, actualEscapeRoom.Description);
            Assert.AreEqual(escapeRoom.Name, actualEscapeRoom.Name);
            var editEscapeRoom = new EditEscapeRoomDto
            {
                ForAdult        = escapeRoom.ForAdult,
                BuildingNumber  = escapeRoom.BuildingNumber,
                Category        = escapeRoom.Category,
                City            = escapeRoom.City,
                Description     = escapeRoom.Description,
                Email           = escapeRoom.Email,
                MaxPeopleNumber = escapeRoom.MaxPeopleNumber,
                Name            = "EDITEDNAME",
                PhoneNumber     = escapeRoom.PhoneNumber,
                Price           = 200,
                Id = actualEscapeRoom.Id
            };
            await Client.PutAsJsonAsync("api/escaperooms", editEscapeRoom);

            var afterEditEscapeRoom = await Client.GetAsync($"api/escaperooms/{actualEscapeRoom.Id}").Result.Content.ReadAsAsync <EscapeRoomDto>();

            //Assert.AreEqual("EDITEDNAME", afterEditEscapeRoom.Name);
            //Assert.AreEqual(200, afterEditEscapeRoom.Price);
            await Client.DeleteAsync($"api/escaperooms/{actualEscapeRoom.Id}");

            var allEscapeRoomsAfterDelete = await Client.GetAsync("api/escaperooms").Result.Content.ReadAsAsync <ICollection <EscapeRoomDto> >();

            Assert.AreEqual(0, allEscapeRoomsAfterDelete.Count);
            await Client.PostAsJsonAsync("api/escaperooms", escapeRoom);

            allEscapeRooms = await Client.GetAsync("api/escaperooms").Result.Content.ReadAsAsync <ICollection <EscapeRoomDto> >();

            Assert.AreEqual(1, allEscapeRooms.Count);
            actualEscapeRoom = allEscapeRooms.First();
            var review1 = new NewReviewDto
            {
                UserId       = userId,
                Content      = "AwesomeTestRoom",
                EscapeRoomId = actualEscapeRoom.Id,
                Rating       = Rating.Eight,
                Title        = "Great"
            };
            await Client.PostAsJsonAsync("api/reviews", review1);

            var allReviews = Client.GetAsync($"api/reviews/byUser/{userId}").Result.Content.ReadAsAsync <ICollection <ReviewForUserDto> >().Result;

            Assert.AreEqual(1, allReviews.Count);
            var statistics = Client.GetAsync("api/statistics/CityStatistics/Kraków").Result.Content
                             .ReadAsAsync <CityStatisticsDto>().Result;

            Assert.AreEqual(80, statistics.AverageGameTime);
            Assert.AreEqual(150, statistics.AveragePrice);
            Assert.AreEqual(8, statistics.AverageRating);
            Assert.AreEqual(1, statistics.EscapeRoomsNumber);
            Assert.AreEqual(new Dictionary <string, int> {
                { "Abstract", 1 }
            }, statistics.FamousTypes);
        }
Example #7
0
        public async Task <IActionResult> CreateOneReview([FromRoute] Guid experienceId, [FromBody] NewReviewDto createdReview)
        {
            // map the incomming review dto to the review entity
            var reviewToAdd = _mapper.Map <Review>(createdReview);

            // add the necessary relations and id
            reviewToAdd.Id = Guid.NewGuid();
            //reviewToAdd.ExperienceId = experienceId;
            //var profileId = HttpContext.User.Claims.FirstOrDefault(x => x.Type == "profileId").Value;
            //reviewToAdd.ProfileId = Guid.Parse(profileId);
            reviewToAdd.CreatedOn = DateTime.Now;

            // save in database
            _reviewRepository.Create(reviewToAdd);

            if (!await _reviewRepository.SaveAsync())
            {
                var errMSg = "Error creating a review";
                _logger.Error(errMSg);
                var err = new ErrorObject()
                {
                    Method     = "POST",
                    At         = $"/api/experiences/{experienceId}/reviews",
                    StatusCode = 500,
                    Error      = errMSg
                };
                return(StatusCode(500, err));
            }

            return(CreatedAtAction(nameof(GetOneReview), new { experienceId, id = reviewToAdd.Id }, _mapper.Map <ViewOneReviewDto>(reviewToAdd)));
        }
 public ActionResult Post([FromBody] NewReviewDto value)
 {
     _reviewService.Add(value);
     return(Ok());
 }
Example #9
0
        public async Task <IActionResult> AddSolutionReviewAsync([FromBody] NewReviewDto review)
        {
            var result = await _solutionService.AddReviewAsync(review);

            return(ApiResult(result));
        }