Ejemplo n.º 1
0
        /// <summary>
        /// Gets all DTO of a Type corresponding to the acces mode.
        /// </summary>
        /// <param name="smode">The smode.</param>
        /// <returns>all DTO of a Type corresponding to the acces mode</returns>
        public virtual List <DTO> GetAll(ServiceAccessMode smode = ServiceAccessMode.Read)
        {
            IQueryable <Entity> query = Repository.GetStandardQuery(TranslateAccess(smode));
            List <DTO>          list  = query.Select(GetSelectorExpression()).ToList();

            return(list);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Translates the access for the repository.
        /// </summary>
        /// <param name="smode">The smode.</param>
        /// <returns>The access translated for the repository</returns>
        public AccessMode TranslateAccess(ServiceAccessMode smode)
        {
            AccessMode mode = AccessMode.All;

            switch (smode)
            {
            case ServiceAccessMode.All:
                mode = AccessMode.All;
                break;

            case ServiceAccessMode.Read:
                mode = AccessMode.Read;
                break;

            case ServiceAccessMode.Write:
                mode = AccessMode.Write;
                break;

            case ServiceAccessMode.Delete:
                mode = AccessMode.Delete;
                break;
            }

            return(mode);
        }
Ejemplo n.º 3
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));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Gets all DTO filter by condition of a Type corresponding to the acces mode.
 /// </summary>
 /// <typeparam name="DTO">The type of the dto.</typeparam>
 /// <typeparam name="Entity">The type of the entity.</typeparam>
 /// <param name="where">The filter condition.</param>
 /// <param name="smode">The smode.</param>
 /// <returns>all DTO of a Type corresponding to the acces mode</returns>
 public static List <DTO> GetAllWhere <DTO, Entity>(Expression <Func <Entity, bool> > where, ServiceAccessMode smode = ServiceAccessMode.Read)
 {
     return(((dynamic)GetService <DTO>()).GetAllWhere(where, smode));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Gets all dto of a type based on acces right.
 /// </summary>
 /// <typeparam name="DTO">The type of to.</typeparam>
 /// <param name="smode">The smode.</param>
 /// <returns>all dto of a type based on acces right</returns>
 public static List <DTO> GetAll <DTO>(ServiceAccessMode smode = ServiceAccessMode.Read)
 {
     return(((dynamic)GetService <DTO>()).GetAll(smode));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Finds the asynchronous.
 /// </summary>
 /// <typeparam name="DTO">The type of to.</typeparam>
 /// <param name="keyValue_s">The key value_s.</param>
 /// <param name="smode">The smode.</param>
 /// <param name="sFieldsToInclude">The s fields to include.</param>
 /// <returns>DTO fund</returns>
 public static async Task <DTO> FindAsync <DTO>(object keyValue_s, ServiceAccessMode smode = ServiceAccessMode.Read, List <string> sFieldsToInclude = null)
 {
     return(await((dynamic)GetService <DTO>()).FindAsync(keyValue_s, smode, sFieldsToInclude: sFieldsToInclude));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Gets all asynchronous.
 /// </summary>
 /// <typeparam name="DTO">The type of to.</typeparam>
 /// <param name="smode">The smode.</param>
 /// <returns>List of all DTO</returns>
 public static async Task <List <DTO> > GetAllAsync <DTO>(ServiceAccessMode smode = ServiceAccessMode.Read)
 {
     return(await((dynamic)GetService <DTO>()).GetAllAsync(smode));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Finds the DTO by specifing key values, acces mode, and add include.
 /// </summary>
 /// <typeparam name="DTO">The type of to.</typeparam>
 /// <param name="keyValue_s">The key value_s.</param>
 /// <param name="smode">The smode.</param>
 /// <param name="sFieldsToInclude">The s fields to include.</param>
 /// <returns>the DTO</returns>
 public static DTO Find <DTO>(object keyValue_s, ServiceAccessMode smode = ServiceAccessMode.Read, List <string> sFieldsToInclude = null)
 {
     return(((dynamic)GetService <DTO>()).Find(keyValue_s, smode, sFieldsToInclude: sFieldsToInclude));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Gets the standard query retrieving all item corresponding to the user right.
 /// </summary>
 /// <param name="smode">The smode.</param>
 /// <returns>the standard query retrieving all item corresponding to the user right</returns>
 protected IQueryable <Entity> GetQuery(ServiceAccessMode smode = ServiceAccessMode.Read)
 {
     return(this.Repository.GetStandardQuery(TranslateAccess(smode)));
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets all DTO asynchronous.
        /// </summary>
        /// <param name="smode">The smode.</param>
        /// <returns>all DTO</returns>
        public async Task <List <DTO> > GetAllAsync(ServiceAccessMode smode = ServiceAccessMode.Read)
        {
            IQueryable <Entity> query = Repository.GetStandardQuery(TranslateAccess(smode));

            return(await query.Select(GetSelectorExpression()).ToListAsync());
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Finds the DTO by specifing key values, acces mode, and add include.
        /// </summary>
        /// <param name="keyValue_s">The key value_s.</param>
        /// <param name="smode">The smode.</param>
        /// <param name="expFieldsToInclude">The exp fields to include.</param>
        /// <param name="sFieldsToInclude">The s fields to include.</param>
        /// <returns> the DTO by specifing key values, acces mode, and add include</returns>
        public virtual DTO Find(object keyValue_s, ServiceAccessMode smode = ServiceAccessMode.Read, List <Expression <Func <Entity, dynamic> > > expFieldsToInclude = null, List <string> sFieldsToInclude = null)
        {
            DTO entity = Repository.GetFindQuery(keyValue_s, TranslateAccess(smode), expFieldsToInclude, sFieldsToInclude).Select(GetSelectorExpression()).SingleOrDefault();

            return(entity);
        }
Ejemplo n.º 12
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>());
        }