public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Products = await _client.GetProductsAsync(id.Value);

            if (Products == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        public async Task <OrderViewDto> Handle(OrderViewQuery request, CancellationToken cancellationToken)
        {
            var customerEmail = _userContextManager.GetCurrentUserEmail();
            var order         = await _context.Orders.AsNoTracking().Include(x => x.OrderProducts).FirstOrDefaultAsync(x => x.Id == request.OrderId && x.CustomerEmail == customerEmail, cancellationToken);

            if (order == null)
            {
                return(null);
            }
            var products = await _productsClient.GetProductsAsync(order.OrderProducts.Select(x => x.ProductId).ToArray(), cancellationToken);

            var result = _mapper.Map <OrderViewDto>(order);

            foreach (var orderPorduct in result.OrderProducts)
            {
                orderPorduct.Product = products.FirstOrDefault(x => x.Id == orderPorduct.ProductId);
            }
            return(result);
        }
예제 #3
0
        protected virtual async Task DoSingleUserWorkAsync(CancellationToken cancellationToken)
        {
            int iteration = 0;
            var random    = new Random();
            var customers = await customersClient.GetCustomersAsync();

            var customer = customers.ElementAt(random.Next(1, customers.Count()));

            Interlocked.Increment(ref totalRequests);

            while (!cancellationToken.IsCancellationRequested)
            {
                try
                {
                    var products5 = await productsClient.GetProductsAsync("for testing 5", true, cancellationToken);

                    var products4 = await productsClient.GetProductsAsync("for testing 4", true, cancellationToken);

                    var products6 = await productsClient.GetProductsAsync("for testing 6", true, cancellationToken);

                    var orderItems = products4.Take(1)
                                     .Concat(products5.Take(1))
                                     .Concat(products6.Take(1))
                                     .Select(x => new ApiModel.Order.NewOrderItemInfo()
                    {
                        ProductId = x.Id,
                        Quantity  = 4
                    })
                                     .ToList();

                    bool shouldAddOrder = (iteration++) % 4 == 0;

                    if (shouldAddOrder)
                    {
                        await ordersClient.AddNewOrderAsync(new ApiModel.Order.Request.AddOrderRequest()
                        {
                            CustomerId     = customer.Id,
                            EmployeeId     = 2,
                            Freight        = 1,
                            RequiredDate   = DateTime.Now.AddDays(3),
                            ShipAddress    = "Test address",
                            ShipCity       = "Never",
                            ShipCountry    = "Neverland",
                            ShipName       = "Test ship name",
                            ShipPostalCode = "12345",
                            ShipRegion     = "Test region",
                            OrderItems     = orderItems
                        }, cancellationToken);

                        Interlocked.Increment(ref totalRequests);
                    }

                    var orders = await ordersClient.GetOrdersAsync(customerId : customer.Id,
                                                                   cancellationToken : cancellationToken);

                    Interlocked.Increment(ref totalRequests);
                    Interlocked.Increment(ref totalRequests);
                    Interlocked.Increment(ref totalRequests);
                    Interlocked.Increment(ref totalRequests);
                }
                catch (Exception ex) when(ex is IOException || ex is TaskCanceledException)
                {
                    ;
                }
            }
        }