Exemple #1
0
        public List <FacturaDTO> GetByClientId(long ClientId)
        {
            try
            {
                using (var context = new DataModelDB())
                {
                    List <FacturaDTO> facturaDTOs = new List <FacturaDTO>();
                    List <Factura>    listres     = context.Facturas.Where(fac => fac.ClienteId.Equals(ClientId)).ToList();

                    foreach (var factura in listres)
                    {
                        facturaDTOs.Add(new FacturaDTO
                        {
                            Id         = factura.Id,
                            ClienteId  = factura.ClienteId,
                            FechaVenta = factura.FechaVenta,
                            ValorTotal = factura.ValorTotal,
                            Estado     = factura.Estado
                        });
                    }
                    return(facturaDTOs);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemple #2
0
        public List <FacturaDTO> GetAllOrById(int id = 0)
        {
            try
            {
                List <FacturaDTO> facturaDTOs = new List <FacturaDTO>();
                using (var context = new DataModelDB())
                {
                    List <Factura> listres = context.Facturas.ToList();

                    if (id > 0)
                    {
                        listres = listres.Where(fac => fac.Id.Equals(id)).ToList();
                    }

                    foreach (var factura in listres)
                    {
                        facturaDTOs.Add(new FacturaDTO
                        {
                            Id         = factura.Id,
                            ClienteId  = factura.ClienteId,
                            FechaVenta = factura.FechaVenta,
                            ValorTotal = factura.ValorTotal,
                            Estado     = factura.Estado
                        });
                    }
                    return(facturaDTOs);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemple #3
0
        public List <ClienteDTO> GetAllOrById(long id = 0)
        {
            try
            {
                List <ClienteDTO> ClienteDTOs = new List <ClienteDTO>();
                using (var context = new DataModelDB())
                {
                    List <Cliente> listres = context.Clientes.ToList();

                    if (id > 0)
                    {
                        listres = listres.Where(fac => fac.Id.Equals(id)).ToList();
                    }

                    foreach (var cliente in listres)
                    {
                        ClienteDTOs.Add(new ClienteDTO
                        {
                            Id            = cliente.Id,
                            Nombre        = cliente.Nombre,
                            Direccion     = cliente.Direccion,
                            Estado        = cliente.Estado,
                            FechaCreacion = cliente.FechaCreacion
                        });
                    }
                    return(ClienteDTOs);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemple #4
0
 public int DeleteFactura(int id)
 {
     try
     {
         using (var context = new DataModelDB())
         {
             var std = context.Facturas.Where(fac => fac.Id.Equals(id)).FirstOrDefault();
             context.Facturas.Remove(std);
             context.SaveChanges();
         }
         return(1);
     }
     catch (Exception ex)
     {
         return(0);
     }
 }
Exemple #5
0
 public int UpdateFactura(FacturaDTO factura)
 {
     try
     {
         using (var context = new DataModelDB())
         {
             var std = context.Facturas.Where(fac => fac.Id.Equals(factura.Id)).FirstOrDefault();
             std.ClienteId  = factura.ClienteId;
             std.ValorTotal = factura.ValorTotal;
             std.Estado     = factura.Estado;
             context.SaveChanges();
         }
         return(1);
     }
     catch (Exception ex)
     {
         return(0);
     }
 }
Exemple #6
0
 public int UpdateCliente(ClienteDTO cliente)
 {
     try
     {
         using (var context = new DataModelDB())
         {
             var std = context.Clientes.Where(fac => fac.Id.Equals(cliente.Id)).FirstOrDefault();
             std.Nombre        = cliente.Nombre;
             std.Direccion     = cliente.Direccion;
             std.Estado        = true;
             std.FechaCreacion = DateTime.Now;
             context.SaveChanges();
         }
         return(1);
     }
     catch (Exception ex)
     {
         return(0);
     }
 }
Exemple #7
0
        public int InsertFactura(FacturaDTO factura)
        {
            try
            {
                using (var context = new DataModelDB())
                {
                    context.Facturas.Add(new Factura
                    {
                        Id         = factura.Id,
                        ClienteId  = factura.ClienteId,
                        FechaVenta = DateTime.Now,
                        ValorTotal = factura.ValorTotal,
                        Estado     = true
                    });

                    context.SaveChanges();
                }
                return(1);
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
Exemple #8
0
        public int InsertCliente(ClienteDTO cliente)
        {
            try
            {
                using (var context = new DataModelDB())
                {
                    context.Clientes.Add(new Cliente
                    {
                        Id            = cliente.Id,
                        Nombre        = cliente.Nombre,
                        Direccion     = cliente.Direccion,
                        Estado        = true,
                        FechaCreacion = DateTime.Now
                    });

                    context.SaveChanges();
                }
                return(1);
            }
            catch (Exception ex)
            {
                return(0);
            }
        }