Created
April 8, 2015 12:34
-
-
Save rafaelrmou/cdb2aa83d84d979d9aea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using IntegracaoOauth.Models; | |
using SQLite.Net; | |
using SQLite.Net.Interop; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace IntegracaoOauth.Repository | |
{ | |
public class DataBaseRepository | |
{ | |
//Conexão a base de dados | |
private SQLiteConnection dbCon; | |
//Mensagem que será retornada ao usuário | |
public string Mensage { get; set; } | |
/// <summary> | |
/// Construtor da casse para a criação da conexão | |
/// </summary> | |
/// <param name="sqliteP">Plataforma - ios, android ou winPhone</param> | |
/// <param name="dbPath">Caminho onde está o arquivo db3</param> | |
public DataBaseRepository(ISQLitePlatform sqliteP, string dbPath) | |
{ | |
if (dbCon == null) | |
{ | |
dbCon = new SQLiteConnection(sqliteP, dbPath); | |
dbCon.CreateTable<Usuario>(); | |
} | |
} | |
public void Add(Usuario entidadeNova) | |
{ | |
int res = 0; | |
try | |
{ | |
res = dbCon.Insert(entidadeNova); | |
Mensage = string.Format("{0} registro(s)", res); | |
} | |
catch (Exception e) | |
{ | |
Mensage = string.Format("Falha ao Inserir a entidade {0}. Erro: {1}", entidadeNova.GetType().ToString(), e.Message); | |
} | |
} | |
public void Add(Usuario[] entidades) | |
{ | |
int res = 0; | |
try | |
{ | |
res = dbCon.InsertAll(entidades); | |
Mensage = string.Format("{0} registro(s)", res); | |
} | |
catch (Exception e) | |
{ | |
Mensage = string.Format("Falha ao Inserir a entidade {0}. Erro: {1}", entidades.GetType().ToString(), e.Message); | |
} | |
} | |
public void Delete(Usuario entity) | |
{ | |
dbCon.Delete(entity); | |
} | |
public void Update(Usuario entity) | |
{ | |
dbCon.Update(entity); | |
} | |
public IEnumerable<Usuario> List | |
{ | |
get | |
{ | |
return dbCon.Table<Usuario>().ToList(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment