123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System.Data;
- using System.Linq;
- using System.Reflection;
- using System.Threading.Tasks;
- using Dapper;
- using GCAS.Dto;
- using GCAS.Model;
- namespace GCAS.Code
- {
- public class ConfigRepository
- {
- public async Task<int> UpdateThresholdAsync(ConfigDto entity)
- {
- string updateSql = "UPDATE config set config.value=@Value where config.key=@Key ";
- using (IDbConnection conn = DataBaseConfig.GetSqlConnection())
- {
- int result = 0;
- result += await conn.ExecuteAsync(updateSql, new { Value = entity.PutThresholdMin, Key = "PutThresholdMin" });
- result += await conn.ExecuteAsync(updateSql, new { Value = entity.PutThresholdMax, Key = "PutThresholdMax" });
- return result;
- }
- }
- public ConfigDto Get()
- {
- ConfigDto config = new ConfigDto();
- string selectSql = "select config.key,config.value from config";
- using (IDbConnection conn = DataBaseConfig.GetSqlConnection())
- {
- var models = conn.Query<ConfigModel>(selectSql).ToList();
- PropertyInfo[] dataPro = config.GetType().GetProperties();
- foreach (var item in dataPro)
- {
- switch (item.PropertyType.Name)
- {
- case "Int32":
- item.SetValue(config, int.Parse(models.FirstOrDefault(c => c.Key == item.Name).Value));
- break;
- case "Single":
- item.SetValue(config, float.Parse(models.FirstOrDefault(c => c.Key == item.Name).Value));
- break;
- case "Boolean":
- item.SetValue(config, models.FirstOrDefault(c => c.Key == item.Name).Value == "1" ? true : false);
- break;
- }
- }
- }
- return config;
- }
- }
- }
|