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

            var record = _locationService.GetState(model.Id);

            if (record == null)
            {
                return(new HttpNotFoundResult());
            }

            if (ModelState.IsValid)
            {
                record.Name    = model.Name;
                record.IsoCode = model.IsoCode;
                record.Enabled = model.Enabled;
                record.LocationsCountryRecord = model.CountryId > 0 ? _locationService.GetCountry(model.CountryId) : null;

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

                Services.Notifier.Information(T("State {0} successfully updated.", model.Name));
            }

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

            return(View(model));
        }
예제 #2
0
        public ActionResult EditState(int id)
        {
            if (!Services.Authorizer.Authorize(Permissions.OShopPermissions.ManageShopSettings, T("Not allowed to manage States")))
            {
                return(new HttpUnauthorizedResult());
            }

            var record = _locationService.GetState(id);

            if (record == null)
            {
                return(new HttpNotFoundResult());
            }

            var model = new LocationsStatesEditViewModel()
            {
                Name           = record.Name,
                IsoCode        = record.IsoCode,
                Enabled        = record.Enabled,
                CountryId      = record.LocationsCountryRecord != null ? record.LocationsCountryRecord.Id : 0,
                ShippingZoneId = record.ShippingZoneRecord != null ? record.ShippingZoneRecord.Id : 0
            };

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

            return(View(model));
        }