| | |
| | | /// <param name="removeNotContains">移除不存在字段</param> |
| | | /// <param name="removerKey">移除主键</param> |
| | | /// <returns></returns> |
| | | //public static string ValidateDicInEntity(this Type typeinfo, Dictionary<string, object> dic, bool removerKey, PropertyInfo[] propertyInfo, string[] ignoreFields = null) |
| | | //{ |
| | | // if (dic == null || dic.Count == 0) { return "参数无效"; } |
| | | |
| | | // // 不存在的字段直接移除 |
| | | // dic.Where(x => !propertyInfo.Any(p => p.Name.ToUpper() == x.Key.ToUpper())).Select(s => s.Key).ToList().ForEach(f => |
| | | // { |
| | | // dic.Remove(f); |
| | | // }); |
| | | |
| | | // string keyName = typeinfo.GetKeyName(); |
| | | // //移除主键 |
| | | // if (removerKey) |
| | | // dic.Remove(keyName); |
| | | // //else |
| | | // //{ |
| | | // // if (!dic.ContainsKey(keyName)) |
| | | // // return "请传入主键参数"; |
| | | // //} |
| | | |
| | | // foreach (PropertyInfo property in propertyInfo) |
| | | // { |
| | | // SugarColumn sugarColumn = property.GetCustomAttribute<SugarColumn>(); |
| | | // if (sugarColumn == null) |
| | | // return "请配置SugarColumn属性"; |
| | | // //忽略与主键的字段不做验证 |
| | | // if (property.Name.ToUpper() == keyName.ToUpper() || (ignoreFields != null && ignoreFields.Contains(property.Name)) || sugarColumn.IsOnlyIgnoreInsert || sugarColumn.IsOnlyIgnoreUpdate || sugarColumn.IsIgnore) |
| | | // continue; |
| | | |
| | | // //不在编辑中的列,是否也要必填 |
| | | // if (!dic.ContainsKey(property.Name.ToUpper())) |
| | | // { |
| | | // if (!sugarColumn.IsNullable) |
| | | // { |
| | | // if (sugarColumn.DefaultValue == null) |
| | | // return sugarColumn.ColumnDescription + "为必须提交项"; |
| | | // continue; |
| | | // } |
| | | // continue; |
| | | // } |
| | | // if(dic[property.Name.ToUpper()] != null) |
| | | // { |
| | | // string str = dic[property.Name.ToUpper()].ToString(); |
| | | // //将所有空值设置为null |
| | | // if (str == string.Empty) |
| | | // dic[property.Name.ToUpper()] = null; |
| | | // } |
| | | |
| | | // } |
| | | // return string.Empty; |
| | | //} |
| | | |
| | | public static string ValidateDicInEntity(this Type typeinfo, Dictionary<string, object> dic, bool removerKey, PropertyInfo[] propertyInfo, string[] ignoreFields = null) |
| | | { |
| | | if (dic == null || dic.Count == 0) { return "参数无效"; } |
| | |
| | | if (sugarColumn == null) |
| | | return "请配置SugarColumn属性"; |
| | | //忽略与主键的字段不做验证 |
| | | if (property.Name.ToUpper() == keyName.ToUpper() || (ignoreFields != null && ignoreFields.Contains(property.Name)) || sugarColumn.IsOnlyIgnoreInsert || sugarColumn.IsOnlyIgnoreUpdate || sugarColumn.IsIgnore) |
| | | if (property.Name == keyName.FirstLetterToUpper() || (ignoreFields != null && ignoreFields.Contains(property.Name)) || sugarColumn.IsOnlyIgnoreInsert || sugarColumn.IsOnlyIgnoreUpdate || sugarColumn.IsIgnore) |
| | | continue; |
| | | |
| | | //不在编辑中的列,是否也要必填 |
| | | if (!dic.ContainsKey(property.Name.ToUpper())) |
| | | if (!dic.ContainsKey(property.Name.FirstLetterToLower())) |
| | | { |
| | | if (!sugarColumn.IsNullable) |
| | | { |
| | |
| | | } |
| | | continue; |
| | | } |
| | | if(dic[property.Name.ToUpper()] != null) |
| | | if (dic[property.Name.FirstLetterToLower()] != null) |
| | | { |
| | | string str = dic[property.Name.ToUpper()].ToString(); |
| | | string str = dic[property.Name.FirstLetterToLower()].ToString(); |
| | | //将所有空值设置为null |
| | | if (str == string.Empty) |
| | | dic[property.Name.ToUpper()] = null; |
| | | dic[property.Name.FirstLetterToLower()] = null; |
| | | } |
| | | |
| | | |
| | | } |
| | | return string.Empty; |
| | | } |