public ActionResult IndexBulkEdit(LocationsCountriesIndexViewModel model, IEnumerable <int> itemIds, string returnUrl) { if (!Services.Authorizer.Authorize(Permissions.OShopPermissions.ManageShopSettings, T("Not allowed to manage Countries"))) { return(new HttpUnauthorizedResult()); } if (itemIds != null && model.BulkAction != LocationsBulkAction.None) { int counter = 0; foreach (int itemId in itemIds) { var country = _locationService.GetCountry(itemId); if (country != null) { switch (model.BulkAction) { case LocationsBulkAction.Enable: country.Enabled = true; break; case LocationsBulkAction.Disable: country.Enabled = false; break; case LocationsBulkAction.Remove: _locationService.DeleteCountry(country); break; } counter++; } } switch (model.BulkAction) { case LocationsBulkAction.Enable: Services.Notifier.Information(T.Plural("One country successfully enabled.", "{0} countries successfully enabled.", counter)); break; case LocationsBulkAction.Disable: Services.Notifier.Information(T.Plural("One country successfully disabled.", "{0} countries successfully disabled.", counter)); break; case LocationsBulkAction.Remove: Services.Notifier.Information(T.Plural("One country successfully deleted.", "{0} countries successfully deleted.", counter)); break; } } return(this.RedirectLocal(returnUrl, () => RedirectToAction("Index"))); }
public ActionResult Index(LocationsCountriesIndexViewModel model, PagerParameters pagerParameters) { if (!Services.Authorizer.Authorize(Permissions.OShopPermissions.ManageShopSettings, T("Not allowed to manage Countries"))) { return(new HttpUnauthorizedResult()); } var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters); var countries = _locationService.GetCountries(); if (model.ZoneId > 0) { countries = countries.Where(c => c.ShippingZoneRecord != null && c.ShippingZoneRecord.Id == model.ZoneId); } switch (model.Filter) { case LocationsFilter.Disabled: countries = countries.Where(c => !c.Enabled); break; case LocationsFilter.Enabled: countries = countries.Where(c => c.Enabled); break; } var pagerShape = Shape.Pager(pager).TotalItemCount(countries.Count()); var viewModel = new LocationsCountriesIndexViewModel() { DefaultCountryId = _locationService.GetDefaultCountryId(), Countries = countries.Skip(pager.GetStartIndex()).Take(pager.PageSize), Pager = pagerShape, BulkAction = LocationsBulkAction.None, Filter = model.Filter, ShippingZones = _shippingService != null?_shippingService.GetZones() : new List <ShippingZoneRecord>(), ZoneId = model.ZoneId, // Optional features ShippingEnabled = _featureManager.GetEnabledFeatures().Where(f => f.Id == "OShop.Shipping").Any() }; return(View(viewModel)); }
public ActionResult IndexBulkSetZone(LocationsCountriesIndexViewModel model, IEnumerable <int> itemIds, string returnUrl) { if (!Services.Authorizer.Authorize(Permissions.OShopPermissions.ManageShopSettings, T("Not allowed to manage Countries"))) { return(new HttpUnauthorizedResult()); } if (itemIds != null) { ShippingZoneRecord zone = null; if (model.BulkZoneId > 0) { zone = _shippingService.GetZone(model.BulkZoneId); if (zone == null) { Services.Notifier.Warning(T("Unknown zone : Unable to update contry zones")); return(this.RedirectLocal(returnUrl, () => RedirectToAction("Index"))); } } int counter = 0; foreach (int itemId in itemIds) { var country = _locationService.GetCountry(itemId); if (country != null) { country.ShippingZoneRecord = zone; counter++; } } Services.Notifier.Information(T.Plural("One country zone successfully updated.", "{0} countries zones successfully updated.", counter)); } return(this.RedirectLocal(returnUrl, () => RedirectToAction("Index"))); }