public async Task <ActionResult> RejectQuoteRequest(string number)
        {
            if (string.IsNullOrEmpty(number))
            {
                throw new HttpException(404, string.Empty);
            }
            //Need lock to prevent concurrent access to same quote
            using (var lockObject = await AsyncLock.GetLockByKey("quote:" + number).LockAsync())
            {
                var quoteRequest = await GetCustomerQuoteRequestByIdAsync(number);

                if (quoteRequest == null)
                {
                    throw new HttpException(404, string.Empty);
                }

                _quoteRequestBuilder.TakeQuoteRequest(quoteRequest);
                _quoteRequestBuilder.Reject();
                await _quoteRequestBuilder.SaveAsync();
            }

            return(StoreFrontRedirect("~/account/quote-requests"));
        }
Пример #2
0
        public async Task <ActionResult> AddItem([FromBody] AddQuoteItem addQuoteItem)
        {
            EnsureQuoteRequestBelongsToCurrentCustomer(WorkContext.CurrentQuoteRequest.Value);
            _quoteRequestBuilder.TakeQuoteRequest(WorkContext.CurrentQuoteRequest.Value);

            using (await AsyncLock.GetLockByKey(GetAsyncLockQuoteKey(_quoteRequestBuilder.QuoteRequest.Id)).LockAsync())
            {
                var products = await _catalogService.GetProductsAsync(new[] { addQuoteItem.ProductId }, ItemResponseGroup.ItemInfo | ItemResponseGroup.ItemWithPrices);

                if (products != null && products.Any())
                {
                    _quoteRequestBuilder.AddItem(products.First(), addQuoteItem.Quantity);
                    await _quoteRequestBuilder.SaveAsync();
                }
            }

            return(Ok());
        }
        public async Task <ActionResult> AddItem(string productId, int quantity)
        {
            EnsureQuoteRequestBelongsToCurrentCustomer(WorkContext.CurrentQuoteRequest);
            _quoteRequestBuilder.TakeQuoteRequest(WorkContext.CurrentQuoteRequest);

            using (await AsyncLock.GetLockByKey(GetAsyncLockQuoteKey(_quoteRequestBuilder.QuoteRequest.Id)).LockAsync())
            {
                var products = await _catalogSearchService.GetProductsAsync(new[] { productId }, ItemResponseGroup.ItemLarge);

                if (products != null && products.Any())
                {
                    _quoteRequestBuilder.AddItem(products.First(), quantity);
                    await _quoteRequestBuilder.SaveAsync();
                }
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }