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
public static ObservableCollection<Schema.Students> GetAllStudents() | |
{ | |
SQLiteConnection connection; | |
using (connection = new SQLiteConnection(DbPath)) | |
{ | |
var myCollection = connection.Table<Schema.Students>().ToList<Schema.Students>(); | |
var studentsList = new ObservableCollection<Schema.Students>(myCollection); | |
return studentsList; | |
} | |
} |
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
public static bool DeleteStudent(int id) | |
{ | |
SQLiteConnection connection; | |
using (connection = new SQLiteConnection(DbPath)) | |
{ | |
var existingstudent = | |
connection.Query<Schema.Students>("select * from Students where Id =" + id).FirstOrDefault(); | |
connection.RunInTransaction(() => | |
{ | |
connection.Delete(existingstudent); |
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
public static void UpdateStudent(int id,int newmarks) | |
{ | |
SQLiteConnection connection; | |
using (connection = new SQLiteConnection(DbPath)) | |
{ | |
var existingstudent = | |
connection.Query<Schema.Students>("select * from Students where Id =" + id).FirstOrDefault(); | |
if (existingstudent != null) | |
{ | |
existingstudent.Marks = newmarks; |
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
public static void AddNewStudent(Schema.Students obj) | |
{ | |
SQLiteConnection connection; | |
using (connection = new SQLiteConnection(DbPath)) | |
{ | |
connection.RunInTransaction(() => | |
{ | |
connection.Insert(obj); | |
}); | |
} |
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
public static async Task<bool> DeleteDatabase() | |
{ | |
try | |
{ | |
var storageFile = await StorageFile.GetFileFromPathAsync(DbPath); | |
await storageFile.DeleteAsync(StorageDeleteOption.PermanentDelete); | |
return true; | |
} | |
catch (Exception ex) | |
{ |
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
//Database name | |
public static string DbName = "Records.sqlite"; | |
//Full Database Path | |
public static string DbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, DbName); | |
public async static Task<bool> Createdatabase() | |
{ | |
var result = await Checkdatabase(); | |
if (!result) |
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
class Schema | |
{ | |
public class Students | |
{ | |
[PrimaryKey, AutoIncrement] | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public int Marks { get; set; } |
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
public class AlphabetToColorConverter : IValueConverter | |
{ | |
public object Convert(object value, Type targetType, object parameter, string culture) | |
{ | |
string[] colors= { "#7998f3", "#bbf379", "#f379df", "#79f3e3", "#f3bf79", "#9c79f3", "#7af379", "#f3799d", "#79c1f3", "#e4f379", "#f37e79", "#de79f3", "#79f3ba", "#f39779", "#797ff3", "#a2f379", "#f379c6", "#79e9f3", "#f3d979", "#b579f3", "#79f392", "#f37984", "#79a8f3", "#cbf379", "#f379ee", "#79f3d3" }; | |
string input = (string) value; | |
char initialCharacter = input.ToLower().ToCharArray()[0]; | |
int charCode = initialCharacter; |
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
function insert(item, user, request) { | |
var table = tables.getTable('User'); | |
table.where({ | |
userId: user.userId | |
}).read({ | |
success: upsertItem | |
}); | |
function upsertItem(existingItems) { | |
if (existingItems.length === 0) { |
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
public static async Task<byte[]> GetBytesAsync(StorageFile file) | |
{ | |
byte[] fileBytes = null; | |
if (file == null) return null; | |
using (var stream = await file.OpenReadAsync()) | |
{ | |
fileBytes = new byte[stream.Size]; | |
using (var reader = new DataReader(stream)) | |
{ | |
await reader.LoadAsync((uint)stream.Size); |