示例#1
0
        public async Task <Sentinel> GetObtenerIndiceSentinel(int clienteID)
        {
            Sentinel sentinel = new Sentinel();

            try
            {
                var lista = creditoService.ObtenerHistorialSBS(clienteID, connString);

                if (lista.Result != null)
                {
                    var totalCreditosPositivos = from file in lista.Result
                                                 where file.fecha_pago != null
                                                 select new { total = file.Total };

                    var totalCreditosNegativo = from file in lista.Result
                                                where file.fecha_pago == null
                                                select new { total = file.Total };

                    var total = from file in lista.Result
                                select new { total = file.Total };

                    sentinel.ClienteID                 = clienteID;
                    sentinel.CantidadCreditos          = total.Count();
                    sentinel.CantidadCreditosNegativos = totalCreditosNegativo.Count();
                    sentinel.CantidadCreditosPositivos = totalCreditosPositivos.Count();
                    sentinel.Total = total.Sum(f => f.total);
                    sentinel.TotalCreditosNegativo  = totalCreditosNegativo.Sum(f => f.total);
                    sentinel.TotalCreditosPositivos = totalCreditosPositivos.Sum(f => f.total);
                    if (sentinel.CantidadCreditosNegativos == 0)
                    {
                        sentinel.Indicador = "BUENO";
                    }
                    else if (sentinel.CantidadCreditosPositivos > sentinel.CantidadCreditosNegativos)
                    {
                        sentinel.Indicador = "REGULAR";
                    }
                    else
                    {
                        sentinel.Indicador = "MALO";
                    }
                    return(await Task.FromResult(sentinel));
                }
            }
            catch (Exception e)
            {
                sentinel = null;
                Console.Write("Error" + e.ToString());
            }
            return(sentinel);
        }