public async Task <IActionResult> Create([Bind("idFactura,NumeroFactura,Fecha,TipodePago,DocumentoCliente,NombreCliente,SubTotal,Descuento,IVA,TotalDescuento,TotalImpuesto,Total")] Facturas facturas, int codigoProducto, int cantidadProducto, int precioProducto)
        {
            if (ModelState.IsValid)
            {
                /**
                 * Se crean por defecto en 0 el sub total, total impuesto,
                 * total descuento y total.
                 * Estos serán actualizados al momento de agregar los detalles
                 */
                facturas.SubTotal       = 0;
                facturas.TotalDescuento = 0;
                facturas.TotalImpuesto  = 0;
                facturas.Total          = 0;
                var facturaAgregada = _context.Facturas.Add(facturas);
                await _context.SaveChangesAsync();

                /**
                 * Crear primer detalle obligatorio al momento de crear una factura
                 */
                if (await DetallesDao.CrearNuevoDetalles(_context, facturaAgregada.Entity.idFactura, cantidadProducto, precioProducto))
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewData["productos"] = await _context.Productos.ToListAsync();

            return(View(facturas));
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
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"));
        }
Exemplo n.º 8
0
        public async Task <ClienteModel> PutCliente(Cliente cliente)
        {
            _facturacionContext.Entry(cliente).State = EntityState.Modified;

            try
            {
                await _facturacionContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(Mapper.Map <Cliente, ClienteModel>(cliente));
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
        public async Task <ProductoModel> PutProducto(int id, Producto Producto)
        {
            _facturacionContext.Entry(Producto).State = EntityState.Modified;

            try
            {
                await _facturacionContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductoExists(id))
                {
                    throw new Exception("");
                }
                else
                {
                    throw;
                }
            }

            return(Mapper.Map <Producto, ProductoModel>(Producto));
        }
Exemplo n.º 11
0
        public async Task <Venta> PutVenta(int id, Venta Venta)
        {
            _facturacionContext.Entry(Venta).State = EntityState.Modified;

            try
            {
                await _facturacionContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VentaExists(id))
                {
                    throw new Exception("");
                }
                else
                {
                    throw;
                }
            }

            return(Venta);
        }
Exemplo n.º 12
0
        public async Task <FacturaModel> PutFactura(int id, Factura Factura)
        {
            _facturacionContext.Entry(Factura).State = EntityState.Modified;

            try
            {
                await _facturacionContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FacturaExists(id))
                {
                    throw new Exception("");
                }
                else
                {
                    throw;
                }
            }

            return(Mapper.Map <Factura, FacturaModel>(Factura));
        }
Exemplo n.º 13
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));
        }
Exemplo n.º 14
0
        public async Task SaveChangesAsync()
        {
            try
            {
                await _context.SaveChangesAsync();

                await _mcContext.SaveChangesAsync();

                await _maestrosContext.SaveChangesAsync();

                await _mooreveContext.SaveChangesAsync();

                await _sapContext.SaveChangesAsync();

                await _clientesContext.SaveChangesAsync();

                await _facturacionContext.SaveChangesAsync();
            }
            catch (System.Exception e)
            {
                var msg = e.InnerException.Message;
            }
        }