private void GetRates(EstimateShippingViewModel model)
        {
            if (SessionManager.CurrentUserHasCart(MTApp.CurrentStore) == true)
            {
                Order Basket = SessionManager.CurrentShoppingCart(MTApp.OrderServices, MTApp.CurrentStore);
                if (Basket != null)
                {
                    Basket.ShippingAddress.PostalCode = model.PostalCode;

                    if (model.CountryId != string.Empty)
                    {
                        Country current = MerchantTribe.Web.Geography.Country.FindByBvin(model.CountryId);
                        if (current != null)
                        {
                            Basket.ShippingAddress.CountryBvin = model.CountryId;
                            Basket.ShippingAddress.CountryName = current.DisplayName;
                            Basket.ShippingAddress.RegionBvin  = model.RegionId;
                            Basket.ShippingAddress.RegionName  = model.RegionId;
                        }
                    }

                    MTApp.OrderServices.Orders.Update(Basket);

                    SortableCollection <ShippingRateDisplay> Rates;
                    Rates = MTApp.OrderServices.FindAvailableShippingRates(Basket);

                    if (Rates.Count < 1)
                    {
                        TempData["message"] = "Unable to estimate at this time";
                    }
                    model.Rates = Rates.ToList();
                }
            }
        }
        public ActionResult IndexPost(EstimateShippingViewModel posted)
        {
            var model = BuildViewModel();

            if (posted != null)
            {
                model.PostalCode = posted.PostalCode;
                model.CountryId  = posted.CountryId;
                model.RegionId   = posted.RegionId;
            }
            GetRatesImpl(model);

            return(View(model));
        }
        //
        // GET: /EstimateShipping/
        public ActionResult Index()
        {
            EstimateShippingViewModel model = BuildViewModel();

            GetRates(model);

            // Populate Data for DropDownLists
            Country currentCountry = Country.FindByBvin(model.CountryId);

            if (currentCountry != null)
            {
                ViewBag.Regions = currentCountry.Regions;
            }

            return(View(model));
        }
        private EstimateShippingViewModel BuildViewModel()
        {
            ViewBag.Countries = HccApp.GlobalizationServices.Countries.FindActiveCountries();

            var model = new EstimateShippingViewModel();

            if (!string.IsNullOrEmpty(CurrentCart.ShippingAddress.CountryBvin))
            {
                model.CountryId = CurrentCart.ShippingAddress.CountryBvin;
            }
            if (!string.IsNullOrEmpty(CurrentCart.ShippingAddress.RegionBvin))
            {
                model.RegionId = CurrentCart.ShippingAddress.RegionBvin;
            }
            model.City       = CurrentCart.ShippingAddress.City;
            model.PostalCode = CurrentCart.ShippingAddress.PostalCode;

            return(model);
        }
        private void GetRatesImpl(EstimateShippingViewModel model)
        {
            CurrentCart.ShippingAddress.PostalCode = model.PostalCode;

            if (model.CountryId != string.Empty)
            {
                var current = HccApp.GlobalizationServices.Countries.Find(model.CountryId);
                if (current != null)
                {
                    CurrentCart.ShippingAddress.CountryBvin = model.CountryId;
                    CurrentCart.ShippingAddress.RegionBvin  = model.RegionId;
                }
            }

            HccApp.OrderServices.Orders.Update(CurrentCart);

            var rates = HccApp.OrderServices.FindAvailableShippingRates(CurrentCart);

            if (rates.Count < 1)
            {
                TempData["message"] = "Unable to estimate at this time";
            }
            model.Rates = rates.ToList();
        }
        private EstimateShippingViewModel BuildViewModel()
        {
            EstimateShippingViewModel model = new EstimateShippingViewModel();

            ViewBag.GetRatesButton = this.MTApp.ThemeManager().ButtonUrl("GetRates", Request.IsSecureConnection);
            ViewBag.Countries      = MTApp.CurrentStore.Settings.FindActiveCountries();

            if (SessionManager.CurrentUserHasCart(MTApp.CurrentStore))
            {
                Order basket = SessionManager.CurrentShoppingCart(MTApp.OrderServices, MTApp.CurrentStore);
                if (basket.ShippingAddress.CountryBvin != string.Empty)
                {
                    model.CountryId = basket.ShippingAddress.CountryBvin;
                }
                if (basket.ShippingAddress.RegionBvin != string.Empty)
                {
                    model.RegionId = basket.ShippingAddress.RegionBvin;
                }
                model.City       = basket.ShippingAddress.City;
                model.PostalCode = basket.ShippingAddress.PostalCode;
            }

            return(model);
        }