Пример #1
0
 public EN.Factura GetFactura(int id)
 {
     try
     {
         BR.Factura fac = db.Factura.Where(x => x.idFactura == id).FirstOrDefault();
         AutoMapper.Mapper.CreateMap <BR.Factura, EN.Factura>();
         EN.Factura fact = AutoMapper.Mapper.Map <EN.Factura>(fac);
         return(fact);
     }
     catch (Exception)
     {
         throw;
     }
 }
Пример #2
0
        public bool Crear(EN.Factura other)
        {
            bool resultado = false;

            try
            {
                BR.Factura fact = new BR.Factura();
                fact.idCliente    = 789012;
                fact.descuento    = other.descuento;
                fact.FechaFactura = other.FechaFactura;
                fact.montoFinal   = other.montoFinal;
                db.Factura.Add(fact);
                db.SaveChanges();

                //Al annaidr una factura debemos annadir un detalleFactura y disminuir el Stock
                //Consulta del id de la factura asociada al cliente
                //var consulta = from fac in db.Factura
                //               where (fac.Cliente == fact.Cliente && fac.FechaFactura == fact.FechaFactura)
                //               select new { fac.idFactura };

                //foreach (var item in consulta)
                //{
                //    factura.idFactura = item.idFactura;
                //}

                //for (int i = 0; i < factura.DetallesFactura.Count; i++)
                //{
                //    BR.DetalleFactura detalleFactura = new BR.DetalleFactura();
                //    detalleFactura.idFactura = factura.idFactura;
                //    detalleFactura.idProducto = factura.DetallesFactura[i].idProducto;
                //    detalleFactura.cantidad = factura.DetallesFactura[i].cantidad;

                //    BR.Productos producto = db.Productos.Find(factura.DetallesFactura[i].idProducto);
                //    producto.stock = producto.stock - factura.DetallesFactura[i].cantidad;

                //    db.DetalleFactura.Add(detalleFactura);
                //    db.SaveChanges();
                //}


                resultado = true;
            }
            catch (Exception)
            {
                throw;
            }
            return(resultado);
        }