Beispiel #1
0
 public async Task Put <T>(T entity) where T : IEntity
 {
     await Task.Run(() =>
     {
         using var db = new LiteDB.LiteRepository(_connectionString);
         db.Update(entity);
     });
 }
Beispiel #2
0
 public async Task Delete <T>(Guid id) where T : IEntity
 {
     await Task.Run(() =>
     {
         using var db = new LiteDB.LiteRepository(_connectionString);
         db.Delete <T>(e => e.Id == id);
     });
 }
Beispiel #3
0
 public async Task <IEnumerable <T> > Get <T>(Expression <Func <T, bool> > predicate)
 {
     return(await Task.Run(() =>
     {
         using var db = new LiteDB.LiteRepository(_connectionString);
         return db.Query <T>().Where(predicate).ToList();
     }));
 }
Beispiel #4
0
 public async Task Post <T>(T entity)
 {
     await Task.Run(() =>
     {
         using var db = new LiteDB.LiteRepository(_connectionString);
         db.Insert(entity);
     });
 }
Beispiel #5
0
 public async Task <IEnumerable <T> > Get <T>()
 {
     return(await Task.Run(() =>
     {
         using var db = new LiteDB.LiteRepository(_connectionString);
         return db.Query <T>().ToList();
     }));
 }
Beispiel #6
0
        public async Task <T> Get <T>(Guid id, bool isNullable = true) where T : IEntity
        {
            return(await Task.Run(() =>
            {
                using var db = new LiteDB.LiteRepository(_connectionString);
                if (isNullable)
                {
                    return db.Query <T>().Where(e => e.Id == id).FirstOrDefault();
                }

                return db.Query <T>().Where(e => e.Id == id).Single();
            }));
        }
Beispiel #7
0
 /// <summary>
 /// Deletes customer from database by id.
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public bool Delete(Guid id)
 {
     using (var repo = new LiteDB.LiteRepository(ConnectionString))
     {
         try
         {
             return(repo.Delete <Customer>(id));
         }
         catch (DbException e)
         {
             throw e;
         }
     }
 }
Beispiel #8
0
 /// <summary>
 /// Updates customer information to database.
 /// </summary>
 /// <param name="customer"></param>
 /// <returns></returns>
 public bool Update(Customer customer)
 {
     using (var repo = new LiteDB.LiteRepository(ConnectionString))
     {
         try
         {
             return(repo.Update(customer));
         }
         catch (DbException e)
         {
             throw e;
         }
     }
 }
Beispiel #9
0
 /// <summary>
 /// Find customer from database by id.
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public Customer Read(Guid id)
 {
     using (var repo = new LiteDB.LiteRepository(ConnectionString))
     {
         try
         {
             return(repo.Query <Customer>().Where(x => x.Id == id).First());
         }
         catch (DbException e)
         {
             throw e;
         }
     }
 }
Beispiel #10
0
 public void Create(Customer customer)
 {
     using (var repo = new LiteDB.LiteRepository(ConnectionString))
     {
         try
         {
             repo.Insert(customer);
         }
         catch (DbException e)
         {
             throw e;
         }
     }
 }
Beispiel #11
0
        public async Task <T> Get <T>(Expression <Func <T, bool> > predicate, bool isNullable)
        {
            if (isNullable)
            {
                return(await Task.Run(() =>
                {
                    using var db = new LiteDB.LiteRepository(_connectionString);
                    return db.Query <T>().Where(predicate).FirstOrDefault();
                }));
            }

            return(await Task.Run(() =>
            {
                using var db = new LiteDB.LiteRepository(_connectionString);
                return db.Query <T>().Where(predicate).Single();
            }));
        }
Beispiel #12
0
 public void Salva(MenssagerLogEvent logEvent)
 {
     using (LiteDB.LiteRepository repository = new LiteDB.LiteRepository(this.Path))
     {
         try
         {
             lock (block)
             {
                 repository.Upsert(entity: logEvent);
             }
         }
         catch (System.Exception w)
         {
             throw w;
         }
     }
 }
 public LiteRepositoryFixture()
 {
     _stream  = new MemoryStream();
     Instance = new LiteDB.LiteRepository(_stream);
 }