示例#1
0
        protected override void InitializeExecute()
        {
            BusyCount++;
            base.InitializeExecute();
            var parameters = NavigationProvider.GetNavigationParameters();
            if (parameters.ContainsKey(Constants.NavigationParameters.FoodId))
            {
                RunInBackground(() =>
                {
                    Food result;
                    using (var repo = new FoodRepository())
                    {
                        result = repo.GetById(int.Parse(parameters[Constants.NavigationParameters.FoodId]));
                    }

                    InvokeInUIThread(() =>
                    {
                        CurrentFood = result;
                        BusyCount--;
                    });
                });
            }
        }
示例#2
0
        private void GetTop()
        {
            switch (searchType)
            {
                case EnergyType.Activity:
                    using (var activityRepo = new PhysicalActivityRepository())
                    {
                        SearchResults = new ObservableCollection<RaisableObject>(activityRepo.GetTopTwenty().Cast<RaisableObject>().ToList());
                    }
                    break;
                case EnergyType.Food:
                    using (var foodRepo = new FoodRepository())
                    {
                        SearchResults = new ObservableCollection<RaisableObject>(foodRepo.GetTopTwenty().Cast<RaisableObject>().ToList());
                    }

                    break;
            }
        }
示例#3
0
        public Food EatFood(Food eaten)
        {
            using (var repo = new FoodRepository())
            {
                repo.EatFood(eaten);
            }

            Food newItem = eaten.CreateCopy();
            int eatenGramms = newItem.AmountOfEaten;
            switch (newItem.FoodMeasure)
            {
                case FoodMeasure.Glass:
                    eatenGramms = newItem.AmountOfEaten * Constants.GlassGramms;
                    break;
                case FoodMeasure.Portion:
                    eatenGramms = newItem.AmountOfEaten * Constants.PortionGramms;
                    break;
            }


            // in db Calories is specified for 100 gramm of product
            newItem.AmountOfCalories = (int)(((float)eatenGramms / 100) * (float)(newItem.Calories));
            eatenFood.Add(newItem);
            IsolatedStorage.WriteValue(Constants.CacheKeys.EatenFood, eatenFood);
            return newItem;
        }
示例#4
0
        public List<RaisableObject> Search(string query, EnergyType type)
        {
            query = query.ToLower();
            List<RaisableObject> result = new List<RaisableObject>();
            switch (type)
            {
                case EnergyType.Activity:
                    var activityKeys = activityTranslations.Where(item => 
                    {
                        var lower = item.Value.ToLower();
                        return lower.StartsWith(query) || lower.Contains(query);
                    }).Select(item => item.Key);
                    using (var repo = new PhysicalActivityRepository())
                    {
                        result = repo.Search(activityKeys).Cast<RaisableObject>().ToList();
                    }

                    break;
                case EnergyType.Food:
                    var foodKeys = this.foodTranslations.Where(item =>
                    {
                        var lower = item.Value.ToLower();
                        return lower.StartsWith(query) || lower.Contains(query);
                    }).Select(item => item.Key);
                    using (var repo = new FoodRepository())
                    {
                        result = repo.Search(foodKeys).Cast<RaisableObject>().ToList();
                    }
                    break;
            }

            return result;
        }