示例#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));
        }
 public async Task <IActionResult> AddCountry(string name)
 {
     return(Ok(await _locationsService.AddCountry(name)));
 }