Exemple #1
0
        public async Task <IActionResult> Create(ReviewViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                var review = new Review
                {
                    Mark           = model.Mark,
                    Heading        = model.Heading,
                    Text           = model.Text,
                    FilmId         = model.FilmId,
                    ReviewerId     = model.ReviewerId,
                    PublicatonDate = DateTime.Now
                };

                _reviewsRepository.Add(review);
                await _reviewsRepository.SaveChangesAsync();

                return(RedirectToAction("Details", "Film", new { id = model.FilmId }));
            }
            catch
            {
                return(View(model));
            }
        }
        public async Task <string> Post([FromBody] Review review)
        {
            if (review != null)
            {
                await _reviewRepository.Add(review);

                await Task.Factory.StartNew(() => SendConfirmation(review));
            }

            return(JsonConvert.SerializeObject(review));
        }
        public IActionResult Add(Reviews review)
        {
            var reviewCheck = _reviewsRepository.GetReviewById(review.Id);

            if (reviewCheck == null)
            {
                _reviewsRepository.Add(review);
                return(Ok(review));
            }
            return(Ok(reviewCheck));
        }
Exemple #4
0
        public async Task <IActionResult> AddReview([FromBody] ReviewDto reviewData)
        {
            //reviewData.orderId here will not be sent
            if (reviewData.Stars < 1 || reviewData.Stars > 5)
            {
                return(BadRequest("Star evaluation missing or is in incorrect format"));
            }

            var username = JWTtoken.GetUsernameFromToken(Request);

            if (username == null)
            {
                return(BadRequest());
            }

            var acc = await _accountManager.FindByNameAsync(username);

            var newestOrder = _ordersRepository.GetUserPurchaseHistory(acc.Id)
                              .OrderByDescending(order => order.Date)
                              .FirstOrDefault();

            if (newestOrder == null)
            {
                return(BadRequest("Order not found"));
            }

            if (_reviewsRepository.GetById(newestOrder.Id) != null)
            {
                return(BadRequest("This order already has a review"));
            }

            Review newReview = new Review
            {
                Id          = newestOrder.Id,
                Description = reviewData.Description,
                Stars       = reviewData.Stars
            };
            Review addedReview = _reviewsRepository.Add(newReview);

            if (addedReview == null)
            {
                return(BadRequest("Review could not be added"));
            }
            return(Ok("Review added successfully"));
        }