Esempio n. 1
0
        public async Task <Respuesta <IFacturaCompuestaDTO> > LeerFacturas()
        {
            return(await new Wrapper <IFacturaCompuestaDTO>().EjecutarTransaccionAsync(async() =>
            {
                List <IFacturaCompuestaDTO> facturas = await contexto.Factura
                                                       .Include(x => x.IdClienteNavigation)
                                                       .Include(x => x.DetalleFactura)
                                                       .Select(x => new FacturaCompuestaDO
                {
                    IdFactura = x.IdFactura,
                    IdCliente = x.IdCliente,
                    NombreCliente = $"{x.IdClienteNavigation.PrimerNombre} {x.IdClienteNavigation.PrimerApellido}",
                    Fecha = x.Fecha,
                    CantidadProductos = x.DetalleFactura.Count,
                    ValorTotal = (float)x.DetalleFactura.Sum(x => x.Precio),
                    listaDetalle = x.DetalleFactura
                                   .Select(det => new DetalleFacturaCompuestoDO {
                        IdDetalleFactura = det.IdDetalleFactura,
                        IdFactura = det.IdFactura,
                        IdProducto = det.IdProducto,
                        NombreProducto = det.IdProductoNavigation.Nombre,
                        Observaciones = det.Observaciones,
                        Precio = det.Precio
                    }).ToList <IDetalleFacturaCompuestoDTO>()
                }).ToListAsync <IFacturaCompuestaDTO>();


                return FabricaRespuesta <IFacturaCompuestaDTO> .RespuestaConDatos(facturas);
            }));
        }
        public async Task <Respuesta <IProductoCompuestoDTO> > LeerProducto(IProductoDTO productoIn)
        {
            return(await new Wrapper <IProductoCompuestoDTO>().EjecutarTransaccionAsync(async() =>
            {
                IProductoCompuestoDTO producto = await contexto.Producto
                                                 .Include(x => x.IdCategoriaNavigation)
                                                 .Include(x => x.InventarioProducto)
                                                 .Where(x => x.IdProducto == productoIn.IdProducto)
                                                 .Select(x => new ProductoCompuestoDO
                {
                    IdProducto = x.IdProducto,
                    IdCategoria = x.IdCategoria,
                    Nombre = x.Nombre,
                    Precio = x.Precio,
                    Categoria = x.IdCategoriaNavigation.Descripcion,
                    Cantidad = (int)x.InventarioProducto.FirstOrDefault().Cantidad,
                    IdInventario = x.InventarioProducto.FirstOrDefault().IdInventario
                }).FirstOrDefaultAsync <IProductoCompuestoDTO>();

                if (producto == null)
                {
                    return FabricaRespuesta <IProductoCompuestoDTO> .RespuestaSinDatos();
                }
                return FabricaRespuesta <IProductoCompuestoDTO> .RespuestaConDatos(new List <IProductoCompuestoDTO> {
                    producto
                });
            }));
        }
        public async Task <Respuesta <IProductoCompuestoDTO> > LeerProductos()
        {
            return(await new Wrapper <IProductoCompuestoDTO>().EjecutarTransaccionAsync(async() =>
            {
                List <IProductoCompuestoDTO> productos = await contexto.Producto
                                                         .Include(x => x.IdCategoriaNavigation)
                                                         .Include(x => x.InventarioProducto)
                                                         .Select(x => new ProductoCompuestoDO
                {
                    IdProducto = x.IdProducto,
                    IdCategoria = x.IdCategoria,
                    Nombre = x.Nombre,
                    Precio = x.Precio,
                    Categoria = x.IdCategoriaNavigation.Descripcion,
                    Cantidad = (int)x.InventarioProducto.FirstOrDefault().Cantidad,
                    IdInventario = x.InventarioProducto.FirstOrDefault().IdInventario
                }).ToListAsync <IProductoCompuestoDTO>();

                if (productos != null && productos.Count > 0)
                {
                    return FabricaRespuesta <IProductoCompuestoDTO> .RespuestaConDatos(productos);
                }
                else
                {
                    return FabricaRespuesta <IProductoCompuestoDTO> .RespuestaSinDatos();
                }
            }));
        }
Esempio n. 4
0
        public async Task <Respuesta <IDetalleFacturaCompuestoDTO> > ConsultarDetalleFactura(IFacturaDTO factura)
        {
            return(await new Wrapper <IDetalleFacturaCompuestoDTO>().EjecutarTransaccionAsync(async() =>
            {
                List <IDetalleFacturaCompuestoDTO> detalles = await contexto.DetalleFactura
                                                              .Include(x => x.IdProductoNavigation)
                                                              .Where(x => x.IdFactura == factura.IdFactura)
                                                              .Select(x => new DetalleFacturaCompuestoDO()
                {
                    IdDetalleFactura = x.IdDetalleFactura,
                    IdFactura = x.IdFactura,
                    IdProducto = x.IdProducto,
                    NombreProducto = x.IdProductoNavigation.Nombre,
                    Observaciones = x.Observaciones,
                    Precio = x.Precio
                }).ToListAsync <IDetalleFacturaCompuestoDTO>();

                if (detalles != null && detalles.Count > 0)
                {
                    return FabricaRespuesta <IDetalleFacturaCompuestoDTO> .RespuestaConDatos(detalles);
                }
                else
                {
                    return FabricaRespuesta <IDetalleFacturaCompuestoDTO> .RespuestaSinDatos();
                }
            }));
        }
 public async Task <Respuesta <IClienteDTO> > LeerCliente(IClienteDTO clienteIn)
 {
     return(await new Wrapper <IClienteDTO>().EjecutarTransaccionAsync(async() =>
     {
         Cliente cliente = await contexto.Cliente.FirstOrDefaultAsync(cli => cli.Cedula == clienteIn.Cedula);
         if (cliente == null)
         {
             return FabricaRespuesta <IClienteDTO> .RespuestaSinDatos();
         }
         return FabricaRespuesta <IClienteDTO> .RespuestaConDatos(new List <IClienteDTO> {
             clienteIn
         });
     }));
 }
 public async Task <Respuesta <IClienteDTO> > LeerClientes()
 {
     return(await new Wrapper <IClienteDTO>().EjecutarTransaccionAsync(async() =>
     {
         List <IClienteDTO> clientes = mapper.Map <List <IClienteDTO> >(await contexto.Cliente.ToListAsync());
         if (clientes != null && clientes.Count > 0)
         {
             return FabricaRespuesta <IClienteDTO> .RespuestaConDatos(clientes);
         }
         else
         {
             return FabricaRespuesta <IClienteDTO> .RespuestaSinDatos();
         }
     }));
 }
        public async Task <Respuesta <ICategoriaDTO> > LeerCategoria(ICategoriaDTO categoriaIn)
        {
            return(await new Wrapper <ICategoriaDTO>().EjecutarTransaccionAsync(async() =>
            {
                Categoria categoria = await contexto.Categoria
                                      .FirstOrDefaultAsync(cat => cat.IdCategoria == categoriaIn.IdCategoria);

                if (categoria == null)
                {
                    return FabricaRespuesta <ICategoriaDTO> .RespuestaSinDatos();
                }
                return FabricaRespuesta <ICategoriaDTO> .RespuestaConDatos(new List <ICategoriaDTO> {
                    categoria
                });
            }));
        }
Esempio n. 8
0
 public async Task <Respuesta <IFacturaCompuestaDTO> > LeerFactura(IFacturaDTO facturaIn)
 {
     return(await new Wrapper <IFacturaCompuestaDTO>().EjecutarTransaccionAsync(async() =>
     {
         IFacturaCompuestaDTO factura = await contexto.Factura
                                        .Include(x => x.IdClienteNavigation)
                                        .Include(x => x.DetalleFactura)
                                        .Where(x => x.IdFactura == facturaIn.IdFactura)
                                        .Select(x => new FacturaCompuestaDO
         {
             IdFactura = x.IdFactura,
             IdCliente = x.IdCliente,
             NombreCliente = $"{x.IdClienteNavigation.PrimerNombre} {x.IdClienteNavigation.PrimerApellido}",
             Fecha = x.Fecha
         }).FirstOrDefaultAsync <IFacturaCompuestaDTO>();
         if (factura == null)
         {
             return FabricaRespuesta <IFacturaCompuestaDTO> .RespuestaSinDatos();
         }
         return FabricaRespuesta <IFacturaCompuestaDTO> .RespuestaConDatos(new List <IFacturaCompuestaDTO> {
             factura
         });
     }));
 }