private void PrepareShippingMethodModel(ShippingMethodModel model, ShippingMethod shippingMethod) { if (shippingMethod != null) { var allFilters = _shippingService.GetAllShippingMethodFilters(); var configUrls = allFilters .Select(x => x.GetConfigurationUrl(shippingMethod.Id)) .Where(x => x.HasValue()) .ToList(); model.FilterConfigurationUrls = configUrls .Select(x => string.Concat("'", x, "'")) .OrderBy(x => x) .ToList(); model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(shippingMethod); } else { model.FilterConfigurationUrls = new List <string>(); model.SelectedStoreIds = new int[0]; } model.AvailableStores = _services.StoreService.GetAllStores().ToSelectListItems(model.SelectedStoreIds); }
public virtual IActionResult EditMethod(ShippingMethodModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedView()); } var sm = _shippingService.GetShippingMethodById(model.Id); if (sm == null) { //No shipping method found with the specified id return(RedirectToAction("Methods")); } if (ModelState.IsValid) { sm = model.ToEntity(sm); _shippingService.UpdateShippingMethod(sm); //locales UpdateLocales(sm, model); SuccessNotification(_localizationService.GetResource("Admin.Configuration.Shipping.Methods.Updated")); return(continueEditing ? RedirectToAction("EditMethod", sm.Id) : RedirectToAction("Methods")); } //If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult EditMethod(ShippingMethodModel model, bool continueEditing, FormCollection form) { var sm = _shippingService.GetShippingMethodById(model.Id); if (sm == null) { return(HttpNotFound()); } if (ModelState.IsValid) { sm = model.ToEntity(sm); // Add\remove assigned rule sets. _ruleStorage.ApplyRuleSetMappings(sm, model.SelectedRuleSetIds); _shippingService.UpdateShippingMethod(sm); SaveStoreMappings(sm, model.SelectedStoreIds); UpdateLocales(sm, model); Services.EventPublisher.Publish(new ModelBoundEvent(model, sm, form)); NotifySuccess(T("Admin.Configuration.Shipping.Methods.Updated")); return(continueEditing ? RedirectToAction("EditMethod", sm.Id) : RedirectToAction("Methods")); } return(View(model)); }
public virtual IActionResult CreateMethod(ShippingMethodModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var sm = model.ToEntity <ShippingMethod>(); _shippingService.InsertShippingMethod(sm); //locales UpdateLocales(sm, model); SuccessNotification(_localizationService.GetResource("Admin.Configuration.Shipping.Methods.Added")); return(continueEditing ? RedirectToAction("EditMethod", new { id = sm.Id }) : RedirectToAction("Methods")); } //prepare model model = _shippingModelFactory.PrepareShippingMethodModel(model, null, true); //if we got this far, something failed, redisplay form return(View(model)); }
public ActionResult EditMethod(ShippingMethodModel model, bool continueEditing, FormCollection form) { if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedView()); } var sm = _shippingService.GetShippingMethodById(model.Id); if (sm == null) { return(RedirectToAction("Methods")); } if (ModelState.IsValid) { sm = model.ToEntity(sm); _shippingService.UpdateShippingMethod(sm); UpdateLocales(sm, model); _services.EventPublisher.Publish(new ModelBoundEvent(model, sm, form)); NotifySuccess(T("Admin.Configuration.Shipping.Methods.Updated")); return(continueEditing ? RedirectToAction("EditMethod", sm.Id) : RedirectToAction("Methods")); } return(View(model)); }
/// <summary> /// Prepare shipping method model /// </summary> /// <param name="model">Shipping method model</param> /// <param name="shippingMethod">Shipping method</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Shipping method model</returns> public virtual ShippingMethodModel PrepareShippingMethodModel(ShippingMethodModel model, ShippingMethod shippingMethod, bool excludeProperties = false) { Action <ShippingMethodLocalizedModel, int> localizedModelConfiguration = null; if (shippingMethod != null) { //fill in model values from the entity model = model ?? shippingMethod.ToModel(); //define localized model configuration action localizedModelConfiguration = (locale, languageId) => { locale.Name = shippingMethod.GetLocalized(entity => entity.Name, languageId, false, false); locale.Description = shippingMethod.GetLocalized(entity => entity.Description, languageId, false, false); }; } //prepare localized models if (!excludeProperties) { model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration); } return(model); }
public virtual async Task <IActionResult> EditMethod(ShippingMethodModel model, bool continueEditing) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedView()); } //try to get a shipping method with the specified id var shippingMethod = await _shippingService.GetShippingMethodByIdAsync(model.Id); if (shippingMethod == null) { return(RedirectToAction("Methods")); } if (ModelState.IsValid) { shippingMethod = model.ToEntity(shippingMethod); await _shippingService.UpdateShippingMethodAsync(shippingMethod); //locales await UpdateLocalesAsync(shippingMethod, model); _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Configuration.Shipping.Methods.Updated")); return(continueEditing ? RedirectToAction("EditMethod", shippingMethod.Id) : RedirectToAction("Methods")); } //prepare model model = await _shippingModelFactory.PrepareShippingMethodModelAsync(model, shippingMethod, true); //if we got this far, something failed, redisplay form return(View(model)); }
public BatchAddViewModels() { OrderList = new List <OrderModel>(); ShippingMethodModels = new List <SelectListItem>(); ShippingMethodModel = new ShippingMethodModel(); CountryModels = new List <SelectListItem>(); ShippingMethodCountryModel = new ShippingMethodCountryModel(); }
public IActionResult CreateMethod() { var model = new ShippingMethodModel(); //locales AddLocales(_languageService, model.Locales); return(View(model)); }
public TrackingNumberModel() { shippingMethod = new ShippingMethodModel(); shippingMethods = new List <SelectListItem>(); uploadTrackingNumberDetailModel = new UploadTrackingNumberDetailModel(); uploadTrackingNumberDetailModels = new List <UploadTrackingNumberDetailModel>(); PagedList = new PagedList <UploadTrackingNumberDetailModel>(); }
protected virtual void UpdateLocales(ShippingMethod shippingMethod, ShippingMethodModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(shippingMethod, x => x.Name, localized.Name, localized.LanguageId); _localizedEntityService.SaveLocalizedValue(shippingMethod, x => x.Description, localized.Description, localized.LanguageId); } }
public ActionResult CreateMethod() { var model = new ShippingMethodModel(); PrepareShippingMethodModel(model, null); AddLocales(_languageService, model.Locales); return(View(model)); }
private void PrepareShippingMethodModel(ShippingMethodModel model, ShippingMethod shippingMethod) { var allFilters = _shippingService.GetAllShippingMethodFilters(); model.FilterConfigurationUrls = allFilters .Select(x => "'" + x.GetConfigurationUrl(shippingMethod.Id) + "'") .OrderBy(x => x) .ToList(); }
private void PrepareShippingMethodModel(ShippingMethodModel model, ShippingMethod shippingMethod) { if (shippingMethod != null) { model.SelectedRuleSetIds = shippingMethod.RuleSets.Select(x => x.Id).ToArray(); } model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(shippingMethod); }
public ActionResult CreateMethod() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) return AccessDeniedView(); var model = new ShippingMethodModel(); //locales AddLocales(_languageService, model.Locales); return View(model); }
public Response AddShippingInfo(Guid customerId, ShippingMethodModel shippingMethodModel, string storeName) { var option = new ShippingOption { ShippingRateComputationMethodSystemName = shippingMethodModel.SystemName, Name = shippingMethodModel.Name, Description = shippingMethodModel.Description }; return(this.UpdateShippingInfo(customerId, option, storeName)); }
public virtual IActionResult CreateMethod() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedView()); } var model = new ShippingMethodModel(); //locales AddLocales(_languageService, model.Locales); return(View(model)); }
public async Task <IActionResult> CreateMethod(ShippingMethodModel model, bool continueEditing) { if (ModelState.IsValid) { var sm = model.ToEntity(); await _shippingMethodService.InsertShippingMethod(sm); SuccessNotification(_localizationService.GetResource("Admin.Configuration.Shipping.Methods.Added")); return(continueEditing ? RedirectToAction("EditMethod", new { id = sm.Id }) : RedirectToAction("Methods")); } //If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult CreateMethod() { if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedView()); } var model = new ShippingMethodModel(); PrepareShippingMethodModel(model, null); AddLocales(_languageService, model.Locales); return(View(model)); }
public ActionResult CreateMethod(ShippingMethodModel model, bool continueEditing) { if (ModelState.IsValid) { var sm = model.ToEntity(); _shippingService.InsertShippingMethod(sm); SaveStoreMappings(sm, model.SelectedStoreIds); UpdateLocales(sm, model); NotifySuccess(T("Admin.Configuration.Shipping.Methods.Added")); return(continueEditing ? RedirectToAction("EditMethod", new { id = sm.Id }) : RedirectToAction("Methods")); } return(View(model)); }
public ActionResult CanPrint(string templateName, string number) { ResponseResult result = new ResponseResult(); try { //model = GetQuickPrintModel(templateName, number); //string cacheId = SaveObjectToCache(model); if (GetCanPrint(templateName, number)) { result.Result = true; result.Message = ""; //cacheId; } else //如果不能打印,返回详情 { GetQuickPrintModel(templateName, number); } var wayBillInfo = _wayBillInfoRepository.GetWayBill(number); var shippingMethodList = _freightService.GetShippingMethods(null, false); WayBillTemplateExt wayBillTemplate = new WayBillTemplateExt(); ShippingMethodModel shipp = new ShippingMethodModel(); if (wayBillInfo != null) { wayBillTemplate = _wayBillTemplateService.GetWayBillTemplate(wayBillInfo.InShippingMethodID ?? 0, templateName); shipp = shippingMethodList.FirstOrDefault(z => z.ShippingMethodId == wayBillInfo.InShippingMethodID); } if (shipp != null && wayBillTemplate != null && wayBillTemplate.TemplateTypeId == "DT1308100021" && (shipp.Code == "CNPOST-GZ" || shipp.Code == "CNPOSTP-GZ")) { var gzPacketAddress = _wayBillTemplateService.GetGZPacketAddressInfo().FirstOrDefault(); if (gzPacketAddress == null) { result.Result = false; result.Message = "广州小包发货地址不足"; } } } catch (Exception ex) { result.Message = ex.Message; return(Json(result, JsonRequestBehavior.AllowGet)); } return(Json(result, JsonRequestBehavior.AllowGet)); }
public IActionResult ShippingInfo() { if (!CanCheckout(out Cart cart)) { return(RedirectToRoute(RouteNames.Home)); } //is shipping required? var shippingRequired = CartHelper.IsShippingRequired(cart); if (!shippingRequired) { return(RedirectToRoute(RouteNames.CheckoutPayment)); } if (cart.BillingAddressId == 0 || cart.ShippingAddressId == 0) { return(R.Fail.With("error", T("The address details were not provided")).Result); } //find available shipping methods var shippingHandlers = _pluginAccountant.GetActivePlugins(typeof(IShipmentHandlerPlugin)) .Where(x => x.LoadPluginInstance <IShipmentHandlerPlugin>().IsMethodAvailable(cart)).ToList(); if (!shippingHandlers.Any()) { cart.ShippingMethodName = ApplicationConfig.UnavailableMethodName; _cartService.Update(cart); //there are no shipping handlers, may be it's being manually handled by store owner return(RedirectToRoute(RouteNames.CheckoutPayment)); } var shippingModels = shippingHandlers.Select(x => { var model = new ShippingMethodModel() { SystemName = x.SystemName, Description = x.Description, FriendlyName = x.Name }; return(model); }) .ToList(); return(R.Success .With("shippingMethods", shippingModels) .With("shippingRequired", true) .Result); }
public void MapToShippingInfoArgument_ValidInputObjectWithLineIdsNotEmpty_ObjectIsMappedCorrectly() { // Setup var input = new ShippingMethodModel { LineIds = new List <string>() { "1", "2" } }; // Execute var addressPartyMapper = new EntityMapper(); var result = addressPartyMapper.MapToShippingInfoArgument(input); // Assert Assert.NotNull(result); Assert.Equal(2, result.LineIds.Count); }
/// <summary> /// Processes the arguments. /// </summary> /// <param name="args">The pipeline arguments.</param> public override void Process(ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(args.Request, "args.Request"); Assert.ArgumentNotNull(args.Result, "args.Result"); Assert.ArgumentCondition(args.Request is AddShippingInfoRequest, "args.Request", "args.Request is AddShippingInfoRequest"); Assert.ArgumentCondition(args.Result is AddShippingInfoResult, "args.Result", "args.Result is AddShippingInfoResult"); var request = (AddShippingInfoRequest)args.Request; var result = (AddShippingInfoResult)args.Result; var resultShipping = new List <ShippingInfo>(); var shippingInfo = request.ShippingInfo.FirstOrDefault(); if (shippingInfo != null) { Guid customerId; if (Guid.TryParse(request.Cart.ExternalId, out customerId)) { var model = new ShippingMethodModel { SystemName = shippingInfo.ShippingProviderID, Name = shippingInfo.ShippingMethodID }; using (var client = this.GetClient()) { var responseModel = client.AddShippingInfo(customerId, model, request.Cart.ShopName); if (responseModel.Success) { resultShipping.Add(shippingInfo); } } } request.Cart.Shipping = resultShipping.AsReadOnly(); result.ShippingInfo = resultShipping; result.Cart = request.Cart; } }
public async Task <IActionResult> EditMethod(ShippingMethodModel model, bool continueEditing) { var sm = await _shippingMethodService.GetShippingMethodById(model.Id); if (sm == null) { //No shipping method found with the specified id return(RedirectToAction("Methods")); } if (ModelState.IsValid) { sm = model.ToEntity(sm); await _shippingMethodService.UpdateShippingMethod(sm); SuccessNotification(_localizationService.GetResource("Admin.Configuration.Shipping.Methods.Updated")); return(continueEditing ? RedirectToAction("EditMethod", new { id = sm.Id }) : RedirectToAction("Methods")); } //If we got this far, something failed, redisplay form return(View(model)); }
public void MapToShippingInfoArgument_ValidInputObject_ObjectIsMappedCorrectly() { // Setup var input = new ShippingMethodModel { PartyId = "partyId", LineIds = null, ShippingPreferenceType = ShippingOptionType.ElectronicDelivery.Value.ToString() }; // Execute var addressPartyMapper = new EntityMapper(); var result = addressPartyMapper.MapToShippingInfoArgument(input); // Assert Assert.NotNull(result); Assert.Equal("partyId", result.PartyId); Assert.Empty(result.LineIds); Assert.Equal(ShippingOptionType.ElectronicDelivery.Value, result.ShippingPreferenceType.Value); Assert.Equal(ShippingOptionType.ElectronicDelivery.Name, result.ShippingPreferenceType.Name); }
public ActionResult CreateMethod(ShippingMethodModel model, bool continueEditing) { if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var sm = model.ToEntity(); _shippingService.InsertShippingMethod(sm); UpdateLocales(sm, model); NotifySuccess(_services.Localization.GetResource("Admin.Configuration.Shipping.Methods.Added")); return(continueEditing ? RedirectToAction("EditMethod", new { id = sm.Id }) : RedirectToAction("Methods")); } //If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult CreateMethod(ShippingMethodModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) return AccessDeniedView(); if (ModelState.IsValid) { var sm = model.ToEntity(); _shippingService.InsertShippingMethod(sm); //locales UpdateLocales(sm, model); SuccessNotification(_localizationService.GetResource("Admin.Configuration.Shipping.Methods.Added")); return continueEditing ? RedirectToAction("EditMethod", new { id = sm.Id }) : RedirectToAction("Methods"); } //If we got this far, something failed, redisplay form return View(model); }
public ActionResult EditMethod(ShippingMethodModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) return AccessDeniedView(); var sm = _shippingService.GetShippingMethodById(model.Id); if (sm == null) //No shipping method found with the specified id return RedirectToAction("Methods"); if (ModelState.IsValid) { sm = model.ToEntity(sm); _shippingService.UpdateShippingMethod(sm); //locales UpdateLocales(sm, model); SuccessNotification(_localizationService.GetResource("Admin.Configuration.Shipping.Methods.Updated")); return continueEditing ? RedirectToAction("EditMethod", sm.Id) : RedirectToAction("Methods"); } //If we got this far, something failed, redisplay form return View(model); }
public static ShippingMethod ToEntity(this ShippingMethodModel model) { return(model.MapTo <ShippingMethodModel, ShippingMethod>()); }
public static ShippingMethod ToEntity(this ShippingMethodModel model, ShippingMethod destination) { return(model.MapTo(destination)); }
public ActionResult EditMethod(ShippingMethodModel model, bool continueEditing, FormCollection form) { if (!_services.Permissions.Authorize(StandardPermissionProvider.ManageShippingSettings)) return AccessDeniedView(); var sm = _shippingService.GetShippingMethodById(model.Id); if (sm == null) return RedirectToAction("Methods"); if (ModelState.IsValid) { sm = model.ToEntity(sm); _shippingService.UpdateShippingMethod(sm); UpdateLocales(sm, model); _services.EventPublisher.Publish(new ModelBoundEvent(model, sm, form)); NotifySuccess(T("Admin.Configuration.Shipping.Methods.Updated")); return continueEditing ? RedirectToAction("EditMethod", sm.Id) : RedirectToAction("Methods"); } return View(model); }
protected virtual List<LocalizedProperty> UpdateLocales(ShippingMethod shippingMethod, ShippingMethodModel model) { List<LocalizedProperty> localized = new List<LocalizedProperty>(); foreach (var local in model.Locales) { localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "Name", LocaleValue = local.Name }); localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "Description", LocaleValue = local.Description }); } return localized; }
/// <summary> /// Gets all shipping methods. /// </summary> /// <param name="cart">The cart.</param> /// <param name="methodIds">The method ids.</param> /// <returns>shipping method model</returns> public static ShippingMethodModel[] GetShippingMethods(this CartHelper cart, List<string> methodIds = null) { var list = new List<ShippingMethodModel>(); methodIds = methodIds ?? new List<string>(); IEnumerable<ShippingMethod> shippingMethods; if (methodIds.Any()) { shippingMethods = cart.ShippingClient.GetAllShippingMethods().Where(so => methodIds.Contains(so.ShippingMethodId)); } else { var options = cart.ShippingClient.GetAllShippingOptions(); shippingMethods = options.SelectMany(o => o.ShippingMethods.Where(m => m.IsActive)); } var address = cart.FindAddressByName("Shipping") ?? cart.FindAddressByName("Billing"); foreach (var method in shippingMethods.Where(m => m.IsActive && (string.IsNullOrEmpty(m.Currency) || m.Currency.Equals(UserHelper.CustomerSession.Currency, StringComparison.OrdinalIgnoreCase)))) { var model = new ShippingMethodModel(method, cart.Cart); //Filter by shipping method jurisdiction var jurisdictionRelations = method.ShippingMethodJurisdictionGroups.SelectMany(g => g.JurisdictionGroup.JurisdictionRelations).ToArray(); if (jurisdictionRelations.Any()) { var jurisdictionFound = false; if (address != null) { jurisdictionFound = jurisdictionRelations.Any(j => j.Jurisdiction.CheckAllFieldsMatch( address.CountryCode, address.StateProvince, address.PostalCode, address.RegionName, "", "", address.City)); } if (!jurisdictionFound) continue; } if (!string.IsNullOrWhiteSpace(method.RestrictJurisdictionGroups)) { var jurisdictionFound = false; if (address != null) { var ids = method.RestrictJurisdictionGroups.Split(new[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries); var jurisdictions = cart.OrderRepository.JurisdictionGroups.Where(x => ids.Contains(x.JurisdictionGroupId)) .SelectMany(x => x.JurisdictionRelations).Select(x => x.Jurisdiction).ToArray(); jurisdictionFound = jurisdictions.Any(j => j.CheckAllFieldsMatch(address.CountryCode, address.StateProvince, address.PostalCode, address.RegionName, "", "", address.City)); } //If found any match in restrcitions cannot use this shipping method if (jurisdictionFound) continue; } methodIds.Add(method.ShippingMethodId); list.Add(model); } var rates = GetAllShippingRates(cart, methodIds.ToArray(), cart.LineItems); if (rates != null) { foreach (var sm in list) { sm.Rate = (from r in rates where r.Id == sm.Id select r).SingleOrDefault(); } } return list.ToArray(); }
private void PrepareShippingMethodModel(ShippingMethodModel model, ShippingMethod shippingMethod) { var allFilters = _shippingService.GetAllShippingMethodFilters(); if (shippingMethod != null) { model.FilterConfigurationUrls = allFilters .Select(x => "'" + x.GetConfigurationUrl(shippingMethod.Id) + "'") .OrderBy(x => x) .ToList(); } else { model.FilterConfigurationUrls = new List<string>(); } }
public static ShippingMethod ToEntity(this ShippingMethodModel model, ShippingMethod destination) { return(Mapper.Map(model, destination)); }
public static ShippingMethod ToEntity(this ShippingMethodModel model) { return(Mapper.Map <ShippingMethodModel, ShippingMethod>(model)); }
/// <summary> /// Gets all shipping methods. /// </summary> /// <param name="cart">The cart.</param> /// <param name="methodIds">The method ids.</param> /// <returns>shipping method model</returns> public static ShippingMethodModel[] GetShippingMethods(this CartHelper cart, List<string> methodIds = null) { var list = new List<ShippingMethodModel>(); methodIds = methodIds ?? new List<string>(); IEnumerable<ShippingMethod> shippingMethods; if (methodIds.Any()) { shippingMethods = cart.ShippingClient.GetAllShippingMethods().Where(so => methodIds.Contains(so.ShippingMethodId)); } else { var options = cart.ShippingClient.GetAllShippingOptions(); shippingMethods = options.SelectMany(o => o.ShippingMethods.Where(m => m.IsActive)); } foreach (var method in shippingMethods.Where(m => m.IsActive)) { var model = new ShippingMethodModel(method, cart.Cart); methodIds.Add(method.ShippingMethodId); list.Add(model); } var rates = GetAllShippingRates(cart, methodIds.ToArray(), cart.LineItems); if (rates != null) { foreach (var sm in list) { sm.Rate = (from r in rates where r.Id == sm.Id select r).SingleOrDefault(); } } return list.ToArray(); }
private void ApplyRestrictions(ShippingMethod shippingMethod, ShippingMethodModel model) { var countries = _countryService.GetAllCountries(true); shippingMethod.ExcludedCustomerRoleIds = Request.Form["ExcludedCustomerRoleIds"]; shippingMethod.CountryExclusionContext = model.CountryExclusionContext; string[] excludedCountryIds = Request.Form["ExcludedCountryIds"].SplitSafe(","); foreach (var country in countries) { if (excludedCountryIds.Contains(country.Id.ToString())) { if (shippingMethod.RestrictedCountries.Where(c => c.Id == country.Id).FirstOrDefault() == null) { shippingMethod.RestrictedCountries.Add(country); _shippingService.UpdateShippingMethod(shippingMethod); } } else { if (shippingMethod.RestrictedCountries.Where(c => c.Id == country.Id).FirstOrDefault() != null) { shippingMethod.RestrictedCountries.Remove(country); _shippingService.UpdateShippingMethod(shippingMethod); } } } }
private void PrepareShippingMethodModel(ShippingMethodModel model, ShippingMethod shippingMethod) { var customerRoles = _customerService.GetAllCustomerRoles(true); var countries = _countryService.GetAllCountries(true); model.AvailableCustomerRoles = new List<SelectListItem>(); model.AvailableCountries = new List<SelectListItem>(); model.AvailableCountryExclusionContextTypes = CountryRestrictionContextType.BillingAddress.ToSelectList(false).ToList(); foreach (var role in customerRoles.OrderBy(x => x.Name)) { model.AvailableCustomerRoles.Add(new SelectListItem { Text = role.Name, Value = role.Id.ToString() }); } foreach (var country in countries.OrderBy(x => x.Name)) { model.AvailableCountries.Add(new SelectListItem { Text = country.GetLocalized(x => x.Name), Value = country.Id.ToString() }); } if (shippingMethod != null) { model.ExcludedCustomerRoleIds = shippingMethod.ExcludedCustomerRoleIds.SplitSafe(","); model.ExcludedCountryIds = shippingMethod.RestrictedCountries.Select(x => x.Id.ToString()).ToArray(); model.CountryExclusionContext = shippingMethod.CountryExclusionContext; } }