private proveedor GuardarProveedor(proveedor oProveedor) { try { using (BDSoftComputacionEntities bd = new BDSoftComputacionEntities()) { oProveedor.nombreEmpresa = oProveedor.nombreEmpresa.ToUpper(); bd.Entry(oProveedor).State = System.Data.Entity.EntityState.Added; bd.SaveChanges(); return(oProveedor); } } catch (Exception ex) { throw ex; } }
public double ActualizarValorUsd(double valorUSD) { try { using (BDSoftComputacionEntities bd = new BDSoftComputacionEntities()) { valorUSD oValor = bd.valorUSD.FirstOrDefault(); oValor.valorUSD1 = Convert.ToDecimal(valorUSD); bd.Entry(oValor).State = System.Data.Entity.EntityState.Modified; bd.SaveChanges(); return(Convert.ToDouble(oValor.valorUSD1)); } } catch (Exception) { throw; } }
private cliente ModificarCliente(cliente oCliente) { try { using (BDSoftComputacionEntities bd = new BDSoftComputacionEntities()) { oCliente.nombre = oCliente.nombre.ToUpper(); oCliente.apellido = oCliente.apellido.ToUpper(); bd.Entry(oCliente).State = System.Data.Entity.EntityState.Modified; bd.SaveChanges(); return(oCliente); } } catch (Exception ex) { throw ex; } }
private usuario GuardarUsuario(usuario oUsuario) { try { using (BDSoftComputacionEntities bd = new BDSoftComputacionEntities()) { oUsuario.nombre = oUsuario.nombre.ToUpper(); oUsuario.apellido = oUsuario.apellido.ToUpper(); bd.Entry(oUsuario).State = System.Data.Entity.EntityState.Added; bd.SaveChanges(); return(oUsuario); } } catch (Exception ex) { throw ex; } }
//Guardar de historial de productos. public string GuardarHistorialStock(int idProducto, int cantidad, string tipo) { try { using (BDSoftComputacionEntities bd = new BDSoftComputacionEntities()) { historialStock oHistorial = new historialStock(); oHistorial.cantidad = cantidad; oHistorial.idProducto = idProducto; oHistorial.tipo = tipo; oHistorial.fechaHora = System.DateTime.Now; bd.Entry(oHistorial).State = System.Data.Entity.EntityState.Added; bd.SaveChanges(); return("True"); } } catch (Exception ex) { throw ex; } }
public void EliminarSubcategoria(int idSubCategoria) { try { using (BDSoftComputacionEntities bd = new BDSoftComputacionEntities()) { subcategoria oSubcategoria = bd.subcategoria.Where(x => x.idSubCategoria == idSubCategoria).FirstOrDefault(); if (oSubcategoria.producto.Count == 0) { bd.subcategoria.Remove(oSubcategoria); bd.SaveChanges(); } else { throw new Exception(); } } } catch (Exception ex) { throw ex; } }
public bool CancelarVenta(int idVenta) { try { using (BDSoftComputacionEntities bd = new BDSoftComputacionEntities()) { // cambio el estado a la venta y le pongo el 0 el monto entregado venta oVenta = bd.venta.Where(x => x.idVenta == idVenta).FirstOrDefault(); decimal dMontoEntregado = Convert.ToDecimal(oVenta.entregado); oVenta.idEstado = 12; oVenta.entregado = 0; bd.Entry(oVenta).State = System.Data.Entity.EntityState.Modified; // si la venta tiene entregado y no es consumidor final if (dMontoEntregado >= 0 && oVenta.idCliente != null && oVenta.idCliente != 0) { // le agrego lo entregado como saldo al cliente cliente oCliente = bd.cliente.Where(x => x.idCliente == oVenta.idCliente).FirstOrDefault(); oCliente.saldo = oCliente.saldo + dMontoEntregado; bd.Entry(oCliente).State = System.Data.Entity.EntityState.Modified; // creo un detalle en DetallePago para guardar que se le cargó el saldo al cliente detallePago oDetallePago = new detallePago(); oDetallePago.entrega = dMontoEntregado; oDetallePago.fechaPago = DateTime.Now; oDetallePago.idVenta = oVenta.idVenta; oDetallePago.tipoPago = "VENTA CANCELADA"; oDetallePago.idMetodoPago = 1; bd.Entry(oDetallePago).State = System.Data.Entity.EntityState.Added; } bd.SaveChanges(); return(true); } } catch (Exception) { return(false); } }
private producto ModificarProducto(producto oProducto) { try { using (BDSoftComputacionEntities bd = new BDSoftComputacionEntities()) { oProducto.nombre = oProducto.nombre.ToUpper(); oProducto.estado = bd.estado.Where(x => x.idEstado == oProducto.idEstado).FirstOrDefault(); bd.Database.ExecuteSqlCommand("DELETE FROM proveedorXproducto WHERE idProducto = @id", new System.Data.SqlClient.SqlParameter("id", oProducto.idProducto)); foreach (proveedorXproducto oPxp in oProducto.proveedorXproducto.ToList()) { bd.Entry(oPxp).State = System.Data.Entity.EntityState.Added; } oProducto.proveedorXproducto.Clear(); bd.Entry(oProducto).State = System.Data.Entity.EntityState.Modified; bd.SaveChanges(); return(oProducto); } } catch (Exception ex) { throw ex; } }