コード例 #1
0
        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());
        }
コード例 #2
0
        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());
        }