Beispiel #1
0
        /// <summary>
        /// Inserts an entire order from nopcommerce into isam
        /// </summary>
        /// <param name="order"></param>
        public async Task InsertOrderAsync(Order order)
        {
            var shipToRows = await _yahooService.GetYahooShipToRowsAsync(order);

            foreach (var row in shipToRows)
            {
                InsertUsingService(
                    SHIPTO_TABLE_NAME,
                    _shiptoCols,
                    _shiptoParams,
                    row.ToStringValues()
                    );
            }

            var headerRows = await _yahooService.GetYahooHeaderRowsAsync(order);

            foreach (var row in headerRows)
            {
                InsertUsingService(
                    HEADER_TABLE_NAME,
                    _headerCols,
                    _headerParams,
                    row.ToStringValues()
                    );
            }

            var detailRows = await _yahooService.GetYahooDetailRowsAsync(order);

            foreach (var row in detailRows)
            {
                InsertUsingService(
                    DETAIL_TABLE_NAME,
                    _detailCols,
                    _detailParams,
                    row.ToStringValues()
                    );
            }

            _baseIsamService.ExecuteBatch();

            // store amount used before insert order
            // insert order changes the amount in the object memory to properly calculate gift card amounts
            // for multiple orders
            decimal giftCardAmtUsed      = 0;
            var     giftCardUsageHistory = await _giftCardService.GetGiftCardUsageHistoryAsync(order);

            if (giftCardUsageHistory.Any())
            {
                giftCardAmtUsed = giftCardUsageHistory.OrderByDescending(gcu => gcu.CreatedOnUtc).FirstOrDefault().UsedValue;
            }

            // if there is a gift card, update gift card amt in isam
            if (giftCardUsageHistory.Any())
            {
                GiftCardUsageHistory orderGcUsage  = giftCardUsageHistory.FirstOrDefault();
                GiftCard             orderGiftCard = await _giftCardService.GetGiftCardByIdAsync(orderGcUsage.GiftCardId);

                var      isamGiftCardInfo    = _isamGiftCardService.GetGiftCardInfo(orderGiftCard.GiftCardCouponCode);
                GiftCard isamGiftCard        = isamGiftCardInfo.GiftCard;
                decimal  isamGiftCardAmtUsed = isamGiftCardInfo.AmountUsed;
                _isamGiftCardService.UpdateGiftCardAmt(isamGiftCard, isamGiftCardAmtUsed + giftCardAmtUsed);

                await _giftCardUsageHistoryRepository.DeleteAsync(orderGcUsage);

                await _giftCardService.UpdateGiftCardAsync(orderGiftCard);
            }
        }