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 AddCategoryAsync(Category categoryDetails)
 {
     if (_dbConnection != null)
     {
         try
         {
             var allCategories = from category in _dbConnection.Table <Category>() where category.CategoryName.ToLower() == categoryDetails.CategoryName.ToLower() && category.Language.ToLower() == categoryDetails.Language.ToLower() 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");
     }
 }
Exemple #3
0
        public async Task <bool> UpdateDBAsync(FreeDiscItemDownload freeDiscDownloader)
        {
            if (freeDiscDownloader == null)
            {
                #if DEBUG
                Debug.Write("UpdateDBAsync: freeDiscDownloader == null");
                #endif
                return(false);
            }
            Debug.Write("UpdateDB: ID" + freeDiscDownloader.DBID + " Title: " + freeDiscDownloader?.Title + " Status: " + freeDiscDownloader?.ItemStatus.ToString());

            if (freeDiscDownloader.DBID == 0)
            {
                Debug.Write("UpdateDBAsync: freeDiscDownloader.DBID == 0 !");
                return(false);
            }
            try
            {
                var conn = new SQLite.SQLiteAsyncConnection(App.AppSetting.DBDownloadPath);
                await conn.CreateTableAsync <FreeDiscItemDownload>();

                await conn.UpdateAsync(freeDiscDownloader);
            }
            catch (Exception e)
            {
                Debug.Write("UpdateDBAsync: Update error !");
                return(false);
            }
            return(true);
        }
Exemple #4
0
        private async void Save_Clicked(object sender, EventArgs e)
        {
            // validate input
            // assume that the input is in the correct format
            if (string.IsNullOrWhiteSpace(firstNameInput.Text) && string.IsNullOrWhiteSpace(surnameInput.Text))
            {
                await DisplayAlert("Invalid contact", "Please enter the name of your contact", "OK");

                return;
            }

            var contact = BindingContext as Contact;

            if (contact.Id == 0)
            {
                await _connection.InsertAsync(contact);

                ContactAdded?.Invoke(this, contact);
            }
            else
            {
                await _connection.UpdateAsync(contact);

                ContactUpdated?.Invoke(this, contact);
            }

            await Navigation.PopAsync();
        }
 private Task <int> SaveItemAsync(DummyTable item)
 {
     if (item.Id != 0)
     {
         return(_db.UpdateAsync(item));
     }
     else
     {
         return(_db.InsertAsync(item));
     }
 }
Exemple #6
0
 public Task<int> UpdateLogAsync(Logs log)
 {
     return DataBase.UpdateAsync(log);
 }
Exemple #7
0
        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);
            }
        }
Exemple #8
0
        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);
            }
        }
 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));
     }
 }
Exemple #10
0
 public async void Update(Cliente cliente)
 {
     await _connection.UpdateAsync(cliente);
 }
Exemple #11
0
 public Task <int> SaveUserAsync(User user)
 {
     //  User.ID == 0 until database gives it an ID
     return(user.ID == 0 ? _database.InsertAsync(user) : _database.UpdateAsync(user));
 }