SHARE
TWEET

Test

Roofik Nov 12th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Linq;
  5. using SQLite;
  6. using Xamarin.Forms;
  7.  
  8. namespace SQLiteApp1
  9. {
  10.     public class FriendRepository
  11.     {
  12.         SQLiteConnection database;
  13.         public FriendRepository(string filename)
  14.         {
  15.             string databasePath = DependencyService.Get<ISQLite>().GetDatabasePath("freinds.db");
  16.             database = new SQLiteConnection(databasePath);
  17.             database.CreateTable<Friend>();
  18.         }
  19.         public IEnumerable<Friend> GetItems()
  20.         {
  21.             return (from i in database.Table<Friend>() select i).ToList();
  22.  
  23.         }
  24.         public Friend GetItem(int id)
  25.         {
  26.             return database.Get<Friend>(id);
  27.         }
  28.         public int DeleteItem(int id)
  29.         {
  30.             return database.Delete<Friend>(id);
  31.         }
  32.         public int SaveItem(Friend item)
  33.         {
  34.             if (item.Id != 0)
  35.             {
  36.                 database.Update(item);
  37.                 return item.Id;
  38.             }
  39.             else
  40.             {
  41.                 return database.Insert(item);
  42.             }
  43.         }
  44.     }
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top