static internal IEnumerable <T> GetAll <T>(int pagSize, int pagCurrent) where T : class { using (ICPruebaEntities db = new ICPruebaEntities()) { return(db.Set <T>().ToList().Skip(pagCurrent - 1).Take(pagSize)); } }
public async Task <IEnumerable <T> > GetFilterAsync <T>(Expression <Func <T, bool> > filter) where T : class { using (ICPruebaEntities db = new ICPruebaEntities()) { return(await db.Set <T>().Where(filter).ToListAsync()); } }
IEnumerable <T> ObtenerRegistrosPeriodo <T>(string filtro = null, string sort = null) where T : class { var mapaValores = !string.IsNullOrEmpty(filtro) && filtro != "{}" ? (Dictionary <string, object>) new JavaScriptSerializer().Deserialize <object>(filtro) : new Dictionary <string, object>(); var mapaSort = new Dictionary <string, object>(); var listaSort = (!string.IsNullOrEmpty(sort) && sort != "[{}]" ? ((object[])new JavaScriptSerializer().Deserialize <object>(sort)).Cast <Dictionary <string, object> >().ToList() : new List <Dictionary <string, object> >()); if (listaSort.Count > 0) { listaSort.ForEach(l => mapaSort.Add(l["property"].ToString(), l["direction"])); } var propiedades = typeof(T).GetProperties().Where(p => p.CanWrite && p.CanWrite); var respuesta = db.Set <T>() as IQueryable <T>; foreach (var campo in mapaValores.Keys.Where(k => propiedades.Select(p => p.Name).Contains(k))) { respuesta = respuesta.FilterByValue(campo, mapaValores[campo]); } foreach (var campo in mapaSort.Keys.Where(k => propiedades.Select(p => p.Name).Contains(k))) { respuesta = mapaSort[campo].ToString() == "DESC" ? respuesta.OrderByPropertyDescending(campo) : respuesta.OrderByProperty(campo); } return(respuesta); }
public async Task <IEnumerable <T> > GetAllAsync <T>() where T : class { using (ICPruebaEntities db = new ICPruebaEntities()) { return(await db.Set <T>().ToListAsync()); } }
public void GuardarElementos <T>(IEnumerable <T> lista) where T : class { using (ICPruebaEntities db = new ICPruebaEntities()) { using (DbContextTransaction trans = db.Database.BeginTransaction()) { db.Configuration.AutoDetectChangesEnabled = false; foreach (var el in lista) { db.Set <T>().Add(el); } db.SaveChanges(); trans.Commit(); } } }