| | |
| | | using System.ComponentModel.DataAnnotations; |
| | | using System.ComponentModel.DataAnnotations.Schema; |
| | | using System.Linq; |
| | | using System.Linq.Expressions; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Core.Const; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEA_Core.Helper; |
| | | |
| | | namespace WIDESEA_Core.Utilities |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public static void ValidatePageOptions<TEntity>(PageDataOptions options, ref ISugarQueryable<TEntity> sugarQueryable) |
| | | { |
| | | string where = string.Empty; |
| | | PropertyInfo[] entityProperties = typeof(TEntity).GetProperties(); |
| | | List<SearchParameters> searchParametersList = new List<SearchParameters>(); |
| | | if (options.Filter != null && options.Filter.Count > 0) |
| | | { |
| | | searchParametersList.AddRange(options.Filter); |
| | | } |
| | | else if (!string.IsNullOrEmpty(options.Wheres)) |
| | | { |
| | | try |
| | | { |
| | | searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>(); |
| | | options.Filter = searchParametersList; |
| | | } |
| | | catch { } |
| | | } |
| | | for (int i = 0; i < searchParametersList.Count; i++) |
| | | { |
| | | if (string.IsNullOrEmpty(searchParametersList[i].Value)) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | PropertyInfo? property = entityProperties.Where(c => c.Name.ToUpper() == searchParametersList[i].Name.ToUpper()).FirstOrDefault(); |
| | | |
| | | if (property == null) continue; |
| | | |
| | | List<(bool, string, object)> results = property.ValidationValueForDbType(searchParametersList[i].Value.Split(',')).ToList(); |
| | | if (results == null || results.Count() == 0) |
| | | { |
| | | continue; |
| | | } |
| | | for (int j = 0; j < results.Count(); j++) |
| | | { |
| | | LinqExpressionType expressionType = searchParametersList[i].DisplayType.GetLinqCondition(); |
| | | Expression<Func<TEntity, bool>> expression = property.GetWhereExpression<TEntity>(results[j].Item3, null, expressionType); |
| | | sugarQueryable = sugarQueryable.Where(expression); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |