示例#1
0
        public async Task ExecuteSearchFoodsCommand()
        {
            if (cancellationTokenSource != null)
            {
                cancellationTokenSource.Cancel();
            }

            cancellationTokenSource = new CancellationTokenSource();
            SetResultVisibility(true, false);

            try
            {
                Foods.Clear();
                var includUnknownFructose = AppPreferences.UnknownFructose;
                foreach (var food in await FoodDataStore.SearchFoodsAsync(SearchText, includUnknownFructose, cancellationTokenSource.Token))
                {
                    Foods.Add(new FoodViewModel(food));
                }
                SetResultVisibility(false, true);

                Analytics.TrackEvent("Search Completed", new Dictionary <string, string> {
                    { "Search Text", SearchText }
                });
            }
            catch (TaskCanceledException)
            {
                // Task was canceled so just handle the exception and move on
            }
            catch (Exception exception)
            {
                Analytics.TrackEvent("Error Searching Food", new Dictionary <string, string> {
                    { "Exception Message", exception.Message }
                });
            }
        }
示例#2
0
        async Task ExecuteLoadItemsCommand()
        {
            if (IsRefreshing)
            {
                return;
            }

            IsRefreshing = true;

            try
            {
                Foods.Clear();
                var apiService = new Services.ApiService.ApiService();
                var foods      = await apiService.GetAllFoodsAsync();

                foreach (var c in foods)
                {
                    Foods.Add(c);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsRefreshing = false;
            }
        }
示例#3
0
 public UserProfile UpdateFoods(List <long> foodIds)
 {
     if (!foodIds.IsNullOrZero())
     {
         if (Foods.IsNullOrZero())
         {
             Foods = new List <UserFood>();
         }
         Foods.RemoveAll(p => !foodIds.Contains(p.Id));
         var _foods = Foods;
         foodIds.ForEach(item =>
         {
             try
             {
                 var result = _foods.Where(p => p.Id == item).FirstOrDefault();
                 if (result.IsNull())
                 {
                     Foods.Add(new UserFood().Create(item, Id));
                 }
             }
             catch (Exception e)
             {
                 throw e;
             }
         });
     }
     else
     {
         Foods.Clear();
     }
     return(this);
 }
示例#4
0
        public async override Task InitializeAsync(INavigation navigation)
        {
            await base.InitializeAsync(navigation);

            Foods.Clear();
            Foods.AddRange(await DataStore.FoodEntries.Get());
        }
示例#5
0
 private void AddToList(IEnumerable <SelectableFoodViewModel> selectableFoodViewModels)
 {
     Foods.Clear();
     foreach (var item in selectableFoodViewModels)
     {
         Foods.Add(item);
     }
 }
示例#6
0
        private void AddToList(IEnumerable <Food> foods)
        {
            Foods.Clear();

            foreach (var item in foods)
            {
                var newEntry = new SelectableFoodViewModel(item)
                {
                    Price = GetPrice(item.MealCost)
                };

                Foods.Add(newEntry);
            }
        }
        public async void ExecuteLoadFoodsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            LoadFoodsCommand.ChangeCanExecute();

            Foods.Clear();
            Foods.AddRange(await _DataClient.GetFoodsAsync());

            IsBusy = false;
            LoadFoodsCommand.ChangeCanExecute();
        }
示例#8
0
 protected override void Death()
 {
     //base.Death();
     if (myMoM.isActive)
     {
         CedeDrones(myMoM);
     }
     else
     {
         KillDrones();
     }
     myMoM.daughters -= 1;
     Foods.Clear();
     UnityEventManager.TriggerEvent("TargetUnavailable", unitID);
     bMoving    = false;
     isActive   = false;
     hasChanged = false;
     if (teamID >= 0 && NewGameController.Instance.TeamSize[teamID] > 0)
     {
         NewGameController.Instance.TeamSize[teamID] -= 1;
     }
 }
示例#9
0
 protected async void OnSearchTextChanged()
 {
     try
     {
         if (string.IsNullOrEmpty(searchText))
         {
             if (Foods != null)
             {
                 Foods?.Clear();
             }
             SetResultVisibility(false, false);
         }
         if (searchText.Length > 3)
         {
             await ExecuteSearchFoodsCommand();
         }
     }
     catch (Exception exception)
     {
         Analytics.TrackEvent("OnSearchTextChanged Error", new Dictionary <string, string> {
             { "Exception Message", exception.Message }
         });
     }
 }
示例#10
0
 public async void SearchFoodsUnit()
 {
     try
     {
         IsLoad = true;
         Foods.Clear();
         var SaveSearch = Search;
         var result     = await new BL.BlRouter(EventAggregator).GetSearchFood(Search);
         if (SaveSearch != Search)
         {
             return;
         }
         Foods.Clear();
         foreach (var food in result)
         {
             Foods.Add(food);
         }
         IsLoad = false;
     }
     catch (Exception e)
     {
         isLoad = false;
     }
 }
 public void GetFoods()
 {
     Foods.Clear();
     foodService.GetFoods().Where(p => p.Date.Date.Equals(DateUpdate.Date)).ToList().ForEach(a => Foods.Add(a));
     Foods.Add(new Food(null, DateTime.Now, foodService, eventAggregator));
 }