Esempio n. 1
0
        public Training Add(Training training)
        {
            Training newTraining = training.CreateCopy();
            try
            {
                DbContext.Trainings.InsertOnSubmit(newTraining);
                DbContext.SubmitChanges();
            }
            catch (Exception ex)
            {
                ErrorLogger.LogException(ex);
            }

            return newTraining;
        }
Esempio n. 2
0
        public bool Delete(Training training)
        {
            bool result = false;
            try
            {
                var existing = GetById(training.Id);
                if (existing != null)
                {
                    DbContext.Trainings.DeleteOnSubmit(existing);
                    DbContext.SubmitChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogException(ex);
            }

            return result;
        }
Esempio n. 3
0
        private void SaveTrainingExecute()
        {
            using (var repo = new TrainingRepository())
            {
                var existing = repo.GetById(training.Id);
                if (existing == null)
                {
                    training = repo.Add(training);
                    Locator.TrainingsPlanStatic.AddTraining(training);
                }
            }

            using (var repo = new ExersizesRepository())
            {
                foreach (var exersize in exersizes)
                {
                    exersize.TrainingId = training.Id;
                    exersize.Id = repo.Add(exersize).Id;
                }
            }
            
            if (NavigationProvider.CanGoBack())
                NavigationProvider.GoBack();
        }
Esempio n. 4
0
 protected override void CleanupExecute()
 {
     Training = new Training();
     Exersizes = new ObservableCollection<Exersize>();
     base.CleanupExecute();
 }
Esempio n. 5
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>();
            }
        }
Esempio n. 6
0
 private void RemoveTrainingExecute(Training training)
 {
     this.Trainings.Remove(training);
     TotalCalories = Trainings.Sum(item => item.CaloriesMustBurned);
     Diet.Plan.Trainigs.Remove(training);
     Diet.SaveDietPlan();
 }
Esempio n. 7
0
 private void EditTrainingExecute(Training training)
 {
     NavigationProvider.Navigate(Constants.Pages.TrainingPage.AddPageParameter(Constants.NavigationParameters.TrainingId, training.Id));
 }
Esempio n. 8
0
        public void AddTraining(Training training)
        {
            InvokeInUIThread(() =>
            {
                this.Trainings.Add(training);
                TotalCalories = Trainings.Sum(item => item.CaloriesMustBurned);
            });

            Diet.Plan.Trainigs.Add(training);
            Diet.SaveDietPlan();
        }