コード例 #1
0
        public JsonResult GuardarFactura()
        {
            string resultado = "";

            //LA CONEXION A NEGOCIO
            Negocio.NegFactura.NegFactura negFactura = new Negocio.NegFactura.NegFactura();

            //LLENAR OBJETO FACTURA
            Entidades.EntFactura.Factura Factura = new Entidades.EntFactura.Factura();
            Factura.Concepto  = "Factura nueva";
            Factura.Monto     = 5000;
            Factura.RFC       = "SOSOSM8777878";
            Factura.Direccion = "NORTE 45 455 B";

            //LLENAR OBJETOS DETALLE FACTURA
            List <Entidades.EntFactura.DetalleFactura> ListDetalleFactura = new List <Entidades.EntFactura.DetalleFactura>();

            Entidades.EntFactura.DetalleFactura DetalleFactura = new Entidades.EntFactura.DetalleFactura();

            DetalleFactura.Producto = "Pantalon";
            DetalleFactura.Cantidad = 2;
            DetalleFactura.Importe  = 100;
            DetalleFactura.SubTotal = 90;
            DetalleFactura.Iva      = 10;
            DetalleFactura.Total    = 200;
            ListDetalleFactura.Add(DetalleFactura);

            DetalleFactura          = new Entidades.EntFactura.DetalleFactura();
            DetalleFactura.Producto = "Falda";
            DetalleFactura.Cantidad = 3;
            DetalleFactura.Importe  = 150;
            DetalleFactura.SubTotal = 400;
            DetalleFactura.Iva      = 50;
            DetalleFactura.Total    = 450;
            ListDetalleFactura.Add(DetalleFactura);

            DetalleFactura          = new Entidades.EntFactura.DetalleFactura();
            DetalleFactura.Producto = "Blusa";
            DetalleFactura.Cantidad = 1;
            DetalleFactura.Importe  = 50;
            DetalleFactura.SubTotal = 45;
            DetalleFactura.Iva      = 5;
            DetalleFactura.Total    = 50;
            ListDetalleFactura.Add(DetalleFactura);


            resultado = negFactura.GuardarFactura(Factura, ListDetalleFactura);

            return(Json(resultado, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public string GuardarFactura(Entidades.EntFactura.Factura Factura, List <Entidades.EntFactura.DetalleFactura> ListDetalleFactura)
        {
            string resultado = "";

            try
            {
                BaseDatos.BDFactura.BDFactura bdFactura = new BaseDatos.BDFactura.BDFactura();

                resultado = bdFactura.GuardarFactura(Factura, ListDetalleFactura);
            }
            catch (Exception ex)
            {
                resultado = "Error: " + ex.Message;
            }

            return(resultado);
        }
コード例 #3
0
        public string GuardarFactura(Entidades.EntFactura.Factura Factura, List <Entidades.EntFactura.DetalleFactura> ListDetalleFactura)
        {
            string resultado = "";

            try
            {
                using (var bd = new PruebaEntities())
                {
                    //var dos = bd.Factura;
                    using (var tran = new TransactionScope())
                    {
                        //dos.Add(Factura);
                        //var uno = bd.Factura;
                        //uno.Add(Factura);
                        bd.Factura.Add(Factura);
                        bd.SaveChanges();

                        ListDetalleFactura.ForEach(n =>
                        {
                            n.IdFactura = Factura.Id;
                            bd.DetalleFactura.Add(n);
                        });

                        bd.SaveChanges();

                        tran.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                resultado = "Error: " + ex.Message;
            }

            return(resultado);
        }