示例#1
0
        public ActionResult <IEnumerable <CustomerViewDTO> > MyProductsAndReviews([FromQuery] string email) // Don't do this in a real app!
        {
            var customer = _repository.GetFullyLoadedCustomer(email);

            if (customer == null)
            {
                Console.WriteLine("Returning empty list"); return(Ok(null));
            }
            var productMapping = customer
                                 .Products
                                 .Select(cp => cp.Product)
                                 .Select(product =>
                                         new CustomerViewDTO {
                Product = product, Review = product.Reviews.SingleOrDefault(r => r.CustomerId == customer.CustomerId)
            }).ToList();

            return(productMapping);
        }