예제 #1
0
 private HttpResponse <EstadisticasResponse> newHttpEstadisticasResponse(EstadisticasResponse response)
 {
     return(new HttpResponse <EstadisticasResponse>()
     {
         StatusCode = HttpStatusCode.OK,
         ApiResponse = new ApiResponse <EstadisticasResponse>()
         {
             Data = response,
             Error = null
         }
     });
 }
예제 #2
0
        public HttpResponse <EstadisticasResponse> GetEstadisticas(EstadisticasRequest request)
        {
            if (request == null)
            {
                return(newHttpEstadisticasErrorResponse(new Error("Los parametros pasados son invalidos.")));
            }

            using (var db = new GeviApiContext())
            {
                var totalTransporte = db.Gastos
                                      .Where(g => g.Estado == Estado.APROBADO &&
                                             (!String.IsNullOrEmpty(request.ClienteNombre) &&
                                              (g.Viaje != null) && (g.Viaje.Proyecto != null) &&
                                              (g.Viaje.Proyecto.Cliente != null) ? g.Viaje.Proyecto.Cliente.Nombre.Equals(request.ClienteNombre) : true) &&
                                             (request.EmpleadoId > 0 && (g.Empleado != null) ? g.Empleado.Id == request.EmpleadoId : true) &&
                                             (!request.FechaInicio.Equals(DateTime.MinValue) ? g.Fecha >= request.FechaInicio : true) &&
                                             (!request.FechaFin.Equals(DateTime.MinValue) ? g.Fecha <= request.FechaFin : true))
                                      .Where(g => g.Tipo.Nombre.Equals("TRANSPORTE"))
                                      .Include(g => g.Empleado)
                                      .Include(g => g.Tipo)
                                      .Include(g => g.Viaje)
                                      .ToList()
                                      .Select(g => g.Total)
                                      .Sum();

                var totalGastronomico = db.Gastos
                                        .Where(g => g.Estado == Estado.APROBADO &&
                                               (!String.IsNullOrEmpty(request.ClienteNombre) &&
                                                (g.Viaje != null) && (g.Viaje.Proyecto != null) &&
                                                (g.Viaje.Proyecto.Cliente != null) ? g.Viaje.Proyecto.Cliente.Nombre.Equals(request.ClienteNombre) : true) &&
                                               (request.EmpleadoId > 0 && (g.Empleado != null) ? g.Empleado.Id == request.EmpleadoId : true) &&
                                               (!request.FechaInicio.Equals(DateTime.MinValue) ? g.Fecha >= request.FechaInicio : true) &&
                                               (!request.FechaFin.Equals(DateTime.MinValue) ? g.Fecha <= request.FechaFin : true))
                                        .Where(g => g.Tipo.Nombre.Equals("GASTRONOMICO"))
                                        .Include(g => g.Empleado)
                                        .Include(g => g.Tipo)
                                        .Include(g => g.Viaje)
                                        .ToList()
                                        .Select(g => g.Total)
                                        .Sum();

                var totalTelefonia = db.Gastos
                                     .Where(g => g.Estado == Estado.APROBADO &&
                                            (!String.IsNullOrEmpty(request.ClienteNombre) &&
                                             (g.Viaje != null) && (g.Viaje.Proyecto != null) &&
                                             (g.Viaje.Proyecto.Cliente != null) ? g.Viaje.Proyecto.Cliente.Nombre.Equals(request.ClienteNombre) : true) &&
                                            (request.EmpleadoId > 0 && (g.Empleado != null) ? g.Empleado.Id == request.EmpleadoId : true) &&
                                            (!request.FechaInicio.Equals(DateTime.MinValue) ? g.Fecha >= request.FechaInicio : true) &&
                                            (!request.FechaFin.Equals(DateTime.MinValue) ? g.Fecha <= request.FechaFin : true))
                                     .Where(g => g.Tipo.Nombre.Equals("TELEFONIA"))
                                     .Include(g => g.Empleado)
                                     .Include(g => g.Tipo)
                                     .Include(g => g.Viaje)
                                     .ToList()
                                     .Select(g => g.Total)
                                     .Sum();

                var totalOtros = db.Gastos
                                 .Where(g => g.Estado == Estado.APROBADO &&
                                        (!String.IsNullOrEmpty(request.ClienteNombre) &&
                                         (g.Viaje != null) && (g.Viaje.Proyecto != null) &&
                                         (g.Viaje.Proyecto.Cliente != null) ? g.Viaje.Proyecto.Cliente.Nombre.Equals(request.ClienteNombre) : true) &&
                                        (request.EmpleadoId > 0 && (g.Empleado != null) ? g.Empleado.Id == request.EmpleadoId : true) &&
                                        (!request.FechaInicio.Equals(DateTime.MinValue) ? g.Fecha >= request.FechaInicio : true) &&
                                        (!request.FechaFin.Equals(DateTime.MinValue) ? g.Fecha <= request.FechaFin : true))
                                 .Where(g => g.Tipo.Nombre.Equals("OTROS"))
                                 .Include(g => g.Empleado)
                                 .Include(g => g.Tipo)
                                 .Include(g => g.Viaje)
                                 .ToList()
                                 .Select(g => g.Total)
                                 .Sum();


                var response = new EstadisticasResponse()
                {
                    TotalTransporte   = totalTransporte,
                    TotalGastronomico = totalGastronomico,
                    TotalTelefonia    = totalTelefonia,
                    TotalOtros        = totalOtros
                };

                return(newHttpEstadisticasResponse(response));
            }
        }