コード例 #1
0
        // code generated from template "ServiceGetPaged.tt"

        /// <summary>
        /// Recupera una lista paginada de entidades Persona, según la especificación indicada.
        /// </summary>
        /// <param name="specificationDto">
        /// Especificación que se va a aplicar.
        /// </param>
        /// <returns>
        /// La lista paginada de entidades 'Persona', según la especificación indicada.
        /// </returns>
        public PagedElements <PersonaDto> GetPaged(SpecificationDto specificationDto)
        {
            #region Preconditions
            // Comprobar el DTO de entrada.
            Guard.ArgumentIsNotNull(
                specificationDto,
                string.Format(
                    FrameworkResource.EspecificationDataTransferObjectIsNull,
                    "Persona"));
            #endregion
            List <PersonaDto> result = new List <PersonaDto>(0);
            int totalElements        = 0;

            try
            {
                // Creamos el repositorio de la entidad.
                IPersonaRepository repo = ApplicationLayer.IocContainer.Resolve <IPersonaRepository>();

                // Obtenemos las entidades aplicando la especificación.
                ISpecification <Persona> filter =
                    specificationDto.ToSpecification <Persona>();

                PagedElements <Persona> entities =
                    repo.GetPagedElements(
                        specificationDto.PageIndex,
                        specificationDto.PageSize,
                        filter.IsSatisfiedBy(),
                        entity => entity.Id,
                        true);
                totalElements = entities.TotalElements;

                // Mapeamos los datos.
                entities.ToList()
                .ForEach(entity =>
                {
                    var entityDto = this.personaMapper.EntityMapping(entity);
                    result.Add(entityDto);
                });

                // Confirmamos la transacción.
                this.Commit();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            // Devolver el resultado.
            return(new PagedElements <PersonaDto>(result, totalElements));
        }
コード例 #2
0
        //PagedElements<Entity1Dto> GetPaged(SpecificationDto specificationDto, UserContextDto userContextDto);
        public PagedElements <EntityBDto> GetPaged(SpecificationDto specificationDto)
        {
            #region Preconditions

            // Comprobar el DTO de entrada.
            Guard.ArgumentIsNotNull(
                specificationDto,
                string.Format(
                    Inflexion2.Resources.Framework.EspecificationDataTransferObjectIsNull,
                    "Entity B"));                               //// usar un fichero de recursos para el dominio de negocio Company.Product.BoundedContext.Resources.Business.EntityBAlias
            #endregion
            List <EntityBDto> result = new List <EntityBDto>(0);
            int totalElements        = 0;

            try
            {
                // Creamos el repositorio de la entidad.
                IEntityBRepository repo = this.unityContainer.Resolve <IEntityBRepository>();

                // Obtenemos las entidades aplicando la especificación.
                ISpecification <EntityB> filter = specificationDto.ToSpecification <EntityB>();

                PagedElements <EntityB> entities =
                    repo.GetPagedElements(
                        specificationDto.PageIndex,
                        specificationDto.PageSize,
                        filter.IsSatisfiedBy(),
                        entity => entity.Id,
                        true);
                totalElements = entities.TotalElements;
                // Mapeamos los datos.
                entities.ToList().ForEach(entity =>
                {
                    var entityDto = this.EntityBMapper.EntityMapping(entity);
                    result.Add(entityDto);
                });

                // Confirmamos la transacción.
                this.Commit();
            }
            catch (Exception ex)
            {
                // Escribir en el Log.
                //logger.Error(ex.Message, ex);
                throw ex;
            }

            // Devolver el resultado.
            return(new PagedElements <EntityBDto>(result, totalElements));
        }
コード例 #3
0
 public static ISpecification <TEntity> ToSpecification <TEntity>(this SpecificationDto specificationDto)
     where TEntity : class
 {
     return(specificationDto.ToSpecification <TEntity>(null));
 }