mirror of
https://github.com/bitwarden/mobile
synced 2026-02-25 00:52:49 +00:00
Added icons for iOS. Broke out data access into repositories. Added syncing service.
This commit is contained in:
54
src/App/Repositories/Repository.cs
Normal file
54
src/App/Repositories/Repository.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.App.Abstractions;
|
||||
using SQLite;
|
||||
|
||||
namespace Bit.App.Repositories
|
||||
{
|
||||
public abstract class Repository<T, TId> : IRepository<T, TId>
|
||||
where TId : IEquatable<TId>
|
||||
where T : class, IDataObject<TId>, new()
|
||||
{
|
||||
public Repository(ISqlService sqlService)
|
||||
{
|
||||
Connection = sqlService.GetConnection();
|
||||
}
|
||||
|
||||
protected SQLiteConnection Connection { get; private set; }
|
||||
|
||||
public virtual Task<T> GetByIdAsync(TId id)
|
||||
{
|
||||
return Task.FromResult(Connection.Get<T>(id));
|
||||
}
|
||||
|
||||
public virtual Task<IEnumerable<T>> GetAllAsync()
|
||||
{
|
||||
return Task.FromResult(Connection.Table<T>().Cast<T>());
|
||||
}
|
||||
|
||||
public virtual Task InsertAsync(T obj)
|
||||
{
|
||||
Connection.Insert(obj);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public virtual Task UpdateAsync(T obj)
|
||||
{
|
||||
Connection.Update(obj);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public virtual async Task DeleteAsync(T obj)
|
||||
{
|
||||
await DeleteAsync(obj.Id);
|
||||
}
|
||||
|
||||
public virtual Task DeleteAsync(TId id)
|
||||
{
|
||||
Connection.Delete<T>(id);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user