예제 #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);
        }
 public void AddCliente(Cliente cliente)
 {
     if (cliente == null)
     {
         throw new ArgumentNullException(nameof(cliente));
     }
     _context.Add(cliente);
 }
예제 #3
0
        public async Task <IActionResult> Create([Bind("ClienteId,Nombre,Apellido,Direccion,Emeil,Telefono")] Cliente cliente)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cliente);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cliente));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("ProveedorId,Nombre,Apellido,Telefono")] Proveedor proveedor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(proveedor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(proveedor));
        }
예제 #5
0
        public async Task <IActionResult> Create([Bind("IdUsuario,Nombre,Apellido,Telefono,IdProveedor")] Usuario usuario)
        {
            if (ModelState.IsValid)
            {
                _context.Add(usuario);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdProveedor"] = new SelectList(_context.Proveedor, "IdProveedor", "IdProveedor", usuario.IdProveedor);
            return(View(usuario));
        }
예제 #6
0
        public async Task <IActionResult> Create([Bind("FacturaId,Fecha,Precio,Cantidad,Subtotal,Iva,Total,ClienteId")] Factura factura)
        {
            if (ModelState.IsValid)
            {
                _context.Add(factura);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClienteId"] = new SelectList(_context.Cliente, "ClienteId", "ClienteId", factura.ClienteId);
            return(View(factura));
        }
예제 #7
0
        public async Task <IActionResult> Create([Bind("ProductoId,Nombreproducto,Descripcion,Precio,ProveedorId")] Producto producto)
        {
            if (ModelState.IsValid)
            {
                _context.Add(producto);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProveedorId"] = new SelectList(_context.Proveedor, "ProveedorId", "ProveedorId", producto.ProveedorId);
            return(View(producto));
        }
예제 #8
0
        public async Task <IActionResult> Create(int codigoFactura, int codigoProducto, int cantidadDetalle, int precioDetalle)
        {
            Detalles detalle = new Detalles();

            detalle.idFactura      = codigoFactura;
            detalle.idProducto     = codigoProducto;
            detalle.Cantidad       = cantidadDetalle;
            detalle.PrecioUnitario = precioDetalle;
            _context.Add(detalle);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "Facturas"));
        }
예제 #9
0
        public async Task <IActionResult> Create([Bind("DetalleFacturaId,Precio,Cantidad,Total,Iva,Fecha,IdFactura,Nombre,Apellido,ProductoId,FacturaId")] Detallefactura detallefactura)
        {
            if (ModelState.IsValid)
            {
                _context.Add(detallefactura);
                _context.SaveChanges();

                int     FacturaId = (int)detallefactura.IdFactura;
                var     factura   = _context.Factura.FirstOrDefault(f => f.FacturaId == FacturaId);
                decimal subtotal  = 0;
                foreach (var item in _context.Detallefactura.Where(d => d.FacturaId == FacturaId))
                {
                    subtotal += item.Total;
                }
                factura.Subtotal = subtotal;
                factura.Iva      = subtotal * (decimal)0.15;
                factura.Total    = subtotal - factura.Iva;
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(detallefactura));
        }