Ejemplo n.º 1
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() =>
            {
                var activeQuoteSearchCriteria = new QuoteModule.Client.Model.QuoteRequestSearchCriteria
                {
                    Tag        = "actual",
                    CustomerId = customer.Id,
                    StoreId    = store.Id
                };

                var searchResult = await _quoteApi.QuoteModuleSearchAsync(activeQuoteSearchCriteria);

                var quoteRequest = searchResult.QuoteRequests.Select(x => x.ToWebModel(store.Currencies, language)).FirstOrDefault();
                if (quoteRequest == null)
                {
                    quoteRequest = new QuoteRequest(currency, language)
                    {
                        Currency   = currency,
                        CustomerId = customer.Id,
                        Language   = language,
                        Status     = "New",
                        StoreId    = store.Id,
                        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);
        }
Ejemplo n.º 2
0
        private IMutablePagedList <QuoteRequest> GetCustomerQuotes(CustomerInfo customer)
        {
            var workContext = _workContextFactory();
            Func <int, int, IPagedList <QuoteRequest> > quotesGetter = (pageNumber, pageSize) =>
            {
                var quoteSearchCriteria = new QuoteModule.Client.Model.QuoteRequestSearchCriteria
                {
                    Count      = pageSize,
                    CustomerId = customer.Id,
                    Start      = (pageNumber - 1) * pageSize,
                    StoreId    = workContext.CurrentStore.Id
                };
                var cacheKey = "GetCustomerQuotes-" + quoteSearchCriteria.GetHashCode();
                var quoteRequestsResponse = _cacheManager.Get(cacheKey, string.Format(_customerQuotesCacheRegionFormat, customer.Id), () => _quoteApi.QuoteModuleSearch(quoteSearchCriteria));
                return(new StaticPagedList <QuoteRequest>(quoteRequestsResponse.QuoteRequests.Select(x => x.ToWebModel(workContext.AllCurrencies, workContext.CurrentLanguage)),
                                                          pageNumber, pageSize, quoteRequestsResponse.TotalCount.Value));
            };

            return(new MutablePagedList <QuoteRequest>(quotesGetter));
        }