Exemplo n.º 1
0
        /// <summary>
        /// Adds a sort information to the data options. This method will not do anything if the sortinfo already contains values.
        /// </summary>
        /// <typeparam name="TModel">The model type.</typeparam>
        /// <typeparam name="TProperty">The property type.</typeparam>
        /// <param name="data">The data options object referece.</param>
        /// <param name="prop">The lambda expression for the property to order from.</param>
        /// <param name="direction">The sort direction.</param>
        /// <param name="overrideExisting">Set to true if the order should override any existing configuration.</param>
        public static void OrderBy <TModel, TProperty>(this IFWSpecification <TModel> data, Expression <Func <TModel, TProperty> > prop, FWSortDirection direction, bool overrideExisting = false)
        {
            if (data.QueryOptions == null)
            {
                throw new ArgumentException("The specification does not have an instance of IFWDataOptions");
            }

            if (data.QueryOptions.SortInfo == null)
            {
                return;
            }

            var member   = prop.Body as MemberExpression;
            var propInfo = member.Member as PropertyInfo;

            if (!overrideExisting && data.QueryOptions.SortInfo.Any(f => f.SortName == propInfo.Name))
            {
                return;
            }

            data.QueryOptions.SortInfo.Add(new FWDataSorting()
            {
                SortName = propInfo.Name, SortDirection = direction
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Searchs the database, based on a specification.
        /// </summary>
        /// <typeparam name="TResult">The result type.</typeparam>
        /// <param name="selector">A projection funtion the be applied.</param>
        /// <param name="specification">The query specification.</param>
        /// <returns>The list of entities found.</returns>
        public List <TResult> Select <TResult>(Expression <Func <TEntity, TResult> > selector,
                                               IFWSpecification <TEntity> specification)
        {
            List <TResult> result;

            if (specification.QueryOptions != null)
            {
                result = Select(selector, specification, out int total);
                specification.QueryOptions.Total = total;
            }
            else
            {
                result = _dbSet.Where(specification.CreateExpression()).Select(selector).ToList();
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Searchs the database, based on a specification.
        /// </summary>
        /// <typeparam name="TResult">The result type.</typeparam>
        /// <param name="selector">A projection funtion the be applied.</param>
        /// <param name="specification">The query specification.</param>
        /// <param name="total">Total records found.</param>
        /// <returns>The list of entities found.</returns>
        public List <TResult> Select <TResult>(Expression <Func <TEntity, TResult> > selector,
                                               IFWSpecification <TEntity> specification, out int total)
        {
            var queryOptions = specification.QueryOptions;

            int skip  = queryOptions.Display * (queryOptions.Page - 1);
            var query = this._dbSet.Where(specification.CreateExpression());

            query = AddOrderBy(queryOptions, query);

            var result = query.Select(selector);

            total = result.Count();

            if (queryOptions.Page > 0)
            {
                return(result.Skip(skip).Take(queryOptions.Display).ToList());
            }
            else
            {
                return(result.ToList());
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Adds a sort information to the data options. This method will not do anything if the sortinfo already contains values.
 /// </summary>
 /// <typeparam name="TModel">The model type.</typeparam>
 /// <typeparam name="TProperty">The property type.</typeparam>
 /// <param name="data">The data options object referece.</param>
 /// <param name="prop">The lambda expression for the property to order from.</param>
 /// <param name="overrideExisting">Set to true if the order should override any existing configuration.</param>
 public static void OrderBy <TModel, TProperty>(this IFWSpecification <TModel> data, Expression <Func <TModel, TProperty> > prop, bool overrideExisting = false)
 {
     OrderBy(data, prop, FWSortDirection.Ascending, overrideExisting);
 }