public BindableCollection <T> GetList <T>() where T : class { using (QLTVEntities db = new QLTVEntities()) { return(new BindableCollection <T>(db.Set <T>().ToList())); } }
public T GetItem <T>(Expression <Func <T, bool> > currentEntityFilter) where T : class { using (QLTVEntities db = new QLTVEntities()) { var current = db.Set <T>().FirstOrDefault(currentEntityFilter); return(current); } }
public T GetItemInclude <T>(Expression <Func <T, object> >[] includes) where T : class { using (QLTVEntities db = new QLTVEntities()) { var query = db.Set <T>().AsQueryable(); if (includes != null) { query = includes.Aggregate(query, (current, include) => current.Include(include)); } return(query.FirstOrDefault()); } }
public bool Delete <T>(Expression <Func <T, bool> > currentEntityFilter) where T : class { using (QLTVEntities db = new QLTVEntities()) { try { var current = db.Set <T>().FirstOrDefault(currentEntityFilter); if (current is null) { return(false); } db.Set <T>().Remove(current); db.SaveChanges(); return(true); } catch (Exception e) { MessageBox.Show(e.Message); return(false); } } }
public bool Create <T>(T dto) where T : class { using (QLTVEntities db = new QLTVEntities()) { try { db.Set <T>().Add(dto); db.SaveChanges(); return(true); } catch (Exception e) { MessageBox.Show(e.Message); return(false); } } }
public bool Update <T>(T dto, Expression <Func <T, bool> > currentEntityFilter) where T : class { using (QLTVEntities db = new QLTVEntities()) { try { var current = db.Set <T>().FirstOrDefault(currentEntityFilter); if (current is null) { return(false); } db.Entry(current).CurrentValues.SetValues(dto); db.SaveChanges(); return(true); } catch (Exception e) { return(false); } } }