Esempio n. 1
0
 public void Delete(int id)
 {
     using (InjectorDatabase dbContext = new InjectorDatabase())
     {
         var entity = dbContext.Set <TDb>().FirstOrDefault(n => n.Id == id);
         if (entity != null)
         {
             dbContext.Set <TDb>().Remove(entity);
             dbContext.SaveChanges();
         }
     }
 }
Esempio n. 2
0
 public IEnumerable <T> GetAll()
 {
     using (InjectorDatabase dbContext = new InjectorDatabase())
     {
         return(dbContext.Set <TDb>().ToList().Select(entity => entity.MapToEntity <TDb, T>()).ToList());
     }
 }
Esempio n. 3
0
 public void Update(T element)
 {
     using (InjectorDatabase dbContext = new InjectorDatabase())
     {
         var entity = dbContext.Set <TDb>().FirstOrDefault(n => n.Id == element.Id);
         entity?.CopyFieldsFrom(element);
         dbContext.SaveChanges();
     }
 }
Esempio n. 4
0
 public int Insert(T element)
 {
     using (InjectorDatabase dbContext = new InjectorDatabase())
     {
         var entity = dbContext.Set <TDb>().Add(element.MapToEntity <T, TDb>());
         dbContext.SaveChanges();
         return(entity.Id);
     }
 }
Esempio n. 5
0
 public T Get(int id)
 {
     using (InjectorDatabase dbContext = new InjectorDatabase())
     {
         var entity = dbContext.Set <TDb>().FirstOrDefault(n => n.Id == id);
         if (entity != null)
         {
             return(entity.MapToEntity <TDb, T>());
         }
         return(default(T));
     }
 }