private async void Backup_Clicked(object sender, EventArgs e) { //await DisplayAlert("Backup", "To back up your pothi, select Google Drive or any other cloud service", "OK"); try { List <PothiShabadExt> pothis = new List <PothiShabadExt>(); foreach (Pothi pothi in PothiObs) { List <PothiShabad> ps = await _con.QueryAsync <PothiShabad>($"Select * from PothiShabad where PothiId = {pothi.PothiId}"); PothiShabadExt ext = new PothiShabadExt() { pothi = pothi, shabadList = ps }; pothis.Add(ext); } string json = JsonConvert.SerializeObject(pothis); Util.ShareFile(json, "Pothis.json", "Pothi shared from Keertan Pothi"); Util.ShowRoast("Pothis exported successfully"); } catch (Exception exception) { Util.ShowRoast("Unable to export pothis"); } }
public async static Task <bool> ExportPothis(List <Pothi> PothiObs = null, bool autoSave = false) { _con = DependencyService.Get <ISqliteDb>().GetSQLiteConnection(); if (PothiObs == null) { PothiObs = await _con.QueryAsync <Pothi>(Queries.GetAllPothis()); } if ((PothiObs != null && PothiObs.Count > 0) || autoSave) { string folder = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal); string path = System.IO.Path.Combine(folder, "Pothis.json"); try { List <PothiShabadExt> pothis = new List <PothiShabadExt>(); foreach (Pothi pothi in PothiObs) { List <PothiShabad> ps = await _con.QueryAsync <PothiShabad>($"Select * from PothiShabad where PothiId = {pothi.PothiId}"); PothiShabadExt ext = new PothiShabadExt() { pothi = pothi, shabadList = ps }; pothis.Add(ext); } string json = JsonConvert.SerializeObject(pothis); if (autoSave) { Util.SaveFile(Util.AutoSaveFileName, json, true); } else { Util.SaveFile("Pothis.json", json, false); } //Util.ShowRoast("Pothi(s) exported successfully to Internal Storage/KeertanPothi/Pothis.json."); return(true); } catch (Exception exception) { //Util.ShowRoast("Unable to export pothis"); return(false); } } else { return(false); } }
public async static Task <string> GetPothiJson(Pothi pothi) { if (pothi == null || pothi.PothiId == null || pothi.PothiId < 1) { return(string.Empty); } else { SQLiteAsyncConnection _con = DependencyService.Get <ISqliteDb>().GetSQLiteConnection(); List <PothiShabad> ps = await _con.QueryAsync <PothiShabad>($"Select * from PothiShabad where PothiId = {pothi.PothiId}"); PothiShabadExt ext = new PothiShabadExt() { pothi = pothi, shabadList = ps }; string json = JsonConvert.SerializeObject(ext); return(json); } }
internal async static Task <bool> SavePothFromPothiShabadExt(PothiShabadExt cur) { _con = DependencyService.Get <ISqliteDb>().GetSQLiteConnection(); Pothi pothi = new Pothi(); pothi.Name = cur.pothi.Name; pothi.CreatedOn = DateTime.Now; int cnt = await _con.InsertAsync(pothi); if (cnt > 0) { int pothiId = await Queries.GetLastId(); foreach (PothiShabad shabad in cur.shabadList) { PothiShabad pothiShabad = shabad; pothiShabad.PothiId = pothiId; await _con.InsertAsync(pothiShabad); } } return(true); }