public async Task Put <T>(T entity) where T : IEntity { await Task.Run(() => { using var db = new LiteDB.LiteRepository(_connectionString); db.Update(entity); }); }
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); }); }
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(); })); }
public async Task Post <T>(T entity) { await Task.Run(() => { using var db = new LiteDB.LiteRepository(_connectionString); db.Insert(entity); }); }
public async Task <IEnumerable <T> > Get <T>() { return(await Task.Run(() => { using var db = new LiteDB.LiteRepository(_connectionString); return db.Query <T>().ToList(); })); }
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(); })); }
/// <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; } } }
/// <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; } } }
/// <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; } } }
public void Create(Customer customer) { using (var repo = new LiteDB.LiteRepository(ConnectionString)) { try { repo.Insert(customer); } catch (DbException e) { throw e; } } }
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(); })); }
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); }