コード例 #1
0
        private async Task <IHttpActionResult> ValidateOrderAsync(OrderContract order)
        {
            if (order == null)
            {
                return(BadRequest("No order was specified"));
            }

            var productsRepository = await GetOrCreateProductsRepositoryAsync();

            var persistedProduct = await productsRepository.GetAsync(order.Product?.Id);

            if (persistedProduct == null)
            {
                return(NotFound());
            }

            var validationMessages = new List <string>();

            var productValidationMessages = _productValidator.Run(order.Product, persistedProduct);

            validationMessages.AddRange(productValidationMessages);

            var customerValidationMessages = _customerValidator.Run(order.Customer);

            validationMessages.AddRange(customerValidationMessages);

            if (validationMessages.Any())
            {
                return(Content(HttpStatusCode.BadRequest, validationMessages));
            }

            return(null);
        }