Exemple #1
0
        public int SaveProduct([FromBody] ProductClass productForm)
        {
            int answer = 0;

            try
            {
                using (FacturacionContext db = new FacturacionContext())
                {
                    using (var transaccion = new TransactionScope())
                    {
                        Product productModel = new Product();
                        productModel.DateCreated = DateTime.Now;
                        productModel.Name        = productForm.name;
                        productModel.Price       = productForm.price;
                        productModel.Stock       = productForm.stock;
                        db.Add(productModel);
                        db.SaveChanges();
                        transaccion.Complete();
                        answer = 1;
                    }
                }
            }
            catch (Exception)
            {
                answer = 2;
            }
            return(answer);
        }
Exemple #2
0
        public static async Task <bool> CrearNuevoDetalles(FacturacionContext context, int codigoProducto, int cantidadProducto, int precioProducto)
        {
            try
            {
                Detalles detalle = new Detalles();
                detalle.idFactura      = codigoProducto;
                detalle.idProducto     = codigoProducto;
                detalle.Cantidad       = cantidadProducto;
                detalle.PrecioUnitario = precioProducto;
                context.Detalles.Add(detalle);
                await context.SaveChangesAsync();

                System.Diagnostics.Debug.WriteLine("SE CREO El DETALLE");
                return(true);
            }
            catch (Exception e)
            {
                /**
                 * Se podría monitorear los errores,
                 * En este caso simplemente escribimos en consola
                 */
                System.Diagnostics.Debug.WriteLine("ERROR: " + e);
                return(false);
            }
        }
 public ClienteRepository(
     FacturacionContext context,
     ILogger <ClienteRepository> logger
     )
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
     _logger  = logger ?? throw new ArgumentNullException(nameof(logger));
 }
 public IActionResult Index()
 {
     using (var context = new FacturacionContext())
     {
         var data = context.Factura.Include(x => x.IdClienteNavigation).ToList();
         return(View(data));
     }
 }
 public IActionResult DetalleFactura(long id)
 {
     using (var context = new FacturacionContext())
     {
         var data = context.DetalleFactura.Include(x => x.IdFacturaNavigation).Include(x => x.IdFacturaNavigation.IdClienteNavigation).Include(x => x.IdProductoNavigation).Where(x => x.IdFactura == id).ToList();
         return(View(data));
     }
 }
 public JsonResult BuscarProductoXNombre(string nombre)
 {
     using (var context = new FacturacionContext())
     {
         var data = context.Producto.Where(x => x.Nombre.Contains(nombre)).ToList();
         return(Json(data));
     }
 }
 public JsonResult BuscarProductoXId(Int32 id)
 {
     using (var context = new FacturacionContext())
     {
         var data = context.Producto.Where(x => x.IdProducto == id).ToList();
         return(Json(data));
     }
 }
 public IActionResult CrearFactura()
 {
     using (var context = new FacturacionContext())
     {
         Factura fact = new Factura();
         fact.IdFactura      = context.Factura.Max(x => x.IdFactura) + 1;
         fact.DetalleFactura = new Collection <DetalleFactura>();
         return(View(fact));
     }
 }
Exemple #9
0
 public UnitOfWork(RRDContext context, MooreveContext mooreveContext, MCContext mcContext, MaestrosContext maestrosContext, SapContext sapContext, ClientesContext clientesContext, FacturacionContext facturacionContext)
 {
     _context            = context;
     _mooreveContext     = mooreveContext;
     _mcContext          = mcContext;
     _maestrosContext    = maestrosContext;
     _sapContext         = sapContext;
     _clientesContext    = clientesContext;
     _facturacionContext = facturacionContext;
 }
        public JsonResult GuardarFactura([FromBody] Factura factura)
        {
            using (FacturacionContext context = new FacturacionContext())
            {
                if (factura == null)
                {
                    factura = new Factura();
                }
                factura.FechaCreacion = DateTime.Now;
                context.Factura.Add(factura);

                int insertedRecords = context.SaveChanges();
                return(Json(insertedRecords));
            }
        }
        public IActionResult Pdf(long id)
        {
            FacturacionContext context = new FacturacionContext();

            var data = context.DetalleFactura.Include(x => x.IdFacturaNavigation).Include(x => x.IdFacturaNavigation.IdClienteNavigation).Include(x => x.IdProductoNavigation).Where(x => x.IdFactura == id).ToList();

            MemoryStream ms = new MemoryStream();

            PdfWriter   pw          = new PdfWriter(ms);
            PdfDocument pdfDocument = new PdfDocument(pw);
            Document    doc         = new Document(pdfDocument, PageSize.LETTER);
            //doc.SetMargins(75, 35, 70, 35);

            Table table = new Table(1).UseAllAvailableWidth();

            Cell cell = new Cell().Add(new Paragraph("Factura de Venta").SetFontSize(16))
                        .SetBorder(Border.NO_BORDER);

            table.AddCell(cell);

            //Datos Cliente
            cell = new Cell().Add(new Paragraph("Datos del Cliente").SetFontSize(13))
                   .SetBorder(Border.NO_BORDER)
                   .SetPaddingTop(60);
            table.AddCell(cell);

            cell = new Cell().Add(new Paragraph("Cliente      " + data[0].IdFacturaNavigation.IdClienteNavigation.NombreCliente).SetFontSize(11))
                   .SetBorder(Border.NO_BORDER);
            table.AddCell(cell);

            cell = new Cell().Add(new Paragraph("Telefono   " + data[0].IdFacturaNavigation.IdClienteNavigation.Telefono).SetFontSize(11))
                   .SetBorder(Border.NO_BORDER);
            table.AddCell(cell);

            cell = new Cell().Add(new Paragraph("Fec. Nac. " + data[0].IdFacturaNavigation.IdClienteNavigation.FechaNacimiento).SetFontSize(11))
                   .SetBorder(Border.NO_BORDER);
            table.AddCell(cell);

            //Datos Factura
            cell = new Cell().Add(new Paragraph("Datos de la Factura").SetFontSize(13))
                   .SetBorder(Border.NO_BORDER)
                   .SetPaddingTop(20);
            table.AddCell(cell);

            cell = new Cell().Add(new Paragraph("Número   " + data[0].IdFactura).SetFontSize(11))
                   .SetBorder(Border.NO_BORDER);
            table.AddCell(cell);

            cell = new Cell().Add(new Paragraph("Fecha      " + data[0].IdFacturaNavigation.FechaCreacion).SetFontSize(11))
                   .SetBorder(Border.NO_BORDER)
                   .SetPaddingBottom(20);
            table.AddCell(cell);

            doc.Add(table);

            Table _table = new Table(4).UseAllAvailableWidth();
            Cell  _cell  = new Cell().Add(new Paragraph("Producto")).SetBold().SetFontSize(9).SetCharacterSpacing(1);

            _table.AddCell(_cell);
            _cell = new Cell().Add(new Paragraph("Precio")).SetBold().SetFontSize(9).SetCharacterSpacing(1);
            _table.AddCell(_cell);
            _cell = new Cell().Add(new Paragraph("Cantidad")).SetBold().SetFontSize(9).SetCharacterSpacing(1);
            _table.AddCell(_cell);
            _cell = new Cell().Add(new Paragraph("Valor")).SetBold().SetFontSize(9).SetCharacterSpacing(1);
            _table.AddCell(_cell);

            foreach (var item in data)
            {
                _cell = new Cell().Add(new Paragraph(item.IdProductoNavigation.Nombre)).SetFontSize(9);
                _table.AddCell(_cell);
                _cell = new Cell().Add(new Paragraph(string.Format("{0:C}", item.IdProductoNavigation.ValorUnitario))).SetFontSize(9);
                _table.AddCell(_cell);
                _cell = new Cell().Add(new Paragraph(item.Cantidad.ToString())).SetFontSize(9);
                _table.AddCell(_cell);
                _cell = new Cell().Add(new Paragraph(string.Format("{0:C}", item.IdFacturaNavigation.ValorTotal))).SetFontSize(9);
                _table.AddCell(_cell);
            }

            doc.Add(_table);
            doc.Close();

            byte[] bytesStream = ms.ToArray();
            ms = new MemoryStream();
            ms.Write(bytesStream, 0, bytesStream.Length);
            ms.Position = 0;

            return(new FileStreamResult(ms, "application/pdf"));
        }
Exemple #12
0
 public ProductosService(FacturacionContext facturacionContext)
 {
     _facturacionContext = facturacionContext;
 }
Exemple #13
0
 public DetallesController(FacturacionContext context)
 {
     _context = context;
 }
Exemple #14
0
 public ClientesController(FacturacionContext context)
 {
     _context = context;
 }
Exemple #15
0
 public VentasService(FacturacionContext facturacionContext)
 {
     _facturacionContext = facturacionContext;
 }
Exemple #16
0
 public UsuariosController(FacturacionContext context)
 {
     _context = context;
 }
Exemple #17
0
 public ClientesService(FacturacionContext facturacionContext)
 {
     _facturacionContext = facturacionContext;
 }
Exemple #18
0
 public ProveedorsController(FacturacionContext context)
 {
     _context = context;
 }
 public Winy243Repository(FacturacionContext context)
 {
     _context = context;
 }
 public FacturasController(FacturacionContext context)
 {
     _context = context;
 }
Exemple #21
0
 public ProductosController(FacturacionContext context)
 {
     _context = context;
 }