public CartWidgetModel GetCartWidgetFromSource(string id, string countryCode, string locale)
        {
            var proxy = ServiceClientProvider.GetShoppingCartServiceProxy();

            try
            {
                var circuitBreaker =
                    CircuitBreakerFactory.GetFactory().GetCircuitBreaker <GetShoppingCartResponse_V01>();
                var response =
                    circuitBreaker.Execute(() => proxy.GetShoppingCart(new GetShoppingCartRequest1(new GetShoppingCartRequest_V01
                {
                    Locale        = locale,
                    DistributorId = id,
                    Platform      = "MyHL"
                })).GetShoppingCartResult as GetShoppingCartResponse_V01);

                if (response != null && response.Status == ServiceProvider.ShoppingCartSvc.ServiceResponseStatusType.Success)
                {
                    return(GetCartWidgetModel(response));
                }
                LogErrorIfAny(response);
            }
            catch (Exception ex)
            {
                LoggerHelper.Exception("Error", ex,
                                       "Errored out in GetCartWidgetFromSource " + id + countryCode);
                if (null != proxy)
                {
                    proxy.Close();
                }
                throw;
            }
            finally
            {
                if (null != proxy)
                {
                    proxy.Close();
                }
            }

            return(new CartWidgetModel());
        }
        public CartWidgetModel AddToCart(CartWidgetModel cartWidget, string id, string countryCode, string locale)
        {
            if (null == cartWidget)
            {
                throw new ArgumentException("cartWidget is null", "cartWidget");
            }
            if (string.IsNullOrEmpty(countryCode))
            {
                throw new ArgumentException("countryCode is blank", "countryCode");
            }

            if (string.IsNullOrEmpty(locale))
            {
                throw new ArgumentException("Locale is blank", "locale");
            }

            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException("id is blank", "id");
            }

            var cartModel = GetCartWidget(id, countryCode, locale);

            if (null != cartModel)
            {
                cartWidget.Id = cartModel.Id;
                var proxy = ServiceClientProvider.GetShoppingCartServiceProxy();
                try
                {
                    var circuitBreaker =
                        CircuitBreakerFactory.GetFactory().GetCircuitBreaker <AddItemsToCartResponse_V01>();
                    var response =
                        circuitBreaker.Execute(() => proxy.AddItemsToCart(new AddItemsToCartRequest1(new AddItemsToCartRequest_V01
                    {
                        ShoppingCartID = cartWidget.Id,
                        OrderItems     =
                            new List <ServiceProvider.ShoppingCartSvc.OrderItem>
                        {
                            new ServiceProvider.ShoppingCartSvc.OrderItem {
                                Quantity = cartWidget.Quantity, SKU = cartWidget.Sku
                            }
                        },
                        Platform      = "MyHL",
                        DistributorId = id,
                        Locale        = locale
                    }))).AddItemsToCartResult as AddItemsToCartResponse_V01;

                    if (response != null && response.Status == ServiceProvider.ShoppingCartSvc.ServiceResponseStatusType.Success)
                    {
                        ExpireShoppingCartCache(id, locale);
                        ClearShoppingCartFromSession(id, locale);
                        return(new CartWidgetModel
                        {
                            Id = response.ShoppingCartID,
                            Quantity = response.TotalItems,
                            Subtotal = response.Subtotal,
                            DisplaySubtotal =
                                String.Format("{0}{1}",
                                              HLConfigManager.Configurations.CheckoutConfiguration.CurrencySymbol,
                                              response.Subtotal)
                        });
                    }

                    LogErrorIfAny(response);

                    return(null);
                }
                catch (Exception ex)
                {
                    LoggerHelper.Exception("Error", ex,
                                           "Errored out in AddToCart");
                    if (null != proxy)
                    {
                        proxy.Close();
                    }
                    throw;
                }
                finally
                {
                    if (null != proxy)
                    {
                        proxy.Close();
                    }
                }
            }
            return(null);
        }