public async Task <IActionResult> Edit(int id, [Bind("CodigoEmail,Email,CodigoProveedor")] EmailProveedor emailProveedor) { if (id != emailProveedor.CodigoEmail) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(emailProveedor); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmailProveedorExists(emailProveedor.CodigoEmail)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(emailProveedor)); }
public async Task <IActionResult> Create([Bind("CodigoEmail,Email,CodigoProveedor")] EmailProveedor emailProveedor) { if (ModelState.IsValid) { _context.Add(emailProveedor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(emailProveedor)); }
public void Execute(object parameter) { if (parameter.Equals("Add")) { this.IsReadOnlyEmail = false; this.IsReadOnlyCodigoProveedor = false; } if (parameter.Equals("Save")) { EmailProveedor parametro = new EmailProveedor(); parametro.Codigo_Proveedor = Convert.ToInt16(this.CodigoProveedor); parametro.Email = this.Email; db.EmailProveedores.Add(parametro); db.SaveChanges(); this.EmailProveedores.Add(parametro); MessageBox.Show("Registro Almacenado"); } }
public void Execute(object parameter) { if (parameter.Equals("Add")) { this.IsReadOnlyEmail = false; this.IsReadOnlyCodigoProveedor = false; this.accion = ACCION.NUEVO; } if (parameter.Equals("Save")) { switch (this.accion) { case ACCION.NUEVO: EmailProveedor nuevo = new EmailProveedor(); nuevo.Email = this.Email; nuevo.CodigoProveedor = Convert.ToInt16(this.CodigoProveedor); db.EmailProveedores.Add(nuevo); db.SaveChanges(); this.EmailProveedores.Add(nuevo); MessageBox.Show("Registro Almacenado"); break; case ACCION.ACTUALIZAR: try { int posicion = this.EmailProveedores.IndexOf(this.SeleccionarEmailProveedor); var updateEmailProveedor = this.db.EmailProveedores.Find(this.SeleccionarEmailProveedor.CodigoEmail); updateEmailProveedor.Email = this.Email; updateEmailProveedor.CodigoProveedor = Convert.ToInt16(this.CodigoProveedor); this.db.Entry(updateEmailProveedor).State = EntityState.Modified; this.db.SaveChanges(); this.EmailProveedores.RemoveAt(posicion); this.EmailProveedores.Insert(posicion, updateEmailProveedor); MessageBox.Show("Registro Actualizado!!!"); } catch (Exception e) { MessageBox.Show(e.Message); } break; } } else if (parameter.Equals("Delete")) { if (this.SeleccionarEmailProveedor != null) { var respuesta = MessageBox.Show("Esta seguro de eliminar el registro?", "Eliminar", MessageBoxButton.YesNo); if (respuesta == MessageBoxResult.Yes) { try { db.EmailProveedores.Remove(this.SeleccionarEmailProveedor); db.SaveChanges(); this.EmailProveedores.Remove(this.SeleccionarEmailProveedor); } 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.IsReadOnlyEmail = false; this.IsReadOnlyCodigoProveedor = false; this.accion = ACCION.NUEVO; this.IsEnabledAdd = false; this.IsEnabledCancel = true; this.IsEnabledDelete = false; this.IsEnabledSave = true; this.IsEnabledUpdate = false; } else if (parameter.Equals("Save")) { switch (this.accion) { case ACCION.NUEVO: EmailProveedor nuevo = new EmailProveedor(); nuevo.email = this.email; nuevo.codigoProveedor = this.codigoProveedor; db.EmailProveedores.Add(nuevo); db.SaveChanges(); this.EmailProveedor.Add(nuevo); MessageBox.Show("Registro almacenado correctamente"); this.IsReadOnlyEmail = true; this.IsReadOnlyCodigoProveedor = true; this.IsEnabledAdd = true; this.IsEnabledCancel = true; this.IsEnabledDelete = true; this.IsEnabledSave = true; this.IsEnabledUpdate = true; this.email = ""; break; case ACCION.ACTUALIZAR: try { int posicion = this.EmailProveedor.IndexOf(this.SelectEmailProveedor); var updateEmail = this.db.EmailProveedores.Find(this.SelectEmailProveedor.codigoEmail); updateEmail.email = this.email; updateEmail.codigoProveedor = this.codigoProveedor; this.db.Entry(updateEmail).State = System.Data.Entity.EntityState.Modified; this.db.SaveChanges(); this.EmailProveedor.RemoveAt(posicion); this.EmailProveedor.Insert(posicion, updateEmail); MessageBox.Show("Registro actualizado"); } catch (Exception e) { MessageBox.Show(e.Message); } break; } } else if (parameter.Equals("Delete")) { if (this.SelectEmailProveedor != null) { var respuesta = MessageBox.Show("¿Está seguro de eliminar el registro?", "Eliminar", MessageBoxButton.YesNo); if (respuesta == MessageBoxResult.Yes) { try { db.EmailProveedores.Remove(this.SelectEmailProveedor); db.SaveChanges(); this.EmailProveedor.Remove(this.SelectEmailProveedor); } 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.IsReadOnlyEmail = false; this.IsReadOnlyCodigoProveedor = false; } else if (parameter.Equals("Cancel")) { this.IsReadOnlyEmail = true; this.IsReadOnlyCodigoProveedor = true; this.IsEnabledAdd = true; this.IsEnabledCancel = true; this.IsEnabledDelete = true; this.IsEnabledSave = true; this.IsEnabledUpdate = true; this.email = ""; } }