public List<NegociosEmpresa> ObtenerNegociosSucursales(int idEmpresa, bool insertaSeleccion = false) { DbContext db = new DbContext(); List<NegociosEmpresa> result; try { db.ContextOptions.ProxyCreationEnabled = _proxy; result = db.NegociosEmpresa.Where(w => w.IdEmpresa == idEmpresa).ToList(); foreach (NegociosEmpresa negocio in result) { db.LoadProperty(negocio, "SucursalNegocio"); foreach (SucursalNegocio sucursal in negocio.SucursalNegocio) { db.LoadProperty(sucursal, "Colonias"); } } if(insertaSeleccion) result.Insert(0 , new NegociosEmpresa{IdNegocio = BusinessVariables.ComboBox.ValueMember, Nombre = BusinessVariables.ComboBox.DisplayMember}); } catch (Exception ex) { throw new Exception(ex.InnerException.Message); } finally { db.Dispose(); } return result; }
public Empresa ObtenerEmpresa() { Empresa result; DbContext db; try { db= new DbContext(); } catch (Exception ex) { throw new Exception(ex.Message); } try { result = db.Empresa.SingleOrDefault(); if (result != null) db.LoadProperty(result, "Colonias"); } catch (Exception ex) { throw new Exception(ex.InnerException.Message); } finally { db.Dispose(); } return result; }
public List<Producto> ObtenerProductos() { List<Producto> result = null; DbContext db = new DbContext(); try { result = db.Producto.ToList(); foreach (Producto producto in result) { db.LoadProperty(producto, "Categoria"); if (producto.Categoria != null) db.LoadProperty(producto.Categoria, "NegociosEmpresa"); } } catch (Exception ex) { throw new Exception(ex.Message); } return result; }
public List<Presentaciones> ObtenerPresentaciones(bool insertaSeleccion = false) { List<Presentaciones> result; DbContext db = new DbContext(); try { result = db.Presentaciones.ToList(); foreach (Presentaciones presentacion in result) { db.LoadProperty(presentacion, "UnidadMedida"); } if (insertaSeleccion) result.Insert(0, new Presentaciones { IdPresentacion = BusinessVariables.ComboBox.ValueMember, Descripcion = BusinessVariables.ComboBox.DisplayMember}); } catch (Exception ex) { throw new Exception(ex.Message); } finally { db.Dispose(); } return result; }