//Metodo Modificar. private static bool Modificar(PrestamoMoras prestamoMoras) { Contexto contexto = new Contexto(); bool ok = false; try { contexto.Database.ExecuteSqlRaw($"Delete FROM MorasDetalle Where MoraId={prestamoMoras.MoraId}"); //foreach (var anterior in prestamoMoras.PrestamoMorasDetalle) { //contexto.Entry(anterior).State = EntityState.Added; } contexto.Entry(prestamoMoras).State = EntityState.Modified; ok = (contexto.SaveChanges() > 0); } catch (Exception) { throw; } finally { contexto.Dispose(); } return(ok); }
//Metodo Guardar. public static bool Guardar(PrestamoMoras prestamo) { if (!Existe(prestamo.MoraId)) { return(Insertar(prestamo)); } else { return(Modificar(prestamo)); } }
private void BuscarButton_Click(object sender, RoutedEventArgs e) { if (!ValidarBuscar()) { return; } PrestamoMoras moras = PrestamoMorasBLL.Buscar(int.Parse(MoraIdTextBox.Text)); prestamoMoras = moras; Refrescar(); }
//Metodo Buscar public static PrestamoMoras Buscar(int id) { Contexto contexto = new Contexto(); PrestamoMoras moras = new PrestamoMoras(); try { // moras = contexto.PrestamoMoras.Include(x => x.PrestamoMorasDetalle).Where(p => p.MoraId == id).SingleOrDefault(); } catch (Exception) { throw; } finally { contexto.Dispose(); } return(moras); }
//Metodo Insertar. private static bool Insertar(PrestamoMoras prestamoMoras) { Contexto contexto = new Contexto(); bool ok = false; try { if (contexto.PrestamoMoras.Add(prestamoMoras) != null) { ok = contexto.SaveChanges() > 0; } } catch (Exception) { throw; } finally { contexto.Dispose(); } return(ok); }
public void Limpiar() { this.prestamoMoras = new PrestamoMoras(); this.DataContext = prestamoMoras; }