コード例 #1
0
        public async Task <Feedback> CreateAsync(long userId, long orderId, long productId, Feedback feedback, CancellationToken cancellationToken)
        {
            ValidateOrderAndCustomer(userId, orderId, cancellationToken);
            Feedback existingFeedback = default;

            try
            {
                existingFeedback = await GetAsync(userId, orderId, productId, cancellationToken);
            }
            catch (ArgumentException)
            {
            }

            if (existingFeedback != null)
            {
                throw new ArgumentException(FeedbackErrorMessages.ProductFeedbackAlreadyExists);
            }

            ValidateRating(feedback.Rating);

            // if all the filters passed, then we can create the new feedback using the repository
            feedback.CreateTime   = DateTime.UtcNow;
            feedback.CustomerSid  = userId;
            feedback.OrderSid     = orderId;
            feedback.FeedbackType = (int)FeedbackType.Product;

            var savedFeedback = await _productFeedbackManager.CreateFeedbackAsync(feedback, orderId, productId, cancellationToken);

            // Populate products just to display them
            var product = await _productFacade.GetProductByIdAsync(productId, cancellationToken);

            savedFeedback.Products = new List <Product> {
                product
            };

            await SetCacheAsync(feedback, orderId, productId, cancellationToken);

            return(savedFeedback);
        }