Ejemplo n.º 1
0
        public static async Task <SettingServer> GetValueSettingApi(IConfiguration _config, string _atUserToken)
        {
            List <Settings_GetAllSettingsOutput> settingOutPut = new List <Settings_GetAllSettingsOutput>();
            var client  = new RestClient(_config["UrlApi"]);
            var request = new RestRequest("api/Settings", Method.GET);

            request.AddHeader("AtUserToken", _atUserToken);
            var response = await client.ExecuteGetTaskAsync <AtResult <List <Settings_GetAllSettingsOutput> > >(request);

            settingOutPut = response.Data.PayLoad;
            SettingServer serverSetting = SettingServer.ReadServerOptionAsync(settingOutPut);

            return(serverSetting);
        }
Ejemplo n.º 2
0
        public static SettingServer ReadServerOptionAsync(List <Settings_GetAllSettingsOutput> lsSetting)
        {
            SettingServer serverSetting = new SettingServer();

            try
            {
                Settings_GetAllSettingsOutput setting;
                foreach (var prop in typeof(SettingServer).GetProperties())
                {
                    switch (prop.PropertyType.Name)
                    {
                    case "Boolean":
                        setting = lsSetting.FirstOrDefault(u => u.Id == prop.Name);
                        if (setting != null)
                        {
                            bool value;
                            if (!bool.TryParse(setting.Value, out value))
                            {
                                value = false;
                            }
                            prop.SetValue(serverSetting, value, null);
                        }
                        else
                        {
                            prop.SetValue(serverSetting, false, null);
                        }
                        break;

                    case "Int32":
                        setting = lsSetting.FirstOrDefault(u => u.Id == prop.Name);
                        if (setting != null)
                        {
                            int value;
                            if (!int.TryParse(setting.Value, out value))
                            {
                                value = 0;
                            }
                            prop.SetValue(serverSetting, value, null);
                        }
                        else
                        {
                            prop.SetValue(serverSetting, 0, null);
                        }
                        break;

                    case "Decimal":
                        setting = lsSetting.FirstOrDefault(u => u.Id == prop.Name);
                        if (setting != null)
                        {
                            decimal value;
                            if (!decimal.TryParse(setting.Value, out value))
                            {
                                value = 0;
                            }
                            prop.SetValue(serverSetting, value, null);
                        }
                        else
                        {
                            prop.SetValue(serverSetting, Convert.ToDecimal(0), null);
                        }
                        break;

                    case "Double":
                        setting = lsSetting.FirstOrDefault(u => u.Id == prop.Name);
                        if (setting != null)
                        {
                            double value;
                            if (!double.TryParse(setting.Value, out value))
                            {
                                value = 0;
                            }
                            prop.SetValue(serverSetting, value, null);
                        }
                        else
                        {
                            prop.SetValue(serverSetting, Convert.ToDouble(0), null);
                        }
                        break;

                    case "String":
                        setting = lsSetting.FirstOrDefault(u => u.Id == prop.Name);
                        if (setting != null)
                        {
                            string value = setting.Value;
                            prop.SetValue(serverSetting, value, null);
                        }
                        else
                        {
                            prop.SetValue(serverSetting, string.Empty, null);
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(serverSetting);
        }