public PrestamosSemanas Buscar(int id) { Contexto contexto = new Contexto(); PrestamosSemanas prestamoSemana = new PrestamosSemanas(); try { var encontrado = contexto.PrestamosSemanas.Where(r => r.PrestamoSemId == id).Include(r => r.PrestamoSemDetalle).FirstOrDefault(); if (encontrado == null) { return(new PrestamosSemanas()); } if (encontrado.Accesibilidad == false) { return(new PrestamosSemanas()); } else { prestamoSemana = encontrado; } } catch (Exception) { throw; } finally { contexto.Dispose(); } return(prestamoSemana); }
private static bool Modificar(PrestamosSemanas prestamoSemana) { Contexto contexto = new Contexto(); bool modificar = false; try { contexto.Database.ExecuteSqlRaw($"Delete FROM PrestamosSemanasDetalle Where PrestamoSemId={prestamoSemana.PrestamoSemId}"); foreach (var item in prestamoSemana.PrestamoSemDetalle) { contexto.Entry(item).State = EntityState.Added; } contexto.Entry(prestamoSemana).State = EntityState.Modified; modificar = contexto.SaveChanges() > 0; } catch (Exception) { throw; } finally { contexto.Dispose(); } return(modificar); }
public bool Guardar(PrestamosSemanas PrestamoSemana) { if (Existe(PrestamoSemana.PrestamoSemId)) { return(Modificar(PrestamoSemana)); } else { return(Insertar(PrestamoSemana)); } }
private static bool Insertar(PrestamosSemanas prestamoSemana) { Contexto contexto = new Contexto(); bool guardar = false; try { contexto.PrestamosSemanas.Add(prestamoSemana); guardar = contexto.SaveChanges() > 0; } catch (Exception) { throw; } finally { contexto.Dispose(); } return(guardar); }
public ContenedorPrestamosSemanas() { prestamosSemanas = new PrestamosSemanas(); prestamosSemanasDetalle = new PrestamosSemanasDetalle(); listaPrestamosSemanas = new List <ListaPrestamosSemanas>(); }