Ejemplo n.º 1
0
        /// <summary>
        /// Returns a filter object list to be displayed in a paginated list.
        /// </summary>
        /// <param name="datatableDTO"><see cref="DataTableAjaxPostDTO"/></param>
        /// <param name="filteredResultsCount">filtered results count</param>
        /// <param name="totalResultsCount">total results count</param>
        /// <param name="where">custom filter</param>
        /// <param name="smode"><see cref="ServiceAccessMode"/></param>
        /// <returns>list of objects</returns>
        public virtual List <DTO> GetAllWhereForAjaxDataTable(DataTableAjaxPostDTO datatableDTO, out int filteredResultsCount, out int totalResultsCount, Expression <Func <Entity, bool> > where = default(Expression <Func <Entity, bool> >), ServiceAccessMode smode = ServiceAccessMode.Read)
        {
            if (datatableDTO == null)
            {
                throw new ArgumentNullException("datatableDTO", "datatableDTO is null.");
            }

            if (datatableDTO.Order == null)
            {
                throw new ArgumentNullException("datatableDTO.Order", "datatableDTO.Order is null.");
            }

            IQueryable <Entity> query = Repository.GetStandardQuery(TranslateAccess(smode));

            totalResultsCount = query.Count();

            if (where != default(Expression <Func <Entity, bool> >))
            {
                query = query.Where(where);
                filteredResultsCount = query.Count();
            }
            else
            {
                filteredResultsCount = totalResultsCount;
            }

            string sortExpression = datatableDTO.Columns[datatableDTO.Order.First().Column].Data.Replace("__", ".") + " " + datatableDTO.Order.First().Dir.ToLower();

            List <DTO> result = query.OrderBy(sortExpression)
                                .Skip(datatableDTO.Start)
                                .Take(datatableDTO.Length)
                                .Select(GetSelectorExpression()).ToList();

            return(result ?? new List <DTO>());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns a filter object list to be displayed in a paginated list.
 /// </summary>
 /// <typeparam name="DTO">The type of the dto.</typeparam>
 /// <typeparam name="Entity">The type of the entity.</typeparam>
 /// <param name="datatableDTO"><see cref="DataTableAjaxPostDTO"/> </param>
 /// <param name="filteredResultsCount">filtered results count</param>
 /// <param name="totalResultsCount">total results count</param>
 /// <param name="where">custom filter</param>
 /// <param name="smode"><see cref="ServiceAccessMode"/></param>
 /// <returns>list of objects</returns>
 public static List <DTO> GetAllWhereForAjaxDataTable <DTO, Entity>(DataTableAjaxPostDTO datatableDTO, out int filteredResultsCount, out int totalResultsCount, Expression <Func <Entity, bool> > where = default(Expression <Func <Entity, bool> >), ServiceAccessMode smode = ServiceAccessMode.Read)
 {
     return(((dynamic)GetService <DTO>()).GetAllWhereForAjaxDataTable(datatableDTO, out filteredResultsCount, out totalResultsCount, where, smode));
 }