public bool ValidarExistenciaDeNombreDeUsuarioYContraseña(string NombreDeUsuario, string Contraseña) { bool resultadoDeExistencia = false; AccesoADatos.Empleado empleadoLocalizado; using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { //System.IO.FileNotFoundException Unable to resolve assembly NodeloDeDatos.csdl try { empleadoLocalizado = context.Empleados.FirstOrDefault(empleado => empleado.NombreDeUsuario == NombreDeUsuario && empleado.Contraseña == Contraseña); } catch (System.Data.Entity.Core.EntityException e) { throw new InvalidOperationException(e.Message); } } if (empleadoLocalizado != null) { resultadoDeExistencia = true; } return(resultadoDeExistencia); }
public void Actualizar(Clases.Cliente cliente) { using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { Cliente clienteDb = context.Clientes.Find(cliente.Id); clienteDb.FechaDeModicacion = DateTime.Now; clienteDb.Nombre = cliente.Nombre; clienteDb.Telefono = cliente.Telefono; clienteDb.Comentarios = cliente.Comentario; List <Direcciones> direcciones = new List <Direcciones>(); foreach (string direccion in cliente.Direcciones) { Direcciones direccionTabla = new Direcciones { Direccion = direccion }; direcciones.Add(direccionTabla); } context.Direcciones.RemoveRange(clienteDb.Direcciones); clienteDb.Direcciones.Clear(); clienteDb.Direcciones = direcciones; context.SaveChanges(); } }
public void GuardarIngrediente(Clases.Ingrediente ingrediente) { ingrediente.FechaDeCreacion = DateTime.Now; ingrediente.FechaDeModificacion = DateTime.Now; ingrediente.Activo = true; using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { AccesoADatos.Ingrediente ingredienteDb = ConvertirDeLogicaADbParaGuardar(ingrediente); foreach (Clases.Componente componente in ingrediente.Componentes) { RelacionIngrediente componenteDB = new RelacionIngrediente(); componenteDB.Cantidad = componente.Cantidad; componenteDB.IngredienteHijo = context.Ingredientes.Find(componente.Ingrediente.Id); componenteDB.IngredientePadre = null; ingredienteDb.RelacionIngredientesHijo.Add(componenteDB); } context.Ingredientes.Add(ingredienteDb); if (!ValidarExistenciaDeIngrediente(ingredienteDb)) { context.SaveChanges(); } } }
public void CambiarEstadoPedidoCancelar(Clases.Pedido pedido) { using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { if (pedido.Estado != EstadoPedido.EnEspera || pedido.Estado != EstadoPedido.Completado || pedido.Estado != EstadoPedido.Realizado || pedido.Estado != EstadoPedido.Entregado) { AccesoADatos.Pedido pedidoDb = context.Pedidos.Find(pedido.Id); if (pedidoDb != null) { pedidoDb.Estado = 6; context.SaveChanges(); } else { throw new ArgumentException("Id no encontrada PedidoDAO.DarDeBaja"); } } else { throw new ArgumentException("El pedido ya se encuentra en un estado imposible de cancelar"); } } pedido.AumentarIngredientes(); }
public void Depuracion_Eliminar(string nombre) { using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { Platillo platillo = context.Platillos.FirstOrDefault(p => p.Nombre == nombre); context.Platillos.Remove(platillo); context.SaveChanges(); } }
public void Guardar(Clases.Mesa mesa) { AccesoADatos.Mesa mesaAGuardar = ConvertirMesaLogicaADatos(mesa); using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { context.Mesas.Add(mesaAGuardar); context.SaveChanges(); } }
public Clases.Producto CargarPorID(int id) { Producto producto = new Producto(); using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { producto = context.Productos.Find(id); } return(ConvertirProductoDatosALogica(producto)); }
public List <Clases.Iva> CargarTodos() { List <Iva> ivasDb = new List <Iva>(); using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { ivasDb = context.Ivas.ToList(); } return(ConvertirListaDatosALogica(ivasDb)); }
public Clases.Cliente CargarClientePorNumeroTelefonico(string numeroTelefonico) { Cliente cliente = new Cliente(); using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { cliente = context.Clientes.Include(c => c.Direcciones).Include(c => c.Cuenta).FirstOrDefault(c => c.Telefono == numeroTelefonico); } return(ConvertirClienteDatosALogica(cliente)); }
public void EditarPlatillo(Clases.Platillo Platillo) { Platillo.FechaDeModificacion = DateTime.Now; Platillo platilloDb; using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { platilloDb = context.Platillos.Include(x => x.PlatilloIngredientes.Select(i => i.Ingrediente)).FirstOrDefault(p => p.Id == Platillo.Id); platilloDb.Nombre = Platillo.Nombre; platilloDb.Precio = Platillo.Precio; platilloDb.FechaDeModificacion = Platillo.FechaDeModificacion; platilloDb.Activo = Platillo.Activo; platilloDb.Codigo = Platillo.Codigo; platilloDb.Notas = Platillo.Notas; platilloDb.Descripcion = Platillo.Descripcion; platilloDb.Imagen = Platillo.Imagen; foreach (Clases.Proporcion proporcion in Platillo.Proporciones) { if (proporcion.Id == 0) { PlatilloIngrediente platilloIngrediente = new PlatilloIngrediente { Cantidad = proporcion.Cantidad, Platillo = platilloDb, Ingrediente = context.Ingredientes.Find(proporcion.Ingrediente.Id) }; context.PlatilloIngrediente.Add(platilloIngrediente); } else { foreach (PlatilloIngrediente proporcionDB in platilloDb.PlatilloIngredientes) { if (proporcion.Id == proporcionDB.Id) { proporcionDB.Cantidad = proporcion.Cantidad; break; } } } } List <PlatilloIngrediente> proporcionesAEliminar = platilloDb.PlatilloIngredientes.Where(p => !Platillo.Proporciones.Any(p2 => p2.Id == p.Id)).ToList(); foreach (PlatilloIngrediente proporcion in proporcionesAEliminar) { context.PlatilloIngrediente.Remove(proporcion); } context.SaveChanges(); } }
public List <Clases.Ingrediente> CargarIngredientesActivos() { List <Ingrediente> ingredientesDb = new List <Ingrediente>(); using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { ingredientesDb = context.Ingredientes.Include(i => i.RelacionIngredientesHijo).Where(ingredienteCargado => ingredienteCargado.Activo == true).ToList(); } return(ConvertirListaDeDbAListaDeLogica(ingredientesDb)); }
public List <CantidadProducto> RecuperarPorIDPedido(int idPedido) { List <AccesoADatos.ProductoPedido> productoPedido = new List <AccesoADatos.ProductoPedido>(); using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { productoPedido = context.ProductoPedido.Where(p => p.Pedido.Id == idPedido) .Include(p => p.Productos).ToList(); } return(ConvertirListaDatosALogica(productoPedido)); }
public Clases.Cliente RecuperarClientePorIdCuenta(int idCuenta) { Cliente cliente = new Cliente(); using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { cliente = context.Clientes.FirstOrDefault(c => c.Cuenta.ToList().Exists(cuenta => cuenta.Id == idCuenta)); } return(ConvertirClienteDatosALogica(cliente)); }
public void ActualizarCuenta(Clases.Cuenta cuenta) { using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { Cuenta cuentaDb = context.Cuentas.Find(cuenta.Id); cuentaDb.Estado = (short)cuenta.Estado; cuentaDb.PrecioTotal = cuenta.PrecioTotal; //Actualizar pedidos context.SaveChanges(); } }
public List <Clases.Mesa> ObtenerMesasPorEstado(EstadoMesa estado) { List <AccesoADatos.Mesa> mesas; using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { mesas = context.Mesas.Where(m => m.Estado == (short)estado).ToList(); } return(ConvertirListaDeMesasDatosALogica(mesas)); }
public List <Clases.Pedido> CargarPedidosEnEspera() { List <AccesoADatos.Pedido> EnProceso = new List <AccesoADatos.Pedido>(); using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { EnProceso = context.Pedidos.Where(p => p.Estado == (short)EstadoPedido.EnEspera).Include(p => p.Cuenta).ToList(); } List <Clases.Pedido> Proceso = ConvertirListaDeDatosALogica(EnProceso); return(Proceso); }
public Clases.Ingrediente CargarIngredientePorId(int Id) { Ingrediente ingredienteDb = new Ingrediente(); using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { ingredienteDb = context.Ingredientes.Include(i => i.RelacionIngredientesHijo).FirstOrDefault(i => i.Id == Id); } Clases.Ingrediente ingredienteResultado = ConvertirDeDatosALogica(ingredienteDb); return(ingredienteResultado); }
public void GenerarRespaldo(string nombreUsuario, string ruta) { if (string.IsNullOrEmpty(ruta)) { throw new InvalidOperationException("ruta es null"); } if (!ruta.EndsWith("\\")) { ruta += "\\"; } ValidarDirectorio(); string backupname = DateTime.Now.ToString("MM-dd-yyyy_HH-mm") + "_" + nombreUsuario + ".bak"; ruta += backupname; string connection; string databaseName; using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { connection = context.Database.Connection.ConnectionString; databaseName = context.Database.Connection.Database; } if (!string.IsNullOrEmpty(connection) && !string.IsNullOrEmpty(databaseName)) { SqlConnection con = new SqlConnection(connection); con.FireInfoMessageEventOnUserErrors = true; con.InfoMessage += OnInfoMessage; con.Open(); using (var cmd = new SqlCommand(string.Format( @"BACKUP DATABASE {0} TO DISK = N{1} WITH STATS = 10", QuoteIdentifier(databaseName), QuoteString("/tmp/" + backupname)), con)) { cmd.ExecuteNonQuery(); } con.Close(); con.InfoMessage -= OnInfoMessage; con.FireInfoMessageEventOnUserErrors = false; } System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = "cmd.exe"; startInfo.Arguments = "/C docker cp sql1:/tmp/" + backupname + " " + ruta.Replace("\\", @"\"); process.StartInfo = startInfo; process.Start(); }
public bool ValidarExistenciaDeNombreDeUsuario(string NombreDeUsuario) { List <AccesoADatos.Empleado> empleadosContext; using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { empleadosContext = context.Empleados.ToList(); } bool resultadoDeExistencia = empleadosContext.Exists(usuario => usuario.NombreDeUsuario == NombreDeUsuario); return(resultadoDeExistencia); }
public Clases.Platillo CargarPlatilloPorId(int IdPlatillo) { Platillo platilloDb = new Platillo(); using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { platilloDb = context.Platillos.Find(IdPlatillo); } Clases.Platillo platilloResultado = ConvertirDatosALogica(platilloDb); return(platilloResultado); }
public Clases.Ingrediente RecuperarIngredientePorCodigo(string codigo) { Ingrediente ingredienteDb = new Ingrediente(); using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { ingredienteDb = context.Ingredientes.Include(i => i.RelacionIngredientesHijo).FirstOrDefault(i => i.Codigo == codigo); } Clases.Ingrediente ingredienteResultado = ConvertirDeDatosALogica(ingredienteDb); return(ingredienteResultado); }
public void GuardarEmpleado(Clases.Empleado empleado) { empleado.Activo = true; empleado.FechaDeCreacion = DateTime.Now; empleado.FechaDeModicacion = DateTime.Now; AccesoADatos.Empleado empleadoguardado = ConvertirDeLogicaADatos(empleado); using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { context.Empleados.Add(empleadoguardado); context.SaveChanges(); } }
public List <Clases.Pedido> CargarRecientes() { List <AccesoADatos.Pedido> Pendiente = new List <AccesoADatos.Pedido>(); using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { Pendiente = context.Pedidos.Where(p => p.Estado == (short)EstadoPedido.EnEspera || p.Estado == (short)EstadoPedido.EnPreparacion || p.Estado == (short)EstadoPedido.Enviado || p.Estado == (short)EstadoPedido.Realizado).Include(p => p.Cuenta).Include(p => p.Cuenta.Clientes).ToList(); } List <Clases.Pedido> pedidoL = ConvertirListaDeDatosALogica(Pendiente); return(pedidoL); }
public Clases.Producto CargarProductoPorID(int id) { Producto productoDb = new Producto(); using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { productoDb = context.Productos.Find(id); } Clases.Producto productoResultado = ConvertirProductoDatosALogica(productoDb); return(productoResultado); }
public void CambiarEstadoPorID(int idMesa, EstadoMesa nuevoEstado) { using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { AccesoADatos.Mesa mesa = context.Mesas.Find(idMesa); if (mesa != null) { mesa.Estado = (short)nuevoEstado; } context.SaveChanges(); } }
public void Guardar(Clases.Cliente cliente) { Cliente clienteDb = ConvertirClienteLogicaADatos(cliente); clienteDb.Activo = true; clienteDb.FechaDeCreacion = DateTime.Now; clienteDb.FechaDeModicacion = DateTime.Now; using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { context.Clientes.Add(clienteDb); context.SaveChanges(); } }
public List <Clases.Platillo> CargarTodos() { List <Platillo> alimentosDb = new List <Platillo>(); using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { alimentosDb = context.Platillos.ToList(); } List <Clases.Platillo> alimentosResultado = ConvertirListaDeDatosAListaDeLogica(alimentosDb); return(alimentosResultado); }
private bool ValidarExistenciaDeIngrediente(Ingrediente ingredienteDb) { bool resultado = false; using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { if (context.Ingredientes.ToList().Exists(i => i.Codigo == ingredienteDb.Codigo) && context.Ingredientes.ToList().Exists(i => i.Codigo == ingredienteDb.CodigoDeBarras)) { resultado = true; } } return(resultado); }
public List <Clases.Mesa> RecuperarTodos() { List <AccesoADatos.Mesa> mesas; using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { mesas = context.Mesas.ToList(); } List <Clases.Mesa> mesasresultado = new List <Clases.Mesa>(); mesasresultado = ConvertirListaDeMesasDatosALogica(mesas); return(mesasresultado); }
public List <Clases.Cliente> CargarTodosActivos() { List <Cliente> clientes = new List <Cliente>(); using (ModeloDeDatosContainer context = new ModeloDeDatosContainer()) { clientes = context.Clientes.Where(c => c.Activo == true) .Include(c => c.Direcciones) .Include(c => c.Cuenta) .ToList(); } return(ConvertirListaDeDatosALogica(clientes)); }