예제 #1
0
 private async Task onLoadBusinessCards()
 {
     IsBusy = true;
     try
     {
         Businesscards.Clear();
         await GetBusinessCards();
     }
     catch (Exception)
     {
         Debug.WriteLine("BusinessCardsViewModel - Failed to load businesscards");
     }
     finally
     {
         IsBusy = false;
     }
 }
예제 #2
0
        private async Task GetBusinessCards()
        {
            Businesscards.Clear();
            var businesscards = await App.Database.GetBusinesscardsAsync();

            var sortedcards = businesscards.OrderByDescending(i => i.Date);

            foreach (var card in sortedcards)
            {
                //Uncomment this code if the endpoint is set up
                try
                {
                    if (card.Extra != "UNSCANNEDCARD")
                    {
                        // Try to send the card to the endpoint
                        await restService.SendCardsAsync(card);

                        // if succesfull delete is from the database
                        await App.Database.DeleteBusinesscardAsync(card);

                        DependencyService.Get <IToast>().ShortAlert("Card was sent succesfully.");
                    }
                    else
                    {
                        Businesscards.Add(card);
                    }
                }
                catch (RestException ex)
                {
                    // if not succesfull add to the cards list
                    Businesscards.Add(card);
                    DependencyService.Get <IToast>().LongAlert("Something went wrong sending the card.\nPlease check your internet connection and try again.");
                    Debug.WriteLine(ex.ToString());
                }
            }
        }