Пример #1
0
 public ResponseCluster(T objValue, IEnumerable <Erro> erros, int totalItemCount, PagedListMetaData metaData)
 {
     this.objValue       = objValue;
     this.erros          = erros;
     this.totalItemCount = totalItemCount;
     this.metaData       = metaData;
 }
Пример #2
0
        public string GetNext(Webpage webpage, PagedListMetaData metadata, ViewDataDictionary viewData)
        {
            if (webpage == null)
            {
                return(null);
            }
            webpage = webpage.Unproxy();
            var baseUrl = webpage.AbsoluteUrl;

            var type = webpage.GetType();

            if (GetRelTypes.ContainsKey(type))
            {
                var getTags = _kernel.Get(GetRelTypes[type]) as GetRelTags;
                if (getTags != null)
                {
                    return(getTags.GetNext(webpage, metadata, viewData));
                }
            }

            if (metadata.IsLastPage)
            {
                return(null);
            }
            return($"{baseUrl}?Page={metadata.PageNumber + 1}");
        }
        //public static IPagedListMetaData<T> ToPagedListMetaData<T>(this PagedResultDto<T> input) where T : struct
        //{
        //    var newValue = new PagedListMetaData<T>();
        //    newValue.Subset = input.Items.ToList();
        //    newValue.TotalResultSetCount = input.TotalCount;
        //    return newValue;
        //}

        public static IPagedListMetaData <T> ToPagedListMetaData <T>(PagedResultDto <T> input) where T : struct
        {
            var newValue = new PagedListMetaData <T>();

            newValue.Subset = input.Items.ToList();
            newValue.TotalResultSetCount = input.TotalCount;
            return(newValue);
        }
        public static IPagedListMetaData <T> MapToList <T>(this DbDataReader dr) where T : new()
        {
            int totalRegistros = 0;
            var entities       = new List <T>();

            if (dr != null && dr.HasRows)
            {
                var  entity        = typeof(T);
                var  propDict      = DataReaderExtensions.GetCacheProperties(typeof(T));
                bool esPrimeraFila = true;
                while (dr.Read())
                {
                    T newObject = new T();
                    for (int index = 0; index < dr.FieldCount; index++)
                    {
                        if (esPrimeraFila)
                        {
                            if (dr.GetName(index).ToUpper().Equals("totalRegistros".ToUpper()))
                            {
                                var val = dr.GetValue(index);
                                try
                                {
                                    totalRegistros = Convert.ToInt32(val);
                                }
                                catch (System.Exception e)
                                {
                                    throw new System.Exception("totalPaginas debe ser un valor entero", e);
                                }
                            }
                        }
                        if (propDict.ContainsKey(dr.GetName(index).ToUpper()))
                        {
                            var info = propDict[dr.GetName(index).ToUpper()];
                            if ((info != null) && info.CanWrite)
                            {
                                var val = dr.GetValue(index);
                                try
                                {
                                    info.SetValue(newObject, (val == DBNull.Value) ? null : val, null);
                                }
                                catch (System.Exception e)
                                {
                                    throw new System.Exception("Tipos incompatibles para el campo: " + info.Name + ", revice que la clase y el valor devuelto por el sp sean compatibles", e);
                                }
                            }
                        }
                    }
                    entities.Add(newObject);
                    esPrimeraFila = false;
                }
            }
            var resultado = new PagedListMetaData <T> {
                Data = entities, TotalRegistros = totalRegistros
            };

            return(resultado);
        }
        public async Task <IActionResult> FindBorrower([FromQuery] PageOption pageOption, long loanBorrowerId, string session = "")
        {
            IPagedList <SavingsDepositResponse> data = await this.savingsDepositService.PageByLoanBorrower(pageOption, loanBorrowerId);

            PagedListMetaData metaData = data.GetMetaData();

            PagedDataResponse pagedData = new PagedDataResponse {
                Data = data, MetaData = metaData
            };

            return(Ok(pagedData));
        }
Пример #6
0
        public async Task <IActionResult> Paginate([FromQuery] PageOption pageOption, [FromQuery] string session = "")
        {
            IPagedList <IEntityResponseDTO> data = await this.service.PaginateAsync(pageOption);

            PagedListMetaData metaData = data.GetMetaData();

            PagedDataResponse pagedData = new PagedDataResponse {
                Data = data, MetaData = metaData
            };

            return(Ok(pagedData));
        }
Пример #7
0
        public async Task <IActionResult> Paginate([FromQuery] PageOption pageOption)
        {
            IPagedList <IEntity> data = await this.eFRepository.PaginateAsync(pageOption);

            PagedListMetaData metaData = data.GetMetaData();

            PagedDataResponse pagedData = new PagedDataResponse {
                Data = data, MetaData = metaData
            };

            return(Ok(pagedData));
        }
Пример #8
0
        public async Task <IActionResult> FindCustomerExistingLoans([FromQuery] PageOption pageOption, long savingsId, string session = "")
        {
            IPagedList <SavingsDailyBalanceResponse> data = await this.savingsDailyBalanceService.PageBySavingsId(pageOption, savingsId);

            PagedListMetaData metaData = data.GetMetaData();

            PagedDataResponse pagedData = new PagedDataResponse {
                Data = data, MetaData = metaData
            };

            return(Ok(pagedData));
        }
        public async Task <IActionResult> PageCollateralItems([FromQuery] PageOption pageOption, long loanApplicationId, string session = "")
        {
            IPagedList <CollateralItemResponse> data = await this.collateralItemService.PageByLoanApplication(pageOption, loanApplicationId);

            PagedListMetaData metaData = data.GetMetaData();

            PagedDataResponse pagedData = new PagedDataResponse {
                Data = data, MetaData = metaData
            };

            return(Ok(pagedData));
        }
Пример #10
0
        public async Task <IActionResult> PaginateCostOfSales([FromQuery] PageOption pageOption, long businessTypeId, [FromQuery] string session = "")
        {
            IPagedList <BusinessTypeCostOfSaleResponseDTO> data = await this.businessCostOfSaleService.PageByBusinessType(pageOption, businessTypeId);

            PagedListMetaData metaData = data.GetMetaData();

            PagedDataResponse pagedData = new PagedDataResponse {
                Data = data, MetaData = metaData
            };

            return(Ok(pagedData));
        }
        public async Task <IActionResult> PageBorrowerChildren([FromQuery] PageOption pageOption, long loanApplicationId, string session = "")
        {
            IPagedList <BorrowerChildResponse> data = await this.borrowerChildService.PageByLoanApplication(pageOption, loanApplicationId);

            PagedListMetaData metaData = data.GetMetaData();

            PagedDataResponse pagedData = new PagedDataResponse {
                Data = data, MetaData = metaData
            };

            return(Ok(pagedData));
        }
        public async Task <IActionResult> GetPersonalExpenses([FromQuery] PageOption pageOption, long loanApplicationId, string session = "")
        {
            IPagedList <PersonalExpenseResponse> data = await this.personalExpenseService.PageByLoanApplication(pageOption, loanApplicationId);

            PagedListMetaData metaData = data.GetMetaData();

            PagedDataResponse pagedData = new PagedDataResponse {
                Data = data, MetaData = metaData
            };

            return(Ok(pagedData));
        }
        public async Task <IActionResult> FindCustomerExistingLoans([FromQuery] PageOption pageOption, long loanApplicationId, string session = "")
        {
            IPagedList <ExistingLoanResponse> data = await this.existingLoanService.PageByLoanApplication(pageOption, loanApplicationId);

            PagedListMetaData metaData = data.GetMetaData();

            PagedDataResponse pagedData = new PagedDataResponse {
                Data = data, MetaData = metaData
            };

            return(Ok(pagedData));
        }
        public async Task <IActionResult> PaginateBusinesses([FromQuery] PageOption pageOption, long loanApplicationId, string session = "")
        {
            IPagedList <BusinessResponseDTO> data = await this.businessService.PageByLoanApplication(pageOption, loanApplicationId);

            PagedListMetaData metaData = data.GetMetaData();

            PagedDataResponse pagedData = new PagedDataResponse {
                Data = data, MetaData = metaData
            };

            return(Ok(pagedData));
        }
 public DataPagination(PagedListMetaData pagedListMetaData)
 {
     PageCount       = pagedListMetaData.PageCount;
     TotalItemCount  = pagedListMetaData.TotalItemCount;
     PageNumber      = pagedListMetaData.PageNumber;
     PageSize        = pagedListMetaData.PageSize;
     HasPreviousPage = pagedListMetaData.HasPreviousPage;
     HasNextPage     = pagedListMetaData.HasNextPage;
     IsFirstPage     = pagedListMetaData.IsFirstPage;
     IsLastPage      = pagedListMetaData.IsLastPage;
     FirstItemOnPage = pagedListMetaData.FirstItemOnPage;
     LastItemOnPage  = pagedListMetaData.LastItemOnPage;
 }
        public async Task <IActionResult> PaginateUserApplications([FromQuery] PageOption pageOption, string session = "")
        {
            RSUser user = ((RSUser)this.RouteData.Values[nameof(RSUser)]);

            IPagedList <LoanApplicationResponseDTO> data = await this.loanApplicationService.PageUserApplications(pageOption, user.UserName);

            PagedListMetaData metaData = data.GetMetaData();

            PagedDataResponse pagedData = new PagedDataResponse {
                Data = data, MetaData = metaData
            };

            return(Ok(pagedData));
        }
Пример #17
0
        //public EntityFrameworkSesionRepository(DbContext context, IIdentityUser identityUser, IManagerDateTime managerDateTime)
        //    : base(context, identityUser, managerDateTime)
        //{

        //}

        public IPagedListMetaData <TSesion> Buscar(SesionCriteria criteria, int Skip, int Take)
        {
            Guard.AgainstLessThanValue(Skip, "Skip", 0);
            Guard.AgainstLessThanValue(Take, "Take", 0);


            var query = GetAll().AsQueryable();

            if (!string.IsNullOrEmpty(criteria.Cuenta))
            {
                query = query.Where(p => p.Cuenta.ToUpper().Trim().StartsWith(criteria.Cuenta.ToUpper().Trim()));
            }

            if (criteria.Estado.HasValue)
            {
                query = query.Where(p => p.Result == criteria.Estado.Value);
            }

            if (criteria.Fecha.HasValue)
            {
                query = query.Where(p => p.CreationTime >= DbFunctions.TruncateTime(criteria.Fecha.Value) && p.CreationTime <= DbFunctions.AddDays(criteria.Fecha.Value, 1));
            }

            query = query.OrderByDescending(p => p.CreationTime);

            var totalResultSetCount = query.Count();

            query = query.Skip(Skip).Take(Take);


            IEnumerable <TSesion> resultList;

            if (totalResultSetCount > 0)
            {
                resultList = query.ToList();
            }
            else
            {
                resultList = new List <TSesion>();
            }

            var result = new PagedListMetaData <TSesion>();

            result.TotalResultSetCount = totalResultSetCount;
            result.Subset = resultList.ToList();


            return(result);
        }
Пример #18
0
        private void SetPrevAndNext(ViewDataDictionary viewData, Webpage webpage, PagedListMetaData metadata, IGetPrevAndNextRelTags getTags)
        {
            var prev = getTags.GetPrev(webpage, metadata, viewData);

            if (!string.IsNullOrWhiteSpace(prev))
            {
                viewData.LinkTags().Add(LinkTag.Prev, prev);
            }

            var next = getTags.GetNext(webpage, metadata, viewData);

            if (!string.IsNullOrWhiteSpace(next))
            {
                viewData.LinkTags().Add(LinkTag.Next, next);
            }
        }
 public static PagedListMetadataExtended FromParent(PagedListMetaData parent)
 {
     return(new PagedListMetadataExtended
     {
         FirstItemOnPage = parent.FirstItemOnPage,
         HasNextPage = parent.HasNextPage,
         HasPreviousPage = parent.HasPreviousPage,
         IsFirstPage = parent.IsFirstPage,
         IsLastPage = parent.IsLastPage,
         LastItemOnPage = parent.LastItemOnPage,
         PageCount = parent.PageCount,
         PageNumber = parent.PageNumber,
         PageSize = parent.PageSize,
         TotalItemCount = parent.TotalItemCount
     });
 }
Пример #20
0
        public IPagedListMetaData <IUsuario> Buscar(UsuarioCriteria criteria, int Skip, int Take)
        {
            Guard.AgainstLessThanValue(Skip, "Skip", 0);
            Guard.AgainstLessThanValue(Take, "Take", 0);


            var query = GetSet().AsQueryable();

            if (!string.IsNullOrEmpty(criteria.Identificacion))
            {
                query = query.Where(p => p.Identificacion.Trim().StartsWith(criteria.Identificacion.Trim()));
            }

            if (!string.IsNullOrEmpty(criteria.Cuenta))
            {
                query = query.Where(p => p.Cuenta.ToUpper().Trim().Contains(criteria.Cuenta.ToUpper().Trim()));
            }


            query = query.OrderBy(p => p.Apellidos);

            var totalResultSetCount = query.Count();

            query = query.Skip(Skip).Take(Take);


            IEnumerable <IUsuario> resultList;

            if (totalResultSetCount > 0)
            {
                resultList = query.ToList();
            }
            else
            {
                resultList = new List <Usuario>();
            }

            var result = new PagedListMetaData <IUsuario>();

            result.TotalRegistros = totalResultSetCount;
            result.Data           = resultList.ToList();


            return(result);
        }
Пример #21
0
        public IPagedListMetaData <TEntity> GetList <TKey>(int Skip, int Take, Expression <Func <TEntity, bool> > criteria = null, Expression <Func <TEntity, TKey> > orden = null)
        {
            Guard.AgainstLessThanValue(Skip, "Skip", 0);
            Guard.AgainstLessThanValue(Take, "Take", 0);


            var query = GetSet().AsQueryable();

            if (criteria != null)
            {
                query = query.Where(criteria);
            }

            if (orden != null)
            {
                query = query.OrderByDescending(orden);
            }

            var totalResultSetCount = query.Count();

            query = query.Skip(Skip).Take(Take);


            IEnumerable <TEntity> resultList;

            if (totalResultSetCount > 0)
            {
                resultList = query.ToList();
            }
            else
            {
                resultList = new List <TEntity>();
            }

            var result = new PagedListMetaData <TEntity>();

            result.TotalRegistros = totalResultSetCount;
            result.Data           = resultList.ToList();


            return(result);
        }
Пример #22
0
        public IPagedListMetaData <TEntity> GetList(Expression <Func <TEntity, bool> > criteria, int Skip, int Take, string orderBy)
        {
            Guard.AgainstLessThanValue(Skip, "Skip", 0);
            Guard.AgainstLessThanValue(Take, "Take", 0);


            var query = GetAll().AsQueryable();

            query = query.Where(criteria);

            query = query.OrderBy(orderBy);

            var totalResultSetCount = query.Count();

            query = query.Skip(Skip).Take(Take);


            IEnumerable <TEntity> resultList;

            if (totalResultSetCount > 0)
            {
                resultList = query.ToList();
            }
            else
            {
                resultList = new List <TEntity>();
            }

            var result = new PagedListMetaData <TEntity>();

            result.TotalResultSetCount = totalResultSetCount;
            result.Subset = resultList.ToList();


            return(result);
        }
        public IPagedListMetaData <TAuditoria> Buscar(AuditoriaCriteria criteria, int Skip, int Take)
        {
            Guard.AgainstLessThanValue(Skip, "Skip", 0);
            Guard.AgainstLessThanValue(Take, "Take", 0);


            var query = GetAll().AsQueryable();

            if (!string.IsNullOrEmpty(criteria.Identificador))
            {
                query = query.Where(p => p.Identificacion.ToUpper().Trim().StartsWith(criteria.Identificador.ToUpper().Trim()));
            }

            if (!string.IsNullOrEmpty(criteria.Usuario))
            {
                query = query.Where(p => p.Usuario.ToUpper().Trim().StartsWith(criteria.Usuario.ToUpper().Trim()));
            }

            if (!string.IsNullOrEmpty(criteria.Funcionalidad))
            {
                query = query.Where(p => p.Funcionalidad.ToUpper().Trim().StartsWith(criteria.Funcionalidad.ToUpper().Trim()));
            }

            if (!string.IsNullOrEmpty(criteria.Accion))
            {
                query = query.Where(p => p.Accion.ToUpper().Trim().StartsWith(criteria.Accion.ToUpper().Trim()));
            }


            //Fecha
            if (criteria.FechaInicio.HasValue && criteria.FechaFinal.HasValue)
            {
                query = query.Where(p => p.Fecha >= DbFunctions.TruncateTime(criteria.FechaInicio.Value) && p.Fecha <= DbFunctions.AddDays(criteria.FechaFinal.Value, 1));
            }
            else
            {
                if (criteria.FechaInicio.HasValue)
                {
                    query = query.Where(p => p.Fecha >= DbFunctions.TruncateTime(criteria.FechaInicio.Value));
                }
                else if (criteria.FechaFinal.HasValue)
                {
                    query = query.Where(p => p.Fecha <= DbFunctions.AddDays(criteria.FechaFinal.Value, 1));
                }
            }

            query = query.OrderByDescending(p => p.Fecha);

            var totalResultSetCount = query.Count();

            query = query.Skip(Skip).Take(Take);


            IEnumerable <TAuditoria> resultList;

            if (totalResultSetCount > 0)
            {
                resultList = query.ToList();
            }
            else
            {
                resultList = new List <TAuditoria>();
            }

            var result = new PagedListMetaData <TAuditoria>();

            result.TotalResultSetCount = totalResultSetCount;
            result.Subset = resultList.ToList();


            return(result);
        }
Пример #24
0
 public ResponseCluster(T objValue, int totalItemCount, PagedListMetaData metaData) : this()
 {
     this.objValue       = objValue;
     this.totalItemCount = totalItemCount;
     this.metaData       = metaData;
 }
Пример #25
0
 public abstract string GetPrev(Webpage webpage, PagedListMetaData metadata, ViewDataDictionary viewData);
        public IPagedListMetaData <T> SpConResultadosPaginado(string comando, IEnumerable parametros, int pagina)
        {
            pagina = pagina < 1 ? 1 : pagina;
            IEnumerable <SqlParameter> parametrosSqlServer = null;

            try
            {
                parametrosSqlServer = parametros.Cast <SqlParameter>();
            }
            catch (InvalidCastException e)
            {
                Log.Debug("No se puede realizar conversion de parametros para IEnumerable<SqlParameter>", e);
            }
            try
            {
                IPagedListMetaData <T> resultado = new PagedListMetaData <T>();

                //TODO: JOR - Revisar la eficiencia de abrir y cerrar conexiones.
                var iMetaDataPaginacionServicio = ServiceLocator.Current.GetInstance <IMetaDataPaginacionServicio>();

                var connectionString = ConfigurationManager.ConnectionStrings["Contexto"].ConnectionString;
                using (SqlConnection conn = new SqlConnection(connectionString))
                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = comando;

                        foreach (var parametro in parametros)
                        {
                            cmd.Parameters.Add(parametro);
                        }

                        /* Fijar parametros paginacion*/
                        var pageNumber = new SqlParameter("@pageNumber", SqlDbType.Int)
                        {
                            Value = pagina
                        };
                        var pageSize = new SqlParameter("@pageSize", SqlDbType.Int)
                        {
                            Value = iMetaDataPaginacionServicio.getPageSize()
                        };

                        cmd.Parameters.Add(pageNumber);
                        cmd.Parameters.Add(pageSize);

                        conn.Open();
                        var watch = Stopwatch.StartNew();
                        using (var reader = cmd.ExecuteReader())
                        {
                            watch.Stop();
                            var elapsedMs = watch.ElapsedMilliseconds;
                            Log.Debug("Tiempo ejecucion sp (" + comando + "): " + elapsedMs + " ms");

                            watch = Stopwatch.StartNew();

                            //Opcion 1. Mapeo Manual
                            resultado = reader.MapToList <T>();

                            resultado.TotalPaginas = resultado.TotalRegistros / iMetaDataPaginacionServicio.getPageSize();

                            if (resultado.TotalRegistros % iMetaDataPaginacionServicio.getPageSize() != 0)
                            {
                                resultado.TotalPaginas++;
                            }

                            //Opcion 2. Mapeo con AutoMapper
                            //if (reader.HasRows)
                            //{
                            //    CacheMapper<T>();
                            //    resultado = Mapper.Map<IDataReader, IList<T>>(reader);
                            //}

                            watch.Stop();
                            elapsedMs = watch.ElapsedMilliseconds;
                            Log.Debug("Tiempo mapeo resultados para lista<T>: " + elapsedMs + " ms");
                        }
                    }

                if (parametrosSqlServer != null)
                {
                    var parametrosCadena = string.Join("|", parametrosSqlServer.Select(pss => pss.ParameterName + ":" + pss.Value));
                    var mensaje          = "Correcto ejecucion sp " + comando + " => " + parametrosCadena;
                    Log.Debug(mensaje);
                }
                //}
                return(resultado);
            }
            catch (System.Exception ex)
            {
                if (parametrosSqlServer != null)
                {
                    var parametrosCadena = string.Join("|", parametrosSqlServer.Select(pss => pss.ParameterName + ":" + pss.Value));
                    var mensaje          = "Fallo ejecucion sp " + comando + " => " + parametrosCadena;
                    Log.Debug(mensaje, ex);
                    throw new ProcedimientoAlmacenadoExcepcion(mensaje, ex);
                }
                else
                {
                    throw ex;
                }
            }
        }