Пример #1
2
        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;
        }
Пример #2
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;
        }
Пример #3
0
        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;
        }
Пример #4
0
        /// <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
            });
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        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));
        }
Пример #7
0
 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);
     }
 }
Пример #8
0
 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;
 }
Пример #9
0
        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);
        }
Пример #10
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);
            }
        }
Пример #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);
            }
        }
Пример #12
0
 public async Task <IEnumerable <Cliente> > GetClientes()
 {
     return(await _connection.Table <Cliente>().ToListAsync());
 }
Пример #13
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);
            }
        }
Пример #14
0
 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");
     }
 }
Пример #15
0
 public Task<List<Logs>> GetLogsAsync()
 {
     return DataBase.Table<Logs>().ToListAsync();
 }
Пример #16
0
        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;
        }
Пример #17
0
 public Task <List <Person> > getPersonListAsync()
 {
     return(databaseConnection.Table <Person>().ToListAsync());
 }
Пример #18
0
        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));
 }
Пример #20
0
        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;
        }
Пример #21
0
 private Task <DummyTable> GetItemAsync(int id)
 {
     return(_db.Table <DummyTable>()
            .Where(i => i.Id == id)
            .FirstOrDefaultAsync());
 }
Пример #22
0
 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));
     }
 }
Пример #23
0
        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);
        }
Пример #24
0
        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;
        }
Пример #25
0
 public bool IsCategoriesDbAlreadyCreated()
 {
     if (_dbConnection != null)
     {
         var temp = _dbConnection.Table <Category>();
         if (temp != null)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #26
0
 //  USER ACCESS
 public Task <List <User> > GetUsersAsync()
 {
     return(_database.Table <User>().ToListAsync());
 }