Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using ADSProjectLab.Models;
- using ADSProjectLab.Models.Context;
- using System;
- using System.Collections.Generic;
- using System.Data.Entity;
- using System.Linq;
- using System.Web;
- namespace ADSProjectLab.DAL
- {
- public class EstudianteDAL
- {
- private MyDbContext _context;
- public EstudianteDAL(MyDbContext context)
- {
- _context = context;
- }
- // Se listan todos los Estudiantes
- public List<Estudiante> ObtenerTodos()
- {
- try
- {
- var listado = _context.Estudiante.ToList();
- return listado;
- }
- catch (Exception)
- {
- throw;
- }
- }
- // Se listan todos los Estudiantes
- public List<Estudiante> ObtenerTodos(string[] includes)
- {
- try
- {
- var listado = _context.Estudiante.AsQueryable();
- foreach (var include in includes)
- {
- listado = listado.Include(include);
- }
- return listado.ToList();
- }
- catch (Exception)
- {
- throw;
- }
- }
- // Se busca el Estudiante
- public Estudiante ObtenerById(int Id)
- {
- try
- {
- var item = _context.Estudiante.SingleOrDefault(x => x.Id == Id);
- return item;
- }
- catch (Exception ex)
- {
- throw;
- }
- }
- // Se inserta el Estudiante
- public int Insertar(Estudiante model)
- {
- try
- {
- _context.Estudiante.Add(model);
- _context.SaveChanges();
- return model.Id;
- }
- catch (Exception ex)
- {
- throw;
- }
- }
- // Se modifica el Estudiante
- public int Modificar(int Id, Estudiante model)
- {
- try
- {
- var currentItem = _context.Estudiante.SingleOrDefault(x => x.Id == Id);
- _context.Entry(currentItem).CurrentValues.SetValues(model);
- _context.SaveChanges();
- return model.Id;
- }
- catch (Exception ex)
- {
- throw;
- }
- }
- // Se elimina el Estudiante
- public bool Eliminar(int Id)
- {
- try
- {
- var item = _context.Estudiante.SingleOrDefault(x => x.Id == Id);
- _context.Estudiante.Remove(item);
- _context.SaveChanges();
- return true;
- }
- catch (Exception ex)
- {
- throw;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement