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);
        }
Exemplo n.º 2
0
        public async Task <IQuoteRequestBuilder> GetOrCreateNewTransientQuoteRequestAsync(Store store, CustomerInfo customer, Language language, Currency currency)
        {
            var cacheKey = GetQuoteRequestCacheKey(store.Id, customer.Id);

            _quoteRequest = await _cacheManager.GetAsync(cacheKey, _quoteRequestCacheRegion, async() =>
            {
                QuoteRequest quoteRequest     = null;
                var activeQuoteSearchCriteria = new VirtoCommerceDomainQuoteModelQuoteRequestSearchCriteria
                {
                    Tag        = "actual",
                    CustomerId = customer.Id,
                    StoreId    = store.Id
                };
                var searchResult = await _quoteApi.QuoteModuleSearchAsync(activeQuoteSearchCriteria);
                quoteRequest     = searchResult.QuoteRequests.Select(x => x.ToWebModel(store.Currencies, language)).FirstOrDefault();
                if (quoteRequest == null)
                {
                    quoteRequest            = new QuoteRequest(currency, language);
                    quoteRequest.Currency   = currency;
                    quoteRequest.CustomerId = customer.Id;
                    quoteRequest.Language   = language;
                    quoteRequest.Status     = "New";
                    quoteRequest.StoreId    = store.Id;
                    quoteRequest.Tag        = "actual";

                    if (!customer.IsRegisteredUser)
                    {
                        quoteRequest.CustomerName = StorefrontConstants.AnonymousUsername;
                    }
                    else
                    {
                        quoteRequest.CustomerName = string.Format("{0} {1}", customer.FirstName, customer.LastName);
                    }
                }
                else
                {
                    quoteRequest = (await _quoteApi.QuoteModuleGetByIdAsync(quoteRequest.Id)).ToWebModel(store.Currencies, language);
                }

                quoteRequest.Customer = customer;

                return(quoteRequest);
            });

            return(this);
        }
        public async Task <ActionResult> GetCustomerQuoteRequests()
        {
            var criteria            = WorkContext.CurrentQuoteSearchCriteria;
            var quoteSearchCriteria = new VirtoCommerceDomainQuoteModelQuoteRequestSearchCriteria
            {
                Start      = criteria.Start,
                Count      = criteria.PageSize,
                StoreId    = WorkContext.CurrentStore.Id,
                CustomerId = WorkContext.CurrentCustomer.Id,
            };

            var searchResult = await _quoteApi.QuoteModuleSearchAsync(quoteSearchCriteria);

            if (searchResult != null)
            {
                WorkContext.CurrentCustomer.QuoteRequests = new StorefrontPagedList <QuoteRequest>(
                    searchResult.QuoteRequests.Select(x => x.ToWebModel(WorkContext.AllCurrencies, WorkContext.CurrentLanguage)),
                    criteria.PageNumber, criteria.PageSize,
                    searchResult.TotalCount.Value,
                    page => WorkContext.RequestUrl.SetQueryParameter("page", page.ToString()).ToString());
            }

            return(View("customers/quote-requests", WorkContext));
        }