public ActionResult StatesBulkEdit(LocationsStatesIndexViewModel model, IEnumerable <int> itemIds, string returnUrl) { if (!Services.Authorizer.Authorize(Permissions.OShopPermissions.ManageShopSettings, T("Not allowed to manage States"))) { return(new HttpUnauthorizedResult()); } if (itemIds != null && model.BulkAction != LocationsBulkAction.None) { int counter = 0; foreach (int itemId in itemIds) { var state = _locationService.GetState(itemId); if (state != null) { switch (model.BulkAction) { case LocationsBulkAction.Enable: state.Enabled = true; break; case LocationsBulkAction.Disable: state.Enabled = false; break; case LocationsBulkAction.Remove: _locationService.DeleteState(state); break; } counter++; } } switch (model.BulkAction) { case LocationsBulkAction.Enable: Services.Notifier.Information(T.Plural("One state successfully enabled.", "{0} states successfully enabled.", counter)); break; case LocationsBulkAction.Disable: Services.Notifier.Information(T.Plural("One state successfully disabled.", "{0} states successfully disabled.", counter)); break; case LocationsBulkAction.Remove: Services.Notifier.Information(T.Plural("One state successfully deleted.", "{0} states successfully deleted.", counter)); break; } } return(this.RedirectLocal(returnUrl, () => RedirectToAction("states"))); }
public ActionResult States(LocationsStatesIndexViewModel model, PagerParameters pagerParameters) { if (!Services.Authorizer.Authorize(Permissions.OShopPermissions.ManageShopSettings, T("Not allowed to manage States"))) { return(new HttpUnauthorizedResult()); } var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters); var states = _locationService.GetStates(); if (model.CountryId > 0) { states = states.Where(s => s.LocationsCountryRecord.Id == model.CountryId); } if (model.ZoneId > 0) { states = states.Where(c => c.ShippingZoneRecord != null && c.ShippingZoneRecord.Id == model.ZoneId); } switch (model.Filter) { case LocationsFilter.Disabled: states = states.Where(c => !c.Enabled); break; case LocationsFilter.Enabled: states = states.Where(c => c.Enabled); break; } var pagerShape = Shape.Pager(pager).TotalItemCount(states.Count()); var viewModel = new LocationsStatesIndexViewModel() { Countries = _locationService.GetCountries(), States = states.Skip(pager.GetStartIndex()).Take(pager.PageSize), Pager = pagerShape, BulkAction = LocationsBulkAction.None, Filter = model.Filter, ShippingZones = _shippingService != null?_shippingService.GetZones() : new List <ShippingZoneRecord>(), CountryId = model.CountryId, ZoneId = model.ZoneId, // Optional features ShippingEnabled = _featureManager.GetEnabledFeatures().Where(f => f.Id == "OShop.Shipping").Any() }; return(View(viewModel)); }
public ActionResult StatesBulkSetZone(LocationsStatesIndexViewModel model, IEnumerable <int> itemIds, string returnUrl) { if (!Services.Authorizer.Authorize(Permissions.OShopPermissions.ManageShopSettings, T("Not allowed to manage States"))) { 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 state zones")); return(this.RedirectLocal(returnUrl, () => RedirectToAction("States"))); } } int counter = 0; foreach (int itemId in itemIds) { var state = _locationService.GetState(itemId); if (state != null) { state.ShippingZoneRecord = zone; counter++; } } Services.Notifier.Information(T.Plural("One state zone successfully updated.", "{0} states zones successfully updated.", counter)); } return(this.RedirectLocal(returnUrl, () => RedirectToAction("States"))); }