public ActionResult IndexPOST(ShippingZonesIndexViewModel model, IEnumerable<int> itemIds, string returnUrl) { if (!Services.Authorizer.Authorize(Permissions.OShopPermissions.ManageShopSettings, T("Not allowed to manage shipping zones"))) return new HttpUnauthorizedResult(); if (itemIds != null && model.BulkAction != ShippingZoneBulkAction.None) { int counter = 0; foreach (int itemId in itemIds) { var zone = _shippingService.GetZone(itemId); if (zone != null) { switch (model.BulkAction) { case ShippingZoneBulkAction.Enable: zone.Enabled = true; break; case ShippingZoneBulkAction.Disable: zone.Enabled = false; break; case ShippingZoneBulkAction.Remove: _shippingService.DeleteZone(zone); break; } counter++; } } switch (model.BulkAction) { case ShippingZoneBulkAction.Enable: Services.Notifier.Information(T.Plural("One zone successfully enabled.", "{0} zones successfully enabled.", counter)); break; case ShippingZoneBulkAction.Disable: Services.Notifier.Information(T.Plural("One zone successfully disabled.", "{0} zones successfully disabled.", counter)); break; case ShippingZoneBulkAction.Remove: Services.Notifier.Information(T.Plural("One zone successfully deleted.", "{0} zones successfully deleted.", counter)); break; } } return this.RedirectLocal(returnUrl, () => RedirectToAction("Index")); }
public ActionResult Index(ShippingZonesIndexViewModel model, PagerParameters pagerParameters) { if (!Services.Authorizer.Authorize(Permissions.OShopPermissions.ManageShopSettings, T("Not allowed to manage shipping zones"))) return new HttpUnauthorizedResult(); var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters); var zones = _shippingService.GetZones(); switch (model.Filter) { case ShippingZoneFilter.Disabled: zones = zones.Where(z => !z.Enabled); break; case ShippingZoneFilter.Enabled: zones = zones.Where(z => z.Enabled); break; } var pagerShape = Shape.Pager(pager).TotalItemCount(zones.Count()); var viewModel = new ShippingZonesIndexViewModel() { Zones = zones.Skip(pager.GetStartIndex()).Take(pager.PageSize), Pager = pagerShape, BulkAction = ShippingZoneBulkAction.None, Filter = model.Filter }; return View(viewModel); }