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 MemoryCreateTestAsync()
        {
            // Assemble
            CreateConnection();

            var columnInfo = await _db.GetTableInfoAsync("DummyTable");

            // Act
            if (columnInfo != null && columnInfo.Count == 0)
            {
                // Consider..  <..>(CreateFlags.AllImplicit).Wait();
                _db.CreateTableAsync <DummyTable>().Wait();
            }

            var item = new DummyTable {
                // Id = 999,
                IdGuid       = "B7B18CA9-38B8-4BD9-B1ED-095FD2E1287B",
                Name         = "Item-Test1",
                LastSyncDttm = new System.DateTime(),
            };

            var id = await _db.InsertAsync(item);

            // Assert
            Assert.AreNotEqual(0, id);

            var dummyItem = await GetItemAsync(id);

            Assert.AreEqual(dummyItem.IdGuid, item.IdGuid, $"Incorrect guid for ItemId {id}");

            CloseConnection();
        }
Beispiel #3
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");
     }
 }
Beispiel #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();
        }
Beispiel #5
0
        public async Task <bool> SaveToDBAsync(FreeDiscItemDownload freeDiscDownloader)
        {
            if (freeDiscDownloader == null)
            {
                #if DEBUG
                Debug.Write("SaveToDBAsync: freeDiscDownloader == null");
                #endif
                return(false);
            }
            Debug.Write("SaveToDB: ID" + freeDiscDownloader.DBID + " Title: " + freeDiscDownloader?.Title + " Status: " + freeDiscDownloader?.ItemStatus.ToString());
            try
            {
                var conn = new SQLite.SQLiteAsyncConnection(App.AppSetting.DBDownloadPath);
                await conn.CreateTableAsync <FreeDiscItemDownload>();

                await conn.InsertAsync(freeDiscDownloader);
            }
            catch (Exception e)
            {
                Debug.Write("SaveToDB: Save error !");
                return(false);
            }

            Debug.Write("SaveToDB: Result ID" + freeDiscDownloader?.DBID ?? "NULL");
            return(true);
        }
Beispiel #6
0
        void Register(object sender, EventArgs e)
        {
            ValidateForm();

            var user = new User
            {
                username  = UserName.Text,
                firstName = FirstName.Text,
                lastName  = LastName.Text,
                password  = Password.Text,
                phone     = Phone.Text,
                region    = regionPicker.SelectedIndex
            };

            _connection.InsertAsync(user);
        }
Beispiel #7
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));
 }
Beispiel #8
0
 public Task<int> CreateLogAsync(Logs log)
 {
     return DataBase.InsertAsync(log);
 }
 public async void Create(Usuario usuario)
 {
     await _connection.InsertAsync(usuario);
 }
Beispiel #10
0
        protected async Task <bool> WriteAsync(T obj)
        {
            var dbFactory = new SQLite.SQLiteAsyncConnection(Common.Constants.SQLITE_FILENAME);

            return(await dbFactory.InsertAsync(obj) > 0);
        }
Beispiel #11
0
        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);
            }
        }
Beispiel #12
0
        async public Task<int> SaveItemAsync(ItemViewModel item)
        {
            SQLite.SQLiteAsyncConnection context = new SQLite.SQLiteAsyncConnection(connectionString);

            Item newItem = new Item()
            {
                Identifier = item.Identifier,
                Title = item.Title,
                Description = item.Description,
                Cost = item.Cost,
                Latitude = item.Latitude,
                Longitude = item.Longitude,
                Parent = item.Trip.Identifier,
                Traveler = item.Traveler.ToString(),
                Category = item.Category
            };

            await context.InsertAsync(newItem);
            return newItem.Identifier;
        }
Beispiel #13
0
        public async Task<int> SaveTripAsync(TripViewModel trip)
        {
            SQLite.SQLiteAsyncConnection context = new SQLite.SQLiteAsyncConnection(connectionString);

            Item newItem = new Item()
            {
                Identifier = trip.Identifier,
                Title = trip.Title,
                Description = trip.Description,
                Cost = trip.Cost,
                EndDate = trip.EndDate,
                StartDate = trip.StartDate,
                Latitude = trip.Latitude,
                Longitude = trip.Longitude,
                Traveler = trip.Traveler.ToString(),
                Image = trip.LocalPathImage
            };

            await context.InsertAsync(newItem);
            return newItem.Identifier;
        }
 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));
     }
 }
Beispiel #15
0
 public async void Create(Cliente cliente)
 {
     await _connection.InsertAsync(cliente);
 }
Beispiel #16
0
 public Task <int> savePersonAsync(Person personItem)
 {
     return(databaseConnection.InsertAsync(personItem));
 }
Beispiel #17
0
 public async static Task <int> AddToDb(this SQLite.SQLiteAsyncConnection connection, FavoriteRow row)
 {
     return(await connection.InsertAsync(row));
 }