public void insertarFactura(FacturaTO facturaTo) { using (context = new EmpresaEntities()) { var dateQuery = context.Database.SqlQuery <DateTime>("SELECT getdate()"); DateTime serverDate = dateQuery.AsEnumerable().First(); Factura facturaDAO = new Factura { Cliente = facturaTo.Cliente, Fecha_Hora = serverDate, Total = 0 }; context.Facturas.Add(facturaDAO); context.SaveChanges(); var query = from factura in context.Facturas select factura; List <FacturaTO> list = new List <FacturaTO>(); foreach (Factura factura in query) { facturaTo.Consecutivo = factura.Consecutivo; } } }
public void eliminarProducto(ProductoTO productoTO) { Boolean error = true; context = new EmpresaEntities(); var productoEliminar = from producto in context.Productoes where producto.ID_Producto == productoTO.Codigo select producto; foreach (var productDelete in productoEliminar) { error = false; context.Productoes.Remove(productDelete); } if (error) { throw new DbUpdateException(); } try { context.SaveChanges(); } catch (DbUpdateException e) { throw new Exception(); } }
public void eliminarCliente(ClienteTO clienteTO) { context = new EmpresaEntities(); Boolean error = true; var clienteEliminar = from cliente in context.Clientes where cliente.Cedula == clienteTO.Cedula select cliente; foreach (var clientDelete in clienteEliminar) { error = false; context.Clientes.Remove(clientDelete); } if (error) { throw new DbUpdateException(); } try { context.SaveChanges(); } catch (DbUpdateException e) { throw new Exception(); } }
public void actualizarCantidadProducto(int codigo, int cantidad) { context = new EmpresaEntities(); Producto productoDAO = (from producto in context.Productoes where producto.ID_Producto == codigo select producto).First(); productoDAO.Cantidad_Disponible = cantidad; context.SaveChanges(); }
public void actualizarTotalFactura(FacturaTO facturaTO) { context = new EmpresaEntities(); Factura factura = (from facturas in context.Facturas where facturas.Consecutivo == facturaTO.Consecutivo select facturas).First(); factura.Total = facturaTO.Total; context.SaveChanges(); }
public void actualizarProducto(ProductoTO productoTO) { context = new EmpresaEntities(); Producto productoDAO = (from producto in context.Productoes where producto.ID_Producto == productoTO.Codigo select producto).First(); productoDAO.Cantidad_Disponible = productoTO.CantidadInventario; productoDAO.Descripcion = productoTO.Descripcion; productoDAO.Precio_Unidad = productoTO.PrecioVenta; context.SaveChanges(); }
public void actualizarCliente(ClienteTO clienteTO) { context = new EmpresaEntities(); Cliente cliente = (from clientes in context.Clientes where clientes.Cedula == clienteTO.Cedula select clientes).First(); cliente.Nombre = clienteTO.Nombre; cliente.Apellido = clienteTO.Apellido; cliente.Correo = clienteTO.Correo; cliente.Telefono = clienteTO.Telefono; context.SaveChanges(); }
public void insertarCliente(ClienteTO cliente) { using (context = new EmpresaEntities()) { Cliente nuevoCliente = new Cliente { Cedula = cliente.Cedula, Nombre = cliente.Nombre, Apellido = cliente.Apellido, Correo = cliente.Correo, Telefono = cliente.Telefono }; context.Clientes.Add(nuevoCliente); context.SaveChanges(); } }
public void insertarProducto(ProductoTO productoTO) { using (context = new EmpresaEntities()) { Producto productoDAO = new Producto { Cantidad_Disponible = productoTO.CantidadInventario, Descripcion = productoTO.Descripcion, ID_Producto = productoTO.Codigo, Precio_Unidad = productoTO.PrecioVenta }; try { context.Productoes.Add(productoDAO); context.SaveChanges(); } catch (DbUpdateException e) { throw new DbUpdateException(); } } }
public void insertarDetalle(Detalles_FacturaTO detalleTO) { try { ProductoDAO productoDAO = new ProductoDAO(); using (context = new EmpresaEntities()) { Detalle_Factura detalleDAO = new Detalle_Factura { Factura = detalleTO.Consecutivo_Factura, Producto = detalleTO.Codigo_Producto, Cantidad = detalleTO.Cantidad }; ProductoTO productoTO = new ProductoTO(); productoTO.Codigo = detalleTO.Codigo_Producto; productoDAO.extraerProducto(productoTO); if (detalleTO.Cantidad == 0) { throw new Exception("La cantidad de un producto no puede ser 0"); } if (productoTO.CantidadInventario < detalleTO.Cantidad) { throw new Exception("Error, no hay suficientes productos para satisfcaer la demanda"); } context.Detalle_Factura.Add(detalleDAO); context.SaveChanges(); productoDAO.extraerProductoCantidad(detalleTO.Codigo_Producto, detalleTO.Cantidad); } } catch (Exception) { throw; } }