public async Task <IActionResult> Edit(int id, [Bind("CodigoTelefono,NumeroTelefono,Descripcion,CodigoProveedor")] TelefonoProveedor telefonoProveedor)
        {
            if (id != telefonoProveedor.CodigoTelefono)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(telefonoProveedor);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TelefonoProveedorExists(telefonoProveedor.CodigoTelefono))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(telefonoProveedor));
        }
        public async Task <IActionResult> Create([Bind("CodigoTelefono,NumeroTelefono,Descripcion,CodigoProveedor")] TelefonoProveedor telefonoProveedor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(telefonoProveedor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(telefonoProveedor));
        }
Beispiel #3
0
 public void Execute(object parameter)
 {
     if (parameter.Equals("Add"))
     {
         this.IsReadOnlyCodigoProveedor = false;
         this.IsReadOnlyCodigoTelefono  = false;
         this.IsReadOnlyDescripcion     = false;
         this.IsReadOnlyNumero          = false;
     }
     if (parameter.Equals("Save"))
     {
         TelefonoProveedor parametro = new TelefonoProveedor();
         parametro.Codigo_Telefono  = Convert.ToInt16(this.CodigoTelefono);
         parametro.Numero           = this.Numero;
         parametro.Descripcion      = this.Descripcion;
         parametro.Codigo_Proveedor = Convert.ToInt16(this.CodigoProveedor);
         db.TelefonoProveedores.Add(parametro);
         db.SaveChanges();
         this.TelefonoProveedores.Add(parametro);
         MessageBox.Show("Registro Almacenado");
     }
     /*throw new NotImplementedException();*/
 }
Beispiel #4
0
        public void Execute(object parameter)
        {
            if (parameter.Equals("Add"))
            {
                this.IsReadOnlyNumero          = false;
                this.IsReadOnlyDescripcion     = false;
                this.IsReadOnlyCodigoProveedor = false;
                this.accion = ACCION.NUEVO;
            }
            if (parameter.Equals("Save"))
            {
                switch (this.accion)
                {
                case ACCION.NUEVO:
                    TelefonoProveedor nuevo = new TelefonoProveedor();
                    nuevo.Numero          = this.Numero;
                    nuevo.Descripcion     = this.Descripcion;
                    nuevo.CodigoProveedor = Convert.ToInt16(this.CodigoProveedor);
                    db.TelefonoProveedores.Add(nuevo);
                    db.SaveChanges();
                    this.TelefonoProveedores.Add(nuevo);
                    MessageBox.Show("Registro Almacenado");
                    break;

                case ACCION.ACTUALIZAR:
                    try
                    {
                        int posicion = this.TelefonoProveedores.IndexOf(this.SeleccionarTelefonoProveedor);
                        var updateTelefonoProveedor = this.db.TelefonoProveedores.Find(this.SeleccionarTelefonoProveedor.CodigoTelefono);
                        updateTelefonoProveedor.Numero               = this.Numero;
                        updateTelefonoProveedor.Descripcion          = this.Descripcion;
                        updateTelefonoProveedor.CodigoProveedor      = Convert.ToInt16(this.CodigoProveedor);
                        this.db.Entry(updateTelefonoProveedor).State = EntityState.Modified;
                        this.db.SaveChanges();
                        this.TelefonoProveedores.RemoveAt(posicion);
                        this.TelefonoProveedores.Insert(posicion, updateTelefonoProveedor);
                        MessageBox.Show("Registro Actualizado!!!");
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }
                    break;
                }
            }
            else if (parameter.Equals("Delete"))
            {
                if (this.SeleccionarTelefonoProveedor != null)
                {
                    var respuesta = MessageBox.Show("Esta seguro de eliminar el registro?", "Eliminar", MessageBoxButton.YesNo);
                    if (respuesta == MessageBoxResult.Yes)
                    {
                        try
                        {
                            db.TelefonoProveedores.Remove(this.SeleccionarTelefonoProveedor);
                            db.SaveChanges();
                            this.TelefonoProveedores.Remove(this.SeleccionarTelefonoProveedor);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                        }
                        MessageBox.Show("Registro eliminado correctamente!!!");
                    }
                }
                else
                {
                    MessageBox.Show("Debe seleccionar un registro", "Eliminar", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
        public void Execute(object parameter)
        {
            if (parameter.Equals("Add"))
            {
                this.IsReadOnlyDescripcion = false;
                this.IsReadOnlyNumero      = false;
                this.accion          = ACCION.NUEVO;
                this.IsEnabledAdd    = false;
                this.IsEnabledCancel = true;
                this.IsEnabledDelete = false;
                this.IsEnabledSave   = true;
                this.IsEnabledUpdate = false;
                this.descripcion     = "";
                this.numero          = "";
            }
            else if (parameter.Equals("Save"))
            {
                switch (this.accion)
                {
                case ACCION.NUEVO:
                    TelefonoProveedor nuevo = new TelefonoProveedor();
                    nuevo.numero          = this.numero;
                    nuevo.descripcion     = this.descripcion;
                    nuevo.codigoProveedor = this.codigoProveedor;
                    db.TelefonoProveedores.Add(nuevo);
                    db.SaveChanges();
                    this.TelefonoProveedor.Add(nuevo);
                    MessageBox.Show("Registro almacenado correctamente");
                    this.IsReadOnlyNumero      = true;
                    this.IsReadOnlyDescripcion = true;
                    this.IsEnabledAdd          = true;
                    this.IsEnabledCancel       = true;
                    this.IsEnabledDelete       = true;
                    this.IsEnabledSave         = true;
                    this.IsEnabledUpdate       = true;
                    this.descripcion           = "";
                    this.numero = "";
                    break;

                case ACCION.ACTUALIZAR:
                    try
                    {
                        int posicion       = this.TelefonoProveedor.IndexOf(this.SelectTelefonoProveedor);
                        var updateTelefono = this.db.TelefonoProveedores.Find(this.SelectTelefonoProveedor.codigoTelefono);
                        updateTelefono.numero               = this.numero;
                        updateTelefono.descripcion          = this.descripcion;
                        updateTelefono.codigoProveedor      = this.codigoProveedor;
                        this.db.Entry(updateTelefono).State = System.Data.Entity.EntityState.Modified;
                        this.db.SaveChanges();
                        this.TelefonoProveedor.RemoveAt(posicion);
                        this.TelefonoProveedor.Insert(posicion, updateTelefono);
                        MessageBox.Show("Registro actualizado");
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }
                    break;
                }
            }
            else if (parameter.Equals("Delete"))
            {
                if (this.SelectTelefonoProveedor != null)
                {
                    var respuesta = MessageBox.Show("¿Está seguro de eliminar el registro?", "Eliminar", MessageBoxButton.YesNo);
                    if (respuesta == MessageBoxResult.Yes)
                    {
                        try
                        {
                            db.TelefonoProveedores.Remove(this.SelectTelefonoProveedor);
                            db.SaveChanges();
                            this.TelefonoProveedor.Remove(this.SelectTelefonoProveedor);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                        }
                        MessageBox.Show("Registro eliminado correctamente");
                    }
                }
                else
                {
                    MessageBox.Show("Debe seleccionar un registro", "Eliminar", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else if (parameter.Equals("Update"))
            {
                this.accion                = ACCION.ACTUALIZAR;
                this.IsReadOnlyNumero      = false;
                this.IsReadOnlyDescripcion = false;
            }
            else if (parameter.Equals("Cancel"))
            {
                this.IsReadOnlyNumero      = true;
                this.IsReadOnlyDescripcion = true;
                this.IsEnabledAdd          = true;
                this.IsEnabledCancel       = true;
                this.IsEnabledDelete       = true;
                this.IsEnabledSave         = true;
                this.IsEnabledUpdate       = true;
                this.numero      = "";
                this.descripcion = "";
            }
        }