public async Task <TableFiled> AddOrModifyTableFiledAsync(TableFiled model, string sOperator) { TableFiled entityTableFiled; if (model.Id == 0) { entityTableFiled = _mapper.Map <TableFiled>(model); await _tableFiledRepository.AppendAsync(entityTableFiled, sOperator); } else { entityTableFiled = await _tableFiledRepository.SelectAsync(model.Id); if (entityTableFiled != null) { //_mapper.Map(model, entityTableFiled); entityTableFiled.IdataTableId = model.IdataTableId; entityTableFiled.IdataTypeId = model.IdataTypeId; entityTableFiled.ImaxLength = model.ImaxLength; entityTableFiled.SfiledName = model.SfiledName; entityTableFiled.BisEmpty = model.BisEmpty; entityTableFiled.Sremarks = model.Sremarks; entityTableFiled.Sexplain = model.Sexplain; _tableFiledRepository.Update(entityTableFiled, sOperator); } } return(entityTableFiled); }
/// <summary> /// 构造SQL参数化 /// </summary> /// <param name="propertyInfos"></param> /// <returns></returns> public string BuildSqlParms <T>(PropertyInfo[] propertyInfos) { Type type = typeof(T); string key = type.FullName + "sqlParms"; #region 缓存校验 if (StringCacheUntil.ExitsKey(key)) { return(StringCacheUntil.GetCache(key)); } #endregion #region 拼接参数化 StringBuilder paramsSql = new StringBuilder(); paramsSql.Append("VALUES( "); int size = propertyInfos.Length - 1; for (int i = 0; i <= size; i++) { PropertyInfo property = propertyInfos[i]; //判断字段是否是自增主键,如果是自增主键直接跳过 TableId tableId = property.GetCustomAttribute <TableId>(); if (tableId != null) { if (tableId._idType == Enum.IdTypeEnum.AUTO) { continue; } } //校验是否是表字段 TableFiled tableFiled = property.GetCustomAttribute <TableFiled>(); if (tableFiled != null) { if (!tableFiled.Exits) { continue; } } if (i < size) { paramsSql.Append("@"); paramsSql.Append(property.Name); paramsSql.Append(","); } else { paramsSql.Append("@"); paramsSql.Append(property.Name); } } #endregion //加入缓存 string res = paramsSql.ToString(); StringCacheUntil.AddCache(key, res); return(res); }
public async Task <string> AddOrModifyAsync([FromForm] TableFiled model) { BaseResult baseResult = new BaseResult(); try { if (model != null) { TableFiledValidation validationFailure = new TableFiledValidation(); ValidationResult validationResult = await validationFailure.ValidateAsync(model); if (validationResult.IsValid) { if (await _tableFiledService.AddOrModifyTableFiledAsync(model, User.Identity.Name) != null) { baseResult.Code = 0; baseResult.Msg = "操作成功!"; } else { baseResult.Code = 1; baseResult.Msg = "操作失败!"; } } else { baseResult.Code = 3; baseResult.Msg = validationResult.ToString("<br>"); } } } catch (Exception ex) { baseResult.Code = 3; baseResult.Msg = ex.Message; } return(JsonHelper.ObjectToJSON(baseResult)); }
public async Task <List <TableFiled> > SelectALLAsync(TableFiled entityTableFiled = null, string sOperator = null, int iOrderGroup = 0, int iMaxCount = 0, string sSortName = null, string sSortOrder = null) { return(await _tableFiledRepository.SelectALLAsync(entityTableFiled, sOperator, iOrderGroup, iMaxCount, sSortName, sSortOrder)); }
public TableFiled Select(TableFiled entityTableFiled = null, string sOperator = null, int iOrderGroup = 0, string sSortName = null, string sSortOrder = null) { return(_tableFiledRepository.Select(entityTableFiled, sOperator, iOrderGroup, sSortName, sSortOrder)); }
public int Append(TableFiled entityTableFiled, string sOperator) { return(_tableFiledRepository.Append(entityTableFiled, sOperator)); }
public async Task <int> AppendAsync(TableFiled entityTableFiled, string sOperator) { return(await _tableFiledRepository.AppendAsync(entityTableFiled, sOperator)); }
/// <summary> /// 构造SQL字段 /// </summary> /// <param name="propertyInfos">实体属性</param> /// <returns></returns> public string BuildSqlFiled <T>(PropertyInfo[] propertyInfos) { Type type = typeof(T); string cacheKey = type.FullName + "_sqlFiled"; string idKey = type.FullName + "idType"; #region 缓存校验 if (StringCacheUntil.ExitsKey(cacheKey)) { return(StringCacheUntil.GetCache(cacheKey)); } #endregion StringBuilder sqlFiled = new StringBuilder(); sqlFiled.Append("("); int length = propertyInfos.Length - 1; #region 拼接Sql for (int i = 0; i <= length; i++) { PropertyInfo property = propertyInfos[i]; //判断字段是否是自增主键,如果是自增主键直接跳过 TableId tableId = property.GetCustomAttribute <TableId>(); if (tableId != null) { StringCacheUntil.AddCache(idKey, JsonConvert.SerializeObject(new KeyValuePair <string, IdTypeEnum>(property.Name, tableId._idType))); if (tableId._idType == Enum.IdTypeEnum.AUTO) { continue; } } TableFiled tableFiled = property.GetCustomAttribute <TableFiled>(); //最后一个字段不加, if (i < length) { //如果不是数据库字段直接跳过 if (tableFiled != null) { if (!tableFiled.Exits) { continue; } sqlFiled.Append("`"); sqlFiled.Append(tableFiled.FiledName); sqlFiled.Append("`"); sqlFiled.Append(","); } else { sqlFiled.Append("`"); sqlFiled.Append(property.Name); sqlFiled.Append("`"); sqlFiled.Append(","); } } else { //如果不是数据库字段直接跳过 if (tableFiled != null) { if (!tableFiled.Exits) { continue; } sqlFiled.Append("`"); sqlFiled.Append(tableFiled.FiledName); sqlFiled.Append("`"); } else { sqlFiled.Append("`"); sqlFiled.Append(property.Name); sqlFiled.Append("`"); } } } #endregion sqlFiled.Append(")"); //加入缓存 string res = sqlFiled.ToString(); StringCacheUntil.AddCache(cacheKey, res); return(res); }