public async Task<bool> Save() { var db = new SQLite.SQLiteAsyncConnection(app.DBPath); int success = 0; try { Account existingAccount = await (db.Table<Account>().Where( a => a.Id == Id)).FirstOrDefaultAsync(); if (existingAccount != null) { existingAccount.Name = Name; existingAccount.Description = Description; existingAccount.CurrentBalance = CurrentBalance; success = await db.UpdateAsync(existingAccount); } else { success = await db.InsertAsync(new Account() { Name = this.Name, Description = this.Name, Type = this.Type, CurrentBalance = this.CurrentBalance, DateCreated = DateTime.Now }); } } catch { success = 0; } return success != 0; }
public async Task<List<ParentViewModel>> GetParentsAsync(Guid user) { SQLite.SQLiteAsyncConnection context = new SQLite.SQLiteAsyncConnection(connectionString); List<ParentViewModel> parents = new List<ParentViewModel>(); List<Item> result = await context.Table<Item>().Where(p => p.Parent == 0).ToListAsync(); foreach (Item item in result) { parents.Add(new ParentViewModel() { Title = item.Title, Description = item.Description, StartDate = Convert.ToDateTime(item.StartDate), Category = (Int16)Generic.UI.Logic.Enumerations.Category.Trips, Cost = item.Cost, Identifier = item.Identifier, Latitude = item.Latitude, Longitude = item.Longitude, LocalPathImage = item.Image == null ? loader.GetString("DefaultParentImage") : item.Image, User = new Guid(item.User) }); } return parents; }
public async Task<List<TripViewModel>> GetTripsAsync(Guid traveler) { SQLite.SQLiteAsyncConnection context = new SQLite.SQLiteAsyncConnection(connectionString); List<TripViewModel> trips = new List<TripViewModel>(); //trips have the parent null, items have a trip as parent List<Item> result = await context.Table<Item>().Where(p => p.IsSuggestion == false && p.Parent == 0).ToListAsync(); foreach (Item item in result) { trips.Add(new TripViewModel() { Title = item.Title, Description = item.Description, EndDate = Convert.ToDateTime(item.EndDate), StartDate = Convert.ToDateTime(item.StartDate), Category = (Int16)Sugges.UI.Logic.Enumerations.Category.Trips, Cost = item.Cost, Identifier = item.Identifier, Latitude = item.Latitude, Longitude = item.Longitude, RemotePathImage = item.Image == null ? "/Assets/Trip.png" : item.Image, LocalPathImage = item.Image == null ? "/Assets/Trip.png" : item.Image, Traveler = new Guid(item.Traveler) }); } return trips; }
/// <summary> /// Get the single settings object /// </summary> /// <returns>The settings async.</returns> public async System.Threading.Tasks.Task <CommunicationSettings> GetSettingsAsync() { var settings = await database.Table <CommunicationSettings>()?.ToListAsync(); if (settings != null && settings.Count == 1) { return(settings.First()); } return(new CommunicationSettings() { InEditMode = false, InFramedMode = false, RequireDeselect = false, InIconModeAuto = false, IsBottomOriented = false }); }
public static async Task <bool> LocationDataExists(SQLite.SQLiteAsyncConnection dbConn) { try { await dbConn.Table <WeatherData.Favorites>().CountAsync(); int count = await dbConn.Table <WeatherData.LocationData>().CountAsync(); if (count > 0) { return(true); } else { return(false); } } catch (Exception) { return(false); } }
public async Task <List <News> > GetNews() { List <News> ListItems = new List <News>(); SQLite.SQLiteAsyncConnection connection = DataManager.Instance.SqliteDatabase; List <News> news = await connection.Table <News>().ToListAsync(); foreach (News item in news) { ListItems.Add(item); } return(await Task.FromResult <List <News> >(ListItems)); }
private async Task removeOldMessage(OldMessageSettings settings) { var db = new SQLite.SQLiteAsyncConnection(this.DBPath); var messagesToDelete = db.Table<OldMessageSettings>().Where(m => m.ID == settings.ID); foreach (var messageToDelete in await messagesToDelete.ToListAsync()) { await db.DeleteAsync(messageToDelete); } }
async public Task<List<TrashImage>> GetTrashImagesAsync() { SQLite.SQLiteAsyncConnection context = new SQLite.SQLiteAsyncConnection(connectionString); await context.CreateTableAsync<Sugges.UI.Logic.DataModel.TrashImage>(); List<TrashImage> result = await context.Table<TrashImage>().ToListAsync(); return result; }
async public Task DeleteTrashImageAsync(string imageName) { SQLite.SQLiteAsyncConnection context = new SQLite.SQLiteAsyncConnection(connectionString); TrashImage image = await context.Table<TrashImage>().Where(p => p.Name == imageName).FirstOrDefaultAsync(); if (image != null) await context.DeleteAsync(image); }
async public Task UpdateItem(ItemViewModel itemViewModel) { SQLite.SQLiteAsyncConnection context = new SQLite.SQLiteAsyncConnection(connectionString); List<ItemViewModel> result = new List<ItemViewModel>(); Item item = await context.Table<Item>().Where(p => p.Identifier == itemViewModel.Identifier).FirstOrDefaultAsync(); item.Title = itemViewModel.Title; item.Description = itemViewModel.Description; item.Cost = itemViewModel.Cost; item.Category = itemViewModel.Category; if (item != null) { await context.UpdateAsync(item); } }
async public void RegisterTrashImage(string imageName) { SQLite.SQLiteAsyncConnection context = new SQLite.SQLiteAsyncConnection(connectionString); TrashImage image = await context.Table<TrashImage>().Where(p => p.Name == imageName).FirstOrDefaultAsync(); if (image == null) { TrashImage newItem = new TrashImage() { Name = imageName, }; await context.InsertAsync(newItem); } }
public async Task <IEnumerable <Cliente> > GetClientes() { return(await _connection.Table <Cliente>().ToListAsync()); }
async public Task UpdateTrip(TripViewModel trip) { SQLite.SQLiteAsyncConnection context = new SQLite.SQLiteAsyncConnection(connectionString); List<ItemViewModel> result = new List<ItemViewModel>(); Item item = await context.Table<Item>().Where(p => p.Identifier == trip.Identifier).FirstOrDefaultAsync(); item.Image = trip.LocalPathImage; item.Title = trip.Title; item.Description = trip.Description; item.Cost = trip.Cost; item.StartDate = trip.StartDate; if (item != null) { await context.UpdateAsync(item); } }
public async Task AddCategoryAsync(CategoryDetailsModel categoryDetails) { if (_dbConnection != null) { try { var allCategories = from category in _dbConnection.Table <CategoryDetailsModel>() where category.CategoryName == categoryDetails.CategoryName select category; if (allCategories != null && await allCategories.CountAsync() >= 1) { await _dbConnection.UpdateAsync(categoryDetails); } else { await _dbConnection.InsertAsync(categoryDetails); } } catch (Exception e) { Debug.WriteLine(e.ToString()); } } else { Debug.WriteLine("failed to get sqlite connection"); } }
public Task<List<Logs>> GetLogsAsync() { return DataBase.Table<Logs>().ToListAsync(); }
public async Task<List<TripViewModel>> GetSuggestionsAsync() { SQLite.SQLiteAsyncConnection context = new SQLite.SQLiteAsyncConnection(connectionString); List<TripViewModel> suggestions = new List<TripViewModel>(); List<Item> result = await context.Table<Item>().Where(p => p.IsSuggestion == true).ToListAsync(); foreach (Item item in result) { suggestions.Add(new TripViewModel() { Title = item.Title, Description = item.Description, EndDate = Convert.ToDateTime(item.EndDate), StartDate = Convert.ToDateTime(item.StartDate), Category = (Int16)Sugges.UI.Logic.Enumerations.Category.Trips, Cost = item.Cost, Identifier = item.Identifier, Latitude = item.Latitude, Longitude = item.Longitude, RemotePathImage = item.Image == null ? "/Assets/Suggestion.png" : item.Image, LocalPathImage = item.Image == null ? "/Assets/Suggestion.png" : item.Image, Traveler = new Guid(item.Traveler), IsSuggestion = true }); } return suggestions; }
public Task <List <Person> > getPersonListAsync() { return(databaseConnection.Table <Person>().ToListAsync()); }
async public Task<ParentViewModel> GetParentAsync(int identifier) { SQLite.SQLiteAsyncConnection context = new SQLite.SQLiteAsyncConnection(connectionString); ParentViewModel trip = new ParentViewModel(); //trips have the parent null, items have a trip as parent Item item = await context.Table<Item>().Where(p => p.Identifier == identifier && p.Parent == 0).FirstOrDefaultAsync(); trip = new ParentViewModel() { Title = item.Title, Description = item.Description, StartDate = Convert.ToDateTime(item.StartDate), Category = (Int16)Generic.UI.Logic.Enumerations.Category.Trips, Cost = item.Cost, Identifier = item.Identifier, Latitude = item.Latitude, Longitude = item.Longitude, LocalPathImage = item.Image == null ? loader.GetString("DefaultParentImage") : item.Image, User = new Guid(item.User) }; return trip; }
public async Task <Usuario> GetByPredicate(Expression <Func <Usuario, bool> > predicate) { return(await _connection.Table <Usuario>().FirstOrDefaultAsync(predicate)); }
public async Task<bool> DeleteAccount(int accountId) { var db = new SQLite.SQLiteAsyncConnection(app.DBPath); var existingAccount = await (db.Table<Account>().Where( a => a.Id == accountId)).FirstAsync(); return await db.DeleteAsync(existingAccount) > 0; }
private Task <DummyTable> GetItemAsync(int id) { return(_db.Table <DummyTable>() .Where(i => i.Id == id) .FirstOrDefaultAsync()); }
private async Task addOldMessage(OldMessageSettings settings) { var db = new SQLite.SQLiteAsyncConnection(this.DBPath); OldMessageSettings existingMessage; try { existingMessage = await (db.Table<OldMessageSettings>().Where(m => m.ID == settings.ID).FirstAsync()); } catch { existingMessage = null; } if (existingMessage != null) { existingMessage.FontSize = settings.FontSize; existingMessage.AnimateMessage = settings.AnimateMessage; existingMessage.Duration = settings.Duration; existingMessage.Message = settings.Message; existingMessage.ShowCountdown = settings.ShowCountdown; existingMessage.Added = DateTime.Now; int success = await db.UpdateAsync(existingMessage); } else { settings.Added = DateTime.Now; int success = await db.InsertAsync(OldMessageSettings.CreateOldMessageSettings(settings)); } }
public async Task DeleteItemAsync(int identifier) { SQLite.SQLiteAsyncConnection context = new SQLite.SQLiteAsyncConnection(connectionString); List<Item> childs = await context.Table<Item>().Where(p => p.Parent == identifier).ToListAsync(); foreach(Item child in childs) { await context.DeleteAsync(child); } Item item = await context.Table<Item>().Where(p => p.Identifier == identifier).FirstOrDefaultAsync(); if (item != null) await context.DeleteAsync(item); }
public async Task<List<ItemViewModel>> GetItemsByTripAsync(int trip) { SQLite.SQLiteAsyncConnection context = new SQLite.SQLiteAsyncConnection(connectionString); List<ItemViewModel> result = new List<ItemViewModel>(); List<Item> items = await context.Table<Item>().Where(p => p.Parent == trip).ToListAsync(); foreach (Item item in items) { result.Add(new ItemViewModel() { Title = item.Title, Description = item.Description, Cost = item.Cost, Latitude = item.Latitude, Longitude = item.Longitude, Traveler = new Guid(item.Traveler), Category = (byte)item.Category, Identifier = item.Identifier, LocalPathImage = item.Image, }); } return result; }
public bool IsCategoriesDbAlreadyCreated() { if (_dbConnection != null) { var temp = _dbConnection.Table <Category>(); if (temp != null) { return(true); } } return(false); }
// USER ACCESS public Task <List <User> > GetUsersAsync() { return(_database.Table <User>().ToListAsync()); }