Пример #1
0
        public async Task <IActionResult> CreateReview([FromBody] CreateReview createDTO)
        {
            try
            {
                var userId    = HttpContext.User.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
                var nameClaim = HttpContext.User.FindFirst("name").Value;

                int    indexOfSpace = nameClaim.IndexOf(" ");
                string firstLetter  = nameClaim.Substring(0, 1);
                string lastName     = nameClaim.Substring(indexOfSpace + 1, nameClaim.Length - (indexOfSpace + 1));
                string name         = firstLetter + " " + lastName;

                var entityToCreate = _mapper.Map <Review>(createDTO);
                entityToCreate.UserId = userId;
                entityToCreate.Name   = name;
                var entity = await _reviewService.CreateAsync(entityToCreate);

                var view = _mapper.Map <ViewReview>(entity);
                return(Ok(view));
            }
            catch
            {
                return(StatusCode(500));
            }
        }
Пример #2
0
        private async Task SaveReviewAsync()
        {
            var review = GetReviewAsync();
            await _reviewService.CreateAsync(review);

            await UpdatePlaceClassification(PlaceId.Value);
        }
Пример #3
0
        public async Task <ActionResult> Details(int id, string review)
        {
            var book = await _bookServices.GetByIdAsync(id);

            var user = User.Identity.GetApplicationUser();

            if (book == null)
            {
                return(HttpNotFound());
            }

            string encodeReview = HtmlEncoder.Default.Encode(review);

            var bookReview = new Review()
            {
                UserId      = user.Id,
                BookId      = book.BookId,
                Comment     = encodeReview,
                CreatedDate = DateTimeOffset.Now,
                IsActive    = true
            };
            await _reviewServices.CreateAsync(bookReview);

            return(RedirectToAction("Details"));
        }
Пример #4
0
        public async Task <IActionResult> CreateReview([FromBody] Review review, [FromRoute] int restaurantId)
        {
            review.RestaurantId = restaurantId;
            await _service.CreateAsync(review);

            return(Ok(review));
        }
        public async Task CreateAsync_ShouldWorkCorrectly()
        {
            var review = new ReviewInputModel
            {
                Comment = "New comment",
                Rating  = 2
            };

            var reviewId = await _reviewService.CreateAsync(_userId, _productId, review);

            var reviewFromDb = await _context.Reviews
                               .FirstOrDefaultAsync(x => x.Id == reviewId);

            Assert.Equal(reviewFromDb.Comment, review.Comment);
            Assert.Equal(reviewFromDb.Rating, review.Rating);
            Assert.Equal(reviewFromDb.CreatorId, _userId);
            Assert.Equal(reviewFromDb.ProductId, _productId);
        }
Пример #6
0
        public async Task <ActionResult <Review> > CreateAsync(Review review)
        {
            try
            {
                await _reviewService.CreateAsync(review);

                return(Created($"api/reviews/{review.ReviewId}", review));
            }
            catch (Exception ex)
            {
                return(StatusCode(500));
            }
        }
Пример #7
0
        public async Task <IActionResult> Create([FromBody] ReviewModel reviewModel)
        {
            try
            {
                var review = await _reviewService.CreateAsync(reviewModel);

                return(Ok(review));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }