public async Task <IActionResult> Settings(ShippingSettingsModel model,
                                                   [FromServices] ICustomerActivityService customerActivityService)
        {
            //load settings for a chosen store scope
            var storeScope = await GetActiveStore(_storeService, _workContext);

            var shippingSettings = _settingService.LoadSetting <ShippingSettings>(storeScope);

            shippingSettings = model.ToEntity(shippingSettings);

            await _settingService.SaveSetting(shippingSettings, storeScope);

            //activity log
            await customerActivityService.InsertActivity("EditSettings", "", _translationService.GetResource("ActivityLog.EditSettings"));

            Success(_translationService.GetResource("Admin.Configuration.Updated"));
            return(RedirectToAction("Settings"));
        }
 public static ShippingSettings ToEntity(this ShippingSettingsModel model, ShippingSettings destination)
 {
     return(model.MapTo(destination));
 }
示例#3
0
 public static ShippingSettings ToEntity(this ShippingSettingsModel model, ShippingSettings destination)
 {
     return(Mapper.Map(model, destination));
 }
示例#4
0
 public static ShippingSettings ToEntity(this ShippingSettingsModel model)
 {
     return(Mapper.Map <ShippingSettingsModel, ShippingSettings>(model));
 }
示例#5
0
 public static ShippingSettings ToEntity(this ShippingSettingsModel model, ShippingSettings entity)
 {
     MapperFactory.Map(model, entity);
     return(entity);
 }
示例#6
0
        public async Task <IActionResult> Shipping(int storeScope, ShippingSettings settings, ShippingSettingsModel model)
        {
            var form = Request.Form;

            // Note, model state is invalid here due to ShippingOriginAddress validation.
            await MapperFactory.MapAsync(model, settings);

            await _storeDependingSettingHelper.UpdateSettingsAsync(settings, form, storeScope, propertyName =>
            {
                // Skip to prevent the address from being recreated every time you save.
                if (propertyName.EqualsNoCase(nameof(settings.ShippingOriginAddressId)))
                {
                    return(null);
                }

                return(propertyName);
            });

            // Special case ShippingOriginAddressId\ShippingOriginAddress.
            if (storeScope == 0 || _storeDependingSettingHelper.IsOverrideChecked(settings, "ShippingOriginAddress", form))
            {
                var addressId = await Services.Settings.SettingExistsAsync(settings, x => x.ShippingOriginAddressId, storeScope) ? settings.ShippingOriginAddressId : 0;

                var originAddress = await _db.Addresses.FindByIdAsync(addressId) ?? new Address
                {
                    CreatedOnUtc = DateTime.UtcNow
                };

                // Update ID manually (in case we're in multi-store configuration mode it'll be set to the shared one).
                model.ShippingOriginAddress.Id = originAddress.Id == 0 ? 0 : addressId;
                await MapperFactory.MapAsync(model.ShippingOriginAddress, originAddress);

                if (originAddress.Id == 0)
                {
                    _db.Addresses.Add(originAddress);
                    await _db.SaveChangesAsync();
                }

                settings.ShippingOriginAddressId = originAddress.Id;
                await Services.Settings.ApplySettingAsync(settings, x => x.ShippingOriginAddressId, storeScope);
            }
            else
            {
                _db.Addresses.Remove(settings.ShippingOriginAddressId);
                await Services.Settings.RemoveSettingAsync(settings, x => x.ShippingOriginAddressId, storeScope);
            }

            await _db.SaveChangesAsync();

            return(NotifyAndRedirect("Shipping"));
        }