Exemplo n.º 1
0
 public BindableCollection <T> GetList <T>() where T : class
 {
     using (QLTVEntities db = new QLTVEntities())
     {
         return(new BindableCollection <T>(db.Set <T>().ToList()));
     }
 }
Exemplo n.º 2
0
 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);
     }
 }
Exemplo n.º 3
0
 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());
     }
 }
Exemplo n.º 4
0
 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);
         }
     }
 }
Exemplo n.º 5
0
 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);
         }
     }
 }
Exemplo n.º 6
0
 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);
         }
     }
 }