コード例 #1
0
        public async Task<ObservableCollection<CardViewModel>> GetCards(int deckId)
        {
            _cards = new ObservableCollection<CardViewModel>();
            var db = new SQLiteAsyncConnection(App.DBPath);

            var query = await db.Table<Card>().OrderBy(c => c.FrontContent).ToListAsync();

            foreach (var c in query)
            {
                var _card = new CardViewModel();
                _card.Id = c.Id;
                _card.FrontContent = c.FrontContent;
                _card.BackContent = c.BackContent;
                _card.DeckId = c.DeckId;
                _cards.Add(_card);
            }
            return _cards;
        }
コード例 #2
0
        public async Task<string> SaveCard(CardViewModel card)
        {
            string result = String.Empty;
            var db = new SQLiteAsyncConnection(App.DBPath);

            try
            {
                var existingCard = await (db.Table<Card>().Where(c1 => c1.Id == card.Id)).FirstOrDefaultAsync();

                if (existingCard != null)
                {
                    existingCard.FrontContent = card.FrontContent;
                    existingCard.BackContent = card.BackContent;
                    int success = await db.UpdateAsync(existingCard);
                }
                else 
                {
                    var _card = new Card();
                    _card.FrontContent = card.FrontContent;
                    _card.BackContent = card.BackContent;
                    _card.DeckId = card.DeckId;
                    int success = await db.InsertAsync(_card);
                }
                result = "Success";
            }
            catch
            {
                result = "this card was not saved";
            }
            return result;
        }
コード例 #3
0
        public async Task<CardViewModel> GetCard(int cardId)
        {
            var card = new CardViewModel();

            var db = new SQLiteAsyncConnection(App.DBPath);
            var _card = await db.FindAsync<Card>(c1 => c1.Id == cardId);

            if (_card == null)
                return null;

            card.Id = _card.Id;
            card.FrontContent = _card.FrontContent;
            card.BackContent = _card.BackContent;
            card.DeckId = _card.DeckId;

            return card;
        }