/// <returns>A task that represents the asynchronous operation</returns> public virtual async Task <IActionResult> MethodRestrictionsSave(PaymentMethodsModel model, IFormCollection form) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManagePaymentMethods)) { return(AccessDeniedView()); } var paymentMethods = await _paymentPluginManager.LoadAllPluginsAsync(); var countries = await _countryService.GetAllCountriesAsync(showHidden : true); foreach (var pm in paymentMethods) { var formKey = "restrict_" + pm.PluginDescriptor.SystemName; var countryIdsToRestrict = (!StringValues.IsNullOrEmpty(form[formKey]) ? form[formKey].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List <string>()) .Select(x => Convert.ToInt32(x)).ToList(); var newCountryIds = new List <int>(); foreach (var c in countries) { if (countryIdsToRestrict.Contains(c.Id)) { newCountryIds.Add(c.Id); } } await _paymentPluginManager.SaveRestrictedCountriesAsync(pm, newCountryIds); } _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Configuration.Payment.MethodRestrictions.Updated")); return(RedirectToAction("MethodRestrictions")); }
public ActionResult PaymentMethodEdit(PaymentMethodsModel model) { if (ModelState.IsValid) { _servicePaymentMethods.Update(model.ModelToEnity(true)); } return(RedirectToAction("PaymentMethodList")); }
/// <summary> /// Prepare payment methods model /// </summary> /// <param name="methodsModel">Payment methods model</param> /// <returns>Payment methods model</returns> public virtual PaymentMethodsModel PreparePaymentMethodsModel(PaymentMethodsModel methodsModel) { if (methodsModel == null) { throw new ArgumentNullException(nameof(methodsModel)); } //prepare nested search models PreparePaymentMethodSearchModel(methodsModel.PaymentsMethod); PreparePaymentMethodRestrictionModel(methodsModel.PaymentMethodRestriction); return(methodsModel); }
public static PaymentMethods ModelToEnity(this PaymentMethodsModel model, bool virtualActive = false) { PaymentMethods entity = new PaymentMethods() { Name = model.Name, Id = model.Id, IsActive = model.IsActive }; if (virtualActive) { entity.Sales = model.Sales; } return(entity); }
public static PaymentMethodsModel EntityToModel(this PaymentMethods entity, bool virtualActive = false) { try { PaymentMethodsModel model = new PaymentMethodsModel() { Name = entity.Name, IsActive = entity.IsActive, Id = entity.Id }; if (virtualActive) { model.Sales = entity.Sales; } return(model); } catch (Exception) { return(new PaymentMethodsModel()); } }
public virtual IActionResult MethodRestrictionsSave(PaymentMethodsModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManagePaymentMethods)) { return(AccessDeniedView()); } var paymentMethods = _paymentService.LoadAllPaymentMethods(); var countries = _countryService.GetAllCountries(showHidden: true); foreach (var pm in paymentMethods) { var formKey = "restrict_" + pm.PluginDescriptor.SystemName; var countryIdsToRestrict = (!StringValues.IsNullOrEmpty(model.Form[formKey]) ? model.Form[formKey].ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List <string>()) .Select(x => Convert.ToInt32(x)).ToList(); var newCountryIds = new List <int>(); foreach (var c in countries) { if (countryIdsToRestrict.Contains(c.Id)) { newCountryIds.Add(c.Id); } } _paymentService.SaveRestictedCountryIds(pm, newCountryIds); } SuccessNotification(_localizationService.GetResource("Admin.Configuration.Payment.MethodRestrictions.Updated")); //selected tab SaveSelectedTabName(); return(RedirectToAction("PaymentMethods")); }
/// <summary> /// Prepare payment methods model /// </summary> /// <param name="methodsModel">Payment methods model</param> /// <returns>Payment methods model</returns> public virtual async Task <PaymentMethodsModel> PreparePaymentMethodsModelAsync(PaymentMethodsModel methodsModel) { if (methodsModel == null) { throw new ArgumentNullException(nameof(methodsModel)); } //prepare nested search models await PreparePaymentMethodSearchModelAsync(methodsModel.PaymentsMethod); await PreparePaymentMethodRestrictionModelAsync(methodsModel.PaymentMethodRestriction); return(methodsModel); }