public void AddReviewForCustomer(ReviewFromCustomerDTO review)
        {
            var customer = _customerDb.Customers.SingleOrDefault(c => c.Email == review.CustomerEmail);

            if (customer == null)
            {
                throw new NotFoundException(review.CustomerEmail);
            }
            var product = _customerDb.Products.Include(p => p.Reviews).SingleOrDefault(p => p.ProductId == review.ProductId);

            product.Reviews.Add(new Review {
                CustomerId = customer.CustomerId, Stars = 5 /* TODO: Fix */, Comments = review.Review
            });
            _customerDb.SaveChanges();
        }
Exemplo n.º 2
0
        public ActionResult MakeReview([FromBody] ReviewFromCustomerDTO review)
        {
            _logger.LogInformation($"Make Review called with <{review.CustomerEmail}> <{review.ProductId}> <{review.Review}>");
            // SQL update here

            try
            {
                _repository.AddReviewForCustomer(review);
            }
            catch (NotFoundException)
            {
                return(StatusCode(500, "Customer Email not found"));
            }

            return(Ok());
        }