예제 #1
0
        public ActionResult AddCountry(LocationsCountriesAddViewModel model)
        {
            if (!Services.Authorizer.Authorize(Permissions.OShopPermissions.ManageShopSettings, T("Not allowed to manage Countries")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (ModelState.IsValid)
            {
                var record = new LocationsCountryRecord()
                {
                    Name          = model.Name,
                    IsoCode       = model.IsoCode,
                    AddressFormat = model.AddressFormat,
                    Enabled       = model.Enabled,
                };

                if (_shippingService != null)
                {
                    record.ShippingZoneRecord = _shippingService.GetZone(model.ShippingZoneId);
                }

                _locationService.AddCountry(record);
                Services.Notifier.Information(T("Country {0} successfully added.", model.Name));
                return(RedirectToAction("Index"));
            }

            model.ShippingZones = _shippingService != null?_shippingService.GetZones() : new List <ShippingZoneRecord>();

            return(View(model));
        }
예제 #2
0
 public void SetDefaulCountry(LocationsCountryRecord record)
 {
     if (record != null)
     {
         SetDefaulCountryId(record.Id);
     }
 }
예제 #3
0
        public void BuildCart(IShoppingCartService ShoppingCartService, ShoppingCart Cart)
        {
            LocationsStateRecord   state   = null;
            LocationsCountryRecord country = null;

            // Based on user selected location
            Int32 countryId = ShoppingCartService.GetProperty <int>("CountryId");

            if (countryId > 0)
            {
                country = _locationsService.GetCountry(countryId);
                Int32 stateId = ShoppingCartService.GetProperty <int>("StateId");
                if (stateId > 0)
                {
                    state = _locationsService.GetState(stateId);
                }
            }
            else
            {
                // Set default country
                country = _locationsService.GetDefaultCountry();
                if (country != null)
                {
                    ShoppingCartService.SetProperty <int>("CountryId", country.Id);
                }
            }

            Cart.Properties["BillingCountry"]  = country;
            Cart.Properties["BillingState"]    = state;
            Cart.Properties["ShippingCountry"] = country;
            Cart.Properties["ShippingState"]   = state;
        }
예제 #4
0
 public void DeleteCountry(LocationsCountryRecord record)
 {
     foreach (var state in _stateRepository.Fetch(state => state.LocationsCountryRecord == record))
     {
         _stateRepository.Delete(state);
     }
     _countryRepository.Delete(record);
 }
예제 #5
0
 public void Import(XDocument ImportedLocations)
 {
     foreach (var xCountry in ImportedLocations.Root.Elements("country"))
     {
         var countryIsoCode = xCountry.Attribute("iso_code").Value;
         var country        = _countryRepository.Get(c => c.IsoCode == countryIsoCode);
         if (country == null)
         {
             country = new LocationsCountryRecord()
             {
                 IsoCode       = countryIsoCode,
                 Name          = xCountry.Element("name").Value,
                 AddressFormat = xCountry.Element("address_format").Value
             };
             _countryRepository.Create(country);
         }
         else
         {
             country.Name          = xCountry.Element("name").Value;
             country.AddressFormat = xCountry.Element("address_format").Value;
         }
         foreach (var xState in xCountry.Element("states").Elements("state"))
         {
             var stateIsoCode = xState.Attribute("iso_code").Value;
             var state        = _stateRepository.Get(s => s.IsoCode == stateIsoCode && s.LocationsCountryRecord.Id == country.Id);
             if (state == null)
             {
                 state = new LocationsStateRecord()
                 {
                     IsoCode = stateIsoCode,
                     Name    = xState.Element("name").Value,
                     LocationsCountryRecord = country
                 };
                 _stateRepository.Create(state);
             }
             else
             {
                 state.Name = xState.Element("name").Value;
                 _stateRepository.Update(state);
             }
         }
     }
 }
예제 #6
0
 public void UpdateCountry(LocationsCountryRecord record)
 {
     _countryRepository.Update(record);
 }
예제 #7
0
 public void AddCountry(LocationsCountryRecord record)
 {
     _countryRepository.Create(record);
 }
예제 #8
0
 public void DeleteCountry(LocationsCountryRecord record)
 {
     _countryRepository.Delete(record);
 }