public void ChangeApplicationSetting(ApplicationSettingPreset applicationSettingPreset)
        {
            var index = _applicationSettingPresets.FindIndex(x => x.ApplicationSettingId == applicationSettingPreset.ApplicationSettingId);

            _applicationSettingPresets[index].SetSettingPresetValue(applicationSettingPreset.Value);
            _applicationSettingPresets[index].SetIsHidden(applicationSettingPreset.IsHidden);
            _applicationSettingPresets[index].SetIsReadOnly(applicationSettingPreset.IsReadOnly);
            _applicationSettingPresets[index].SetIsRequired(applicationSettingPreset.IsRequired);
        }
        public void AddApplicationSettingPreset(ApplicationSettingPreset applicationSettingPreset)
        {
            if (_applicationSettingPresets.Any(x => x.ApplicationSettingId == applicationSettingPreset.ApplicationSettingId))
            {
                throw new InvariantViolationException(
                          ValidationMessage.AlreadyExists($"Application setting [id:{applicationSettingPreset.ApplicationSettingId}]"));
            }

            _applicationSettingPresets.Add(applicationSettingPreset);
        }
        public async Task <IActionResult> Add([FromBody] SettingsPresetDto settingsPresetDto)
        {
            SettingsPreset settingPreset = new SettingsPreset(settingsPresetDto.Name);

            foreach (var billingSettingPresetDto in settingsPresetDto.BillingSettingPresets)
            {
                SettingPresetValue settingPresetValue = new SettingPresetValue(
                    billingSettingPresetDto.Value.DefaultValue,
                    billingSettingPresetDto.Value.MinValue,
                    billingSettingPresetDto.Value.MaxValue
                    );
                BillingSettingPreset billingSettingPreset = new BillingSettingPreset(
                    billingSettingPresetDto.SettingsPresetId,
                    billingSettingPresetDto.BillingSettingId,
                    settingPresetValue,
                    billingSettingPresetDto.IsRequired,
                    billingSettingPresetDto.IsReadOnly,
                    billingSettingPresetDto.IsHidden
                    );
                settingPreset.AddBillingSettingPreset(billingSettingPreset);
            }

            foreach (var ApplicationSettingPresetDto in settingsPresetDto.ApplicationSettingPresets)
            {
                SettingPresetValue settingPresetValue = new SettingPresetValue(
                    ApplicationSettingPresetDto.Value.DefaultValue,
                    ApplicationSettingPresetDto.Value.MinValue,
                    ApplicationSettingPresetDto.Value.MaxValue
                    );
                ApplicationSettingPreset applicationSettingPreset = new ApplicationSettingPreset(
                    ApplicationSettingPresetDto.SettingsPresetId,
                    ApplicationSettingPresetDto.ApplicationSettingId,
                    settingPresetValue,
                    ApplicationSettingPresetDto.IsRequired,
                    ApplicationSettingPresetDto.IsReadOnly,
                    ApplicationSettingPresetDto.IsHidden
                    );
                settingPreset.AddApplicationSettingPreset(applicationSettingPreset);
            }

            await settingsPresetRepository.Add(settingPreset);

            await unitOfWork.SaveEntitiesAsync();

            return(Ok());
        }
예제 #4
0
 public static ApplicationSettingPresetDto Map(this ApplicationSettingPreset applicationSettingPreset)
 {
     if (applicationSettingPreset == null)
     {
         return(null);
     }
     else
     {
         return(new ApplicationSettingPresetDto
         {
             Id = applicationSettingPreset.Id,
             ApplicationSettingId = applicationSettingPreset.ApplicationSettingId,
             ApplicationSetting = applicationSettingPreset.ApplicationSetting.Map(),
             IsHidden = applicationSettingPreset.IsHidden,
             IsReadOnly = applicationSettingPreset.IsReadOnly,
             IsRequired = applicationSettingPreset.IsRequired,
             SettingsPresetId = applicationSettingPreset.SettingsPresetId,
             Value = applicationSettingPreset.Value.Map()
         });
     }
 }
        public async Task <IActionResult> Update([FromBody] SettingsPresetDto settingsPresetDto)
        {
            SettingsPreset settingsPreset = await settingsPresetRepository.GetSettingsPreset(settingsPresetDto.Id);

            settingsPreset.SetName(settingsPresetDto.Name);
            settingsPreset.RemoveApplicationSettingsPresets(settingsPresetDto.ApplicationSettingPresets.Select(x => x.ApplicationSettingId).ToList());
            settingsPreset.RemoveBillingSettingPresets(settingsPresetDto.BillingSettingPresets.Select(x => x.BillingSettingId).ToList());
            foreach (var item in settingsPresetDto.ApplicationSettingPresets)
            {
                SettingPresetValue settingPresetValue = new SettingPresetValue(
                    item.Value.DefaultValue,
                    item.Value.MinValue,
                    item.Value.MaxValue
                    );
                ApplicationSettingPreset applicationSettingPreset = new ApplicationSettingPreset(
                    item.SettingsPresetId,
                    item.ApplicationSettingId,
                    settingPresetValue,
                    item.IsRequired,
                    item.IsReadOnly,
                    item.IsHidden
                    );

                if (settingsPreset.ApplicationSettingPresets.Select(x => x.ApplicationSettingId).Contains(item.ApplicationSettingId))
                {
                    settingsPreset.ChangeApplicationSetting(applicationSettingPreset);
                }
                else
                {
                    settingsPreset.AddApplicationSettingPreset(applicationSettingPreset);
                }
            }

            foreach (var item in settingsPresetDto.BillingSettingPresets)
            {
                SettingPresetValue settingPresetValue = new SettingPresetValue(
                    item.Value.DefaultValue,
                    item.Value.MinValue,
                    item.Value.MaxValue
                    );
                BillingSettingPreset billingSettingPreset = new BillingSettingPreset(
                    item.SettingsPresetId,
                    item.BillingSettingId,
                    settingPresetValue,
                    item.IsRequired,
                    item.IsReadOnly,
                    item.IsHidden
                    );

                if (settingsPreset.BillingSettingPresets.Select(x => x.BillingSettingId).Contains(item.BillingSettingId))
                {
                    settingsPreset.ChangeBillingSettingPreset(billingSettingPreset);
                }
                else
                {
                    settingsPreset.AddBillingSettingPreset(billingSettingPreset);
                }
            }

            await settingsPresetRepository.Update(settingsPreset);

            await unitOfWork.SaveEntitiesAsync();

            return(Ok());
        }