using System.Collections.Generic; using iBoxDB.LocalServer; using Plugins.Countly.Persistance.Entities; namespace Plugins.iBoxDB { public class Dao where TEntity : class, IEntity, new() { protected readonly AutoBox Auto; protected readonly string Table; public Dao(AutoBox auto, string table) { Auto = auto; Table = table; } public bool Save(TEntity entity) { return Auto.Insert(Table, entity); } public bool Update(TEntity entity) { return Auto.Update(Table, entity); } public List LoadAll() { return Auto.Select("from " + Table); } public void Remove(params object[] key) { Auto.Delete(Table, key); } public void RemoveAll() { var list = Auto.Select("from " + Table); foreach (var entity in list) { Auto.Delete(Table, entity.GetId()); } } public long GenerateNewId() { return Auto.NewId(); } } }