Exemplo n.º 1
0
 protected override void InitializeExecute()
 {
     base.InitializeExecute();
     CurrentExersize = new Exersize();
     var parameters = NavigationProvider.GetNavigationParameters();
     fromPlan = parameters.ContainsKey(Constants.NavigationParameters.FromPlan);
     if (parameters.ContainsKey(Constants.NavigationParameters.ActivityId))
     {
         int id;
         int.TryParse(parameters[Constants.NavigationParameters.ActivityId], out id);
         using (var repo = new PhysicalActivityRepository())
         {
             CurrentExersize.ActivityId = id;
             CurrentExersize.Activity = repo.GetById(id);
         }
     }
 }
Exemplo n.º 2
0
        protected override void InitializeExecute()
        {
            base.InitializeExecute();
            var parameters = NavigationProvider.GetNavigationParameters();
            if (parameters.ContainsKey(Constants.NavigationParameters.TrainingId))
            {
                int id;
                int.TryParse(parameters[Constants.NavigationParameters.TrainingId], out id);

                using (var repo = new TrainingRepository())
                {
                    Training = repo.GetById(id);
                }

                using (var repo = new ExersizesRepository())
                {
                    Exersizes = new ObservableCollection<Exersize>(repo.GetByTraining(id));
                }

                using (var repo = new PhysicalActivityRepository())
                {
                    foreach (var item in exersizes)
                    {
                        item.Activity = repo.GetById(item.ActivityId);
                    }
                }
            }

            if (Training == null)
            {
                Training = new Training();
                Exersizes = new ObservableCollection<Exersize>();
            }
        }
Exemplo n.º 3
0
        public void AddExersize(Exersize exersize)
        {
            Exersizes.Add(exersize);
            this.Training.Duration = Exersizes.Sum(item => item.Duration);
            float caloriesPerBody = 0;
            using (var activityRepo = new PhysicalActivityRepository())
            {
                var activity = activityRepo.GetById(exersize.ActivityId);
                caloriesPerBody = (float)(Diet.User.BodyState.Weight * activity.Calories) / 60;
                exersize.Activity = activity;
            }

            exersize.CaloriesSpent = (int)(exersize.Duration * caloriesPerBody);
            this.Training.CaloriesMustBurned = Exersizes.Sum(item => item.CaloriesSpent);
        }
Exemplo n.º 4
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;
            }
        }
Exemplo n.º 5
0
        public Exersize DoExersize(Exersize invoked)
        {
            Exersize exersize = invoked.CreateCopy();
            // all calories specified for one kilo per minute
            float caloriesPerBody = 0;
            using (var activityRepo = new PhysicalActivityRepository())
            {
                var activity = activityRepo.GetById(invoked.ActivityId);
                caloriesPerBody = (float)(user.BodyState.Weight * activity.Calories) / 60;
            }
            
            exersize.CaloriesSpent = (int)(invoked.Duration * caloriesPerBody);
            using (var repository = new ExersizesRepository())
            {
                exersize = repository.Add(exersize);
            }


            spentToday.Add(exersize);
            if (goal.Course != Course.LoseWeight)
            {
                int totalSpent = spentToday.Sum(item => item.CaloriesSpent);
                plan.FoodPerDay.DailyCalories = plan.FoodPerDay.NormalPerDay + plan.FoodPerDay.ExtraCaloriesPerDay + totalSpent;
            }

            return exersize;
        }
Exemplo n.º 6
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;
        }