public int EliminarPromotoresZona(PromotorZona pPromotorZona)
        {
            PromotorZona tmpPromotorZona = BuscarPromotoresZona(pPromotorZona);

            BDComun.Contexto.PromotorZonas.Remove(tmpPromotorZona);
            return BDComun.Contexto.SaveChanges();
        }
        private void txtProZona_TextChanged(object sender, TextChangedEventArgs e)
        {
            PromotorZona _promzona = new PromotorZona();
            _promzona.Promotore = _promB;

            dgPromotorZona.ItemsSource = _promzBL.ObtenerPromotoresZonaPorNombre(_promzona);
        }
        public int ModificarPromotoresZona(PromotorZona pPromotorZona)
        {
            PromotorZona tmpPromotorZona = BuscarPromotoresZona(pPromotorZona);
            tmpPromotorZona.Id = pPromotorZona.Id;
            tmpPromotorZona.Actividade = pPromotorZona.Actividade;
            tmpPromotorZona.ADESCO = pPromotorZona.ADESCO;
            tmpPromotorZona.Promotore = pPromotorZona.Promotore;
            tmpPromotorZona.Proyecto = pPromotorZona.Proyecto;
            tmpPromotorZona.Zona = pPromotorZona.Zona;

            return BDComun.Contexto.SaveChanges();
        }
        private void btnGuardar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtProyecto.Text == string.Empty)
                {
                    MessageBox.Show("Llene el campo proyecto");
                }
                if (txtPromotor.Text == string.Empty)
                {
                    MessageBox.Show("Llene el campo promotor");
                }
                if (txtZona.Text == string.Empty)
                {
                    MessageBox.Show("Llene el campo zona");
                }
                if (txtActividad.Text == string.Empty)
                {
                    MessageBox.Show("Llene el campo actividad");
                }
                if (txtAdesco.Text == string.Empty)
                {
                    MessageBox.Show("Llene el campo adesco");
                }
                if (!(txtProyecto.Text == string.Empty || txtPromotor.Text == string.Empty || txtZona.Text == string.Empty || txtActividad.Text == string.Empty || txtAdesco.Text == string.Empty))
                {
                    PromotorZona _promzona = new PromotorZona();
                    _promzona.Proyecto = _proyectoB;
                    _promzona.Promotore = _promotorB;
                    _promzona.Zona = _zonaB;
                    _promzona.Actividade = _actividadB;
                    _promzona.ADESCO = _adescoB;

                    if (_promZonBL.AgregaPromotoresZona(_promzona) > 0)
                    {
                        MessageBox.Show("El registro se agregó con éxito");
                        Actualizar();
                    }
                    else
                    {
                        MessageBox.Show("El registro no pudo ser agregado");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("No se pudo agregar el registro" + "Advertencia" + ex.Message);
            }
        }
        private void btnConsultar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                BuscarPromotorZona _bus = new BuscarPromotorZona();
                _bus.ShowDialog();

                _promzEntity = _bus.PromzE;
                txtId.Text = _promzEntity.Id.ToString();
                txtProyecto.Text = _proyectoB.Nombre;
                txtPromotor.Text = _promotorB.Nombre;
                txtZona.Text = _zonaB.Nombre;
                txtActividad.Text = _actividadB.Nombre;
                txtAdesco.Text = _adescoB.Nombre;

                txtProyecto.IsEnabled = false;
                txtPromotor.IsEnabled = false;
                txtZona.IsEnabled = false;
                txtActividad.IsEnabled = false;
                txtAdesco.IsEnabled = false;
                btnNuevo.IsEnabled = false;
                btnGuardar.IsEnabled = false;
                btnModificar.IsEnabled = true;
                btnEliminar.IsEnabled = true;
                btnBusProyecto.IsEnabled = true;
                btnBusPromotor.IsEnabled = true;
                btnBusZona.IsEnabled = true;
                btnBusActividad.IsEnabled = true;
                btnBusAdesco.IsEnabled = true;
                btnConsultar.IsEnabled = true;
                btnSalir.IsEnabled = true;
            }
            catch
            {
            }
        }
 public List<PromotorZona> ObtenerPromotoresZonaPorNombre(PromotorZona pPromotorZona)
 {
     return BDComun.Contexto.PromotorZonas.Where(p => p.Promotore.Nombre.Contains(pPromotorZona.Promotore.Nombre)).ToList();
 }
 public PromotorZona BuscarPromotoresZona(PromotorZona pPromotorZona)
 {
     return BDComun.Contexto.PromotorZonas.SingleOrDefault(c => c.Id == pPromotorZona.Id);
 }
        public int AgregaPromotoresZona(PromotorZona pPromotorZona)
        {
            BDComun.Contexto.PromotorZonas.Add(pPromotorZona);

            return BDComun.Contexto.SaveChanges();
        }
 private void dgPromotorZona_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     PromzE = dgPromotorZona.SelectedItem as PromotorZona;
     DialogResult = true;
 }