/// <summary>
        /// Gets the settings definitions by names
        /// </summary>
        /// <param name="settingNames"></param>
        /// <returns></returns>
        public async Task <SettingsOutput> GetSettingsOptions(params string[] settingNames)
        {
            var settings     = _definitionManager.GetAllSettingDefinitions().Where(a => a.Scopes != SettingScopes.User).ToList();
            var settingsList = new List <SettingInputDto>();
            var output       = new SettingsOutput();

            foreach (var settingName in settingNames)
            {
                var settingDefinition = settings.FirstOrDefault(a => a.Name == settingName);
                if (settingDefinition == null)
                {
                    continue;
                }
                var value = await _settingManager.GetSettingValueAsync(settingDefinition.Name);

                var setting = new SettingInputDto()
                {
                    Key                                               = settingDefinition.Name,
                    DisplayName                                       = settingDefinition.DisplayName != null?settingDefinition.DisplayName.Localize(_localizationContext) : settingDefinition.Name,
                                                         Value        = value,
                                                         DefaultValue = settingDefinition.DefaultValue,
                                                         Description  = settingDefinition.Description != null?settingDefinition.Description.Localize(_localizationContext) : "",
                                                                            SettingScopes = settingDefinition.Scopes
                };
                settingsList.Add(setting);
            }
            output.Settings = settingsList;
            return(output);
        }
        public async Task EditSetting(SettingInputDto input)
        {
            switch (input.SettingScopes)
            {
            case SettingScopes.Application:
                await _settingManager.ChangeSettingForApplicationAsync(input.Key, input.Value);

                break;

            case SettingScopes.Application | SettingScopes.User | SettingScopes.Tenant:
                await _settingManager.ChangeSettingForApplicationAsync(input.Key, input.Value);

                break;

            case SettingScopes.Application | SettingScopes.Tenant:
                await _settingManager.ChangeSettingForApplicationAsync(input.Key, input.Value);

                break;

            case SettingScopes.Tenant:

                break;

            case SettingScopes.User:
                if (AbpSession.UserId != null)
                {
                    await _settingManager.ChangeSettingForUserAsync(AbpSession.UserId.Value, input.Key, input.Value);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            await _settingsAppNotifications.SendSettingsChangedNotification(AbpSession.TenantId, await GetCurrentUserAsync());
        }
Esempio n. 3
0
        public void UpdateSetting()
        {
            var getSetting = Utils.GetWebApiData("FinanceWebApi", SettingUrl);

            Task.WaitAll(getSetting);
            var response        = JsonConvert.DeserializeObject <Response>(getSetting.Result);
            var serializedStats = JsonConvert.SerializeObject(response.stats);

            var responsePayload   = JsonConvert.DeserializeObject <Response>(getSetting.Result);
            var serializedPayload = JsonConvert.SerializeObject(responsePayload.payload);
            var resultSettings    = JsonConvert.DeserializeObject <List <object> >(serializedPayload);

            // Get SettingId
            JObject settingRes        = (JObject)resultSettings[0];
            var     settingProperties = settingRes.Properties();
            var     settingId         = (int)settingProperties.Where(x => x.Name == "id").FirstOrDefault().Value;

            var payload = new SettingInputDto
            {
                Id             = settingId,
                CurrencyCode   = "CAD",
                TaxMethodology = "MINTAX",
                FiscalMonth    = "January",
                FiscalDay      = 4
            };

            var createSetting = Utils.PutWebApi("FinanceWebApi", $"{SettingUrl}", payload);

            Task.WaitAll(createSetting);

            var resultSetting = JsonConvert.DeserializeObject <Response>(createSetting.Result);

            Assert.IsTrue(resultSetting.isSuccessful == true, "Settings Updated");
        }
Esempio n. 4
0
        public void CreateSetting()
        {
            var payload = new SettingInputDto
            {
                CurrencyCode   = "USD",
                TaxMethodology = "MINTAX",
                FiscalMonth    = "February",
                FiscalDay      = 4
            };

            var Invalidpayload = new SettingInputDto
            {
                CurrencyCode   = "",
                TaxMethodology = "MINTAX",
                FiscalMonth    = "February",
                FiscalDay      = 4
            };

            var createSetting = Utils.PostWebApi("FinanceWebApi", $"{SettingUrl}", payload);

            Task.WaitAll(createSetting);

            var resultSetting = JsonConvert.DeserializeObject <Response>(createSetting.Result);

            Assert.IsTrue(resultSetting.isSuccessful == true, "Settings Added");

            //For Invalid Payload
            var createSettingI = Utils.PostWebApi("FinanceWebApi", $"{SettingUrl}", Invalidpayload);

            Task.WaitAll(createSettingI);

            var resultSettingI = JsonConvert.DeserializeObject <Response>(createSettingI.Result);

            Assert.IsTrue(!resultSettingI.isSuccessful, "Expected Result");
        }
        public async Task CreateEditSetting_Test()
        {
            LoginAsHostAdmin();

            var settingInputDto = new SettingInputDto()
            {
                Key           = "Theme",
                Value         = "smart-style-0",
                SettingScopes = SettingScopes.User
            };

            await _settingsAppService.CreateEditSetting(new List <SettingInputDto>() { settingInputDto });
        }
        public object UpdateSetting(SettingInputDto setting)
        {
            SqlHelper sqlHelper = new SqlHelper(connectionString);

            try
            {
                sqlHelper.VerifyConnection();

                var lastUpdatedDate = DateTime.Now.ToString("MM-dd-yyyy");
                var createdBy       = "John Doe";

                List <SqlParameter> settingParameters = new List <SqlParameter>
                {
                    new SqlParameter("id", setting.Id),
                    new SqlParameter("createdBy", createdBy),
                    new SqlParameter("lastUpdatedBy", createdBy),
                    new SqlParameter("lastUpdatedDate", lastUpdatedDate),
                    new SqlParameter("currencyCode", setting.CurrencyCode),
                    new SqlParameter("taxMethodology", setting.TaxMethodology),
                    new SqlParameter("fiscalMonth", setting.FiscalMonth),
                    new SqlParameter("fiscalDay", setting.FiscalDay),
                };

                var settingQuery = $@"UPDATE [settings]
                            SET
                            [created_by] = @createdBy
                            ,[last_updated_by] = @createdBy
                            ,[last_updated_date] = @lastUpdatedDate
                            ,[currency_code] = @currencyCode
                            ,[tax_methodology] = @taxMethodology
                            ,[fiscal_month] = @fiscalMonth
                            ,[fiscal_day] = @fiscalDay
                            WHERE [settings].[id] = @id";

                sqlHelper.Update(settingQuery, CommandType.Text, settingParameters.ToArray());
                sqlHelper.CloseConnection();


                return(Utils.Wrap(true, null, HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                sqlHelper.CloseConnection();

                return(Utils.Wrap(false));
            }
        }
Esempio n. 7
0
        public async Task <AjaxResult> Update(SettingInputDto dto)
        {
            Check.NotNull(dto, nameof(dto));

            Type type = Type.GetType(dto.SettingTypeName);

            if (type == null)
            {
                return(new AjaxResult($"设置类型\"{dto.SettingTypeName}\"无法找到"));
            }
            ISetting        setting = JsonConvert.DeserializeObject(dto.SettingJson, type) as ISetting;
            OperationResult result  = await _keyValueStore.SaveSetting(setting);

            if (result.Succeeded)
            {
                return(new AjaxResult("设置保存成功"));
            }
            return(result.ToAjaxResult());
        }
        public object AddSetting(SettingInputDto setting)
        {
            SqlHelper sqlHelper = new SqlHelper(connectionString);

            try
            {
                sqlHelper.VerifyConnection();

                var createdDate = DateTime.Now.ToString("MM-dd-yyyy");
                var createdBy   = "John Doe";

                List <SqlParameter> settingParameters = new List <SqlParameter>
                {
                    new SqlParameter("createdBy", createdBy),
                    new SqlParameter("createdDate", createdDate),
                    new SqlParameter("lastUpdatedDate", createdDate),
                    new SqlParameter("currencyCode", setting.CurrencyCode),
                    new SqlParameter("taxMethodology", setting.TaxMethodology),
                    new SqlParameter("fiscalMonth", setting.FiscalMonth),
                    new SqlParameter("fiscalDay", setting.FiscalDay),
                };

                var query = $@"INSERT INTO [settings]
                                    ([created_by], [created_date], [last_updated_date], [currency_code], [tax_methodology], [fiscal_month]
                                    ,[fiscal_day])
                                    VALUES
                                    (@createdBy, @createdDate, @lastUpdatedDate, @currencyCode, @taxMethodology, @fiscalMonth
                                    ,@fiscalDay)";

                sqlHelper.Insert(query, CommandType.Text, settingParameters.ToArray());
                sqlHelper.CloseConnection();

                return(Utils.Wrap(true, null, HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                sqlHelper.CloseConnection();

                return(Utils.Wrap(false));
            }
        }
 public object UpdateSetting([FromBody] SettingInputDto setting)
 {
     return(!ModelState.IsValid || setting == null?BadRequest(ModelState) : controller.UpdateSetting(setting));
 }