Пример #1
0
 public User Get(string email)
 {
     using (var context = new PwContext())
     {
         return(context.Set <User>().FirstOrDefault(e => e.Email == email));
     };
 }
Пример #2
0
 public T Get(int id)
 {
     using (var context = new PwContext())
     {
         return(context.Set <T>().FirstOrDefault <T>(e => e.ID == id));
     }
 }
Пример #3
0
 public IEnumerable <T> GetAll()
 {
     using (var context = new PwContext())
     {
         var result = context.Set <T>().ToList();
         return(result);
     }
 }
Пример #4
0
 public void Update(T entity)
 {
     using (var context = new PwContext())
     {
         context.Entry <T>(entity).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #5
0
 public void Create(T entity)
 {
     using (var context = new PwContext())
     {
         context.Set <T>().Add(entity);
         context.SaveChanges();
     }
 }
 public new void Create(Transaction entity)
 {
     using (var context = new PwContext())
     {
         context.Set <User>().Attach(entity.CorrespondentUser);
         context.Set <User>().Attach(entity.OwnerUser);
         context.Set <Transaction>().Add(entity);
         context.SaveChanges();
     }
 }
 public IEnumerable <Transaction> GetByUser(int userId)
 {
     using (var context = new PwContext())
     {
         var result = context.Set <Transaction>()
                      .Include("OwnerUser")
                      .Include("CorrespondentUser")
                      .Where(t => t.OwnerUser.ID == userId)
                      .ToList();
         return(result);
     }
 }
Пример #8
0
 public void Remove(int id)
 {
     using (var context = new PwContext())
     {
         var entity = context.Set <T>().FirstOrDefault(e => e.ID == id);
         if (entity != null)
         {
             context.Set <T>().Remove(entity);
             context.SaveChanges();
         }
     }
 }