Guest User

Untitled

a guest
Apr 25th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. using System;
  2. using SQLite.Net;
  3. using System.IO;
  4. using Xamarin.Forms;
  5. using System.Linq;
  6. using System.Collections.Generic;
  7. namespace Cadastro
  8. {
  9. public class AcessoDB : IDisposable
  10. {
  11. private SQLiteConnection conexaoSQLite;
  12. public AcessoDB()
  13. {
  14. var config = DependencyService.Get<IConfig>();
  15. conexaoSQLite = new SQLiteConnection(config.Plataforma, Path.Combine(config.DiretorioSQLite, "Cadastro.db3"));
  16. conexaoSQLite.CreateTable<Cliente>();
  17. }
  18. public void InserirCliente(Cliente cliente)
  19. {
  20. conexaoSQLite.Insert(cliente);
  21. }
  22. public void AtualizarCliente(Cliente cliente)
  23. {
  24. conexaoSQLite.Update(cliente);
  25. }
  26. public void DeletarCliente(Cliente cliente)
  27. {
  28. conexaoSQLite.Delete(cliente);
  29. }
  30. public Cliente GetCliente(int codigo)
  31. {
  32. return conexaoSQLite.Table<Cliente>().FirstOrDefault(c => c.Id == codigo);
  33. }
  34. public List<Cliente> GetClientes()
  35. {
  36. return conexaoSQLite.Table<Cliente>().OrderBy(c => c.Nome).ToList();
  37. }
  38. public void Dispose()
  39. {
  40. conexaoSQLite.Dispose();
  41. }
  42. }
  43. }
Add Comment
Please, Sign In to add comment