Esempio n. 1
0
 public static void ClickAddDeck(String title, String author, String subject, String description, String imagePath, CategoryViewModel category)
 {
     var _deck = GetDeck(category, title);
     if (_deck == null)
     {
         _deck = new DeckViewModel("", category, title, author, subject, description, imagePath);
         FlashcardDataSource.AddDeck(_deck);
     }
 }
Esempio n. 2
0
 public static void ClickAddCategory(String name)
 {
     CategoryViewModel _category = GetCategory(name);
     if (_category == null)
     {
         CategoryViewModel newCategory = new CategoryViewModel("",name);
         FlashcardDataSource.AddCategory(newCategory);
     }
 }
        public async Task<CategoryViewModel> GetCategory(int categoryId)
        {
            var category = new CategoryViewModel();
            var db = new SQLiteAsyncConnection(App.DBPath);

            var _category = await db.FindAsync<Category>(c => c.Id == categoryId);

            if (_category == null)
                return null;

            category.Id = _category.Id;
            category.Name = _category.Name;

            return category;
        }
        public async Task<ObservableCollection<CategoryViewModel>> GetCategories()
        {
            _categories = new ObservableCollection<CategoryViewModel>();
            var db = new SQLiteAsyncConnection(App.DBPath);

            var query = await db.Table<Category>().OrderBy(c => c.Name).ToListAsync();

            foreach (var c in query)
            {
                var _category = new CategoryViewModel();
                _category.Id = c.Id;
                _category.Name = c.Name;

                _categories.Add(_category);
            }
            return _categories;
        }
 public FlashcardDataSource()
 {
     databasePath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "MyDatabase.db");
     using (var database = new SQLiteConnection(databasePath))
     {
         database.CreateTable<Category>();
         database.CreateTable<Deck>();
         database.CreateTable<Card>();
     }
     var category1 = new CategoryViewModel("", "english");
     AddCategory(category1);
     AllCategories.Add(category1);
     var deck1 = new DeckViewModel("", category1, "1001 words need to know", "Thang", "toefl", "", "");
     AddDeck(deck1);
     AllDecks.Add(deck1);
     var card1 = new CardsViewModel("", "abc", "abc", deck1);
     AddCard(card1);
     AllCards.Add(card1);
 }
Esempio n. 6
0
 public static void ClickEditCategory(CategoryViewModel category, String newCategoryName)
 {
     if (category != null)
     {
         category.Name = newCategoryName;
         FlashcardDataSource.UpdateCategory(category);
     }
 }
Esempio n. 7
0
 public static void ClickDeleteCategory(CategoryViewModel category)
 {
     if (category != null)
         FlashcardDataSource.DeleteCategory(category);
 }
Esempio n. 8
0
 public static DeckViewModel GetDeck(CategoryViewModel category,String title)
 {
     var _decks = FlashcardDataSource.GetDecks(category);
     foreach (var _deck in _decks)
     {
         if (_deck.Title == title)
             return _deck;
     }
     return null;
 }
        public static void AddCategory(CategoryViewModel category)
        {
            using (var database = new SQLiteConnection(databasePath))
            {

                var _category = new Category();
                _category.Id = Guid.NewGuid();
                _category.Name = category.Name;
                database.Insert(_category);
                category.UniqueId = _category.Id.ToString();
            }
        }
 public static void UpdateCategory(CategoryViewModel category)
 {
     using (var database = new SQLiteConnection(databasePath))
     {
         var _category = database.Find<Category>(c1 => c1.Id.ToString() == category.UniqueId);
         if (_category != null)
         {
             _category.Name = category.Name;
             database.Update(_category);
         }
     }
 }
        //function for deck
        // get
        // add
        // edit
        // delete
        public static ObservableCollection<DeckViewModel> GetDecks(CategoryViewModel category)
        {
            _flashcardDataSource._allDecks.Clear();

            using (var database = new SQLiteConnection(databasePath))
            {
                var decks = database.Table<Deck>().Where(d1 => d1.Id.ToString() == category.UniqueId).OrderBy(d2 => d2.Title);
                foreach (var deck in decks)
                {
                    DeckViewModel flashcardDataDeck = new DeckViewModel(""+deck.Id,
                                                                                category,
                                                                                deck.Title,
                                                                                deck.Author,
                                                                                deck.Subject,
                                                                                deck.Description,
                                                                                deck.ImagePath);
                    _flashcardDataSource._allDecks.Add(flashcardDataDeck);
                }
            }
            return _flashcardDataSource.AllDecks;
        }
        // function for category
        // get
        // add
        // edit
        // delete
        public static ObservableCollection<CategoryViewModel> GetCategories(String uniqueId)
        {
            _flashcardDataSource._allCategories.Clear();

            using (var database = new SQLiteConnection(databasePath))
            {
                var _categories = database.Table<Category>().OrderBy(c1 => c1.Name);
                foreach (var _category in _categories)
                {
                    CategoryViewModel categoriesViewModel = new CategoryViewModel(_category.Id.ToString(), _category.Name);
                    _flashcardDataSource._allCategories.Add(categoriesViewModel);
                }
            }
            return _flashcardDataSource._allCategories;
        }
 public static void DeleteCategory(CategoryViewModel category)
 {
     using (var database = new SQLiteConnection(databasePath))
     {
         var _category = database.Find<Category>(c1 => c1.Id.ToString() == category.UniqueId);
         database.Delete(category);
     }
 }
Esempio n. 14
0
        public async Task<string> SaveCategory(CategoryViewModel category)
        {
            string result = String.Empty;
            var db = new SQLiteAsyncConnection(App.DBPath);

            try
            {
                var existingCategory = await (db.Table<Category>().Where(c1 => c1.Id == category.Id)).FirstOrDefaultAsync();

                if (existingCategory != null)
                {
                    existingCategory.Name = category.Name;
                    int success = await db.UpdateAsync(existingCategory);
                }
                else
                {
                    var _category = new Category();
                    _category.Name = category.Name;
                    int success = await db.InsertAsync(_category);
                }

                result = "success";
            }
            catch
            {
                result = "this category was not saved";
            }

            return result;
        }