public async Task <CustomerInfo> GetCustomerByIdAsync(string customerId)
        {
            var retVal = await _cacheManager.GetAsync(GetCacheKey(customerId), "ApiRegion", async() =>
            {
                var workContext = _workContextFactory();

                //TODO: Make parallels call
                var contact         = await _customerApi.CustomerModuleGetContactByIdAsync(customerId);
                CustomerInfo result = null;
                if (contact != null)
                {
                    result = contact.ToWebModel();
                    var currentOrderCriteria = workContext.CurrentOrderSearchCriteria;
                    var orderSearchcriteria  = new VirtoCommerceDomainOrderModelSearchCriteria
                    {
                        CustomerId    = customerId,
                        ResponseGroup = "full",
                        Start         = currentOrderCriteria.Start,
                        Count         = currentOrderCriteria.PageSize
                    };
                    var ordersResponse = await _orderApi.OrderModuleSearchAsync(orderSearchcriteria);
                    result.Orders      = new StorefrontPagedList <CustomerOrder>(ordersResponse.CustomerOrders.Select(x => x.ToWebModel(workContext.AllCurrencies, workContext.CurrentLanguage)),
                                                                                 currentOrderCriteria.PageNumber,
                                                                                 currentOrderCriteria.PageSize,
                                                                                 ordersResponse.TotalCount.Value, page => workContext.RequestUrl.SetQueryParameter("page", page.ToString()).ToString());

                    if (workContext.CurrentStore.QuotesEnabled)
                    {
                        var currentQuoteCriteria = workContext.CurrentQuoteSearchCriteria;
                        var quoteSearchCriteria  = new VirtoCommerceDomainQuoteModelQuoteRequestSearchCriteria
                        {
                            Count      = currentQuoteCriteria.PageSize,
                            CustomerId = customerId,
                            Start      = currentQuoteCriteria.Start,
                            StoreId    = workContext.CurrentStore.Id
                        };
                        var quoteRequestsResponse = await _quoteApi.QuoteModuleSearchAsync(quoteSearchCriteria);
                        result.QuoteRequests      = new StorefrontPagedList <QuoteRequest>(quoteRequestsResponse.QuoteRequests.Select(x => x.ToWebModel(workContext.AllCurrencies, workContext.CurrentLanguage)),
                                                                                           currentQuoteCriteria.PageNumber,
                                                                                           currentQuoteCriteria.PageSize,
                                                                                           quoteRequestsResponse.TotalCount.Value, page => workContext.RequestUrl.SetQueryParameter("page", page.ToString()).ToString());
                    }
                }

                return(result);
            });

            if (retVal != null)
            {
                var clone = retVal.JsonClone();
                clone.Orders        = retVal.Orders;
                clone.QuoteRequests = retVal.QuoteRequests;
                retVal = clone;
            }

            return(retVal);
        }
Exemple #2
0
        public async Task <ActionResult> Index(int page = 1)
        {
            if (page < 1)
            {
                page = 1;
            }

            var ordersResponse = await _orderApi.OrderModuleSearchAsync(criteriaCustomerId : WorkContext.CurrentCustomer.Id, criteriaResponseGroup : "full");

            WorkContext.CurrentCustomer.OrdersCount = ordersResponse.TotalCount.Value;
            WorkContext.CurrentCustomer.Orders      = ordersResponse.CustomerOrders.Select(o => o.ToWebModel()).ToList();
            return(View("customers/account", WorkContext));
        }