protected override void OnNavigatedTo(NavigationEventArgs e) { while (NavigationService.BackStack.Any()) { NavigationService.RemoveBackEntry(); } if (e.NavigationMode != NavigationMode.Back) { string trainingId; int Id; if (NavigationContext.QueryString.TryGetValue("trainingId", out trainingId)) if (int.TryParse(trainingId, out Id)) trainingDay = App.FitAndGymViewModel.GetTrainingById(Id); } }
public void AddNewTraining(TrainingDay newTraining) { int index = 0; foreach (TrainingDay training in TrainingDays.ToList()) { if (newTraining.StartTime <= training.StartTime) break; ++index; } TrainingDays.Insert(index, newTraining); db.TrainingDays.InsertOnSubmit(newTraining); Deployment.Current.Dispatcher.BeginInvoke(() => db.SubmitChanges()); }
public void UpdateTraining(TrainingDay trainingToUpdate) { int index = 0; TrainingDay trToUpdate = GetTrainingById(trainingToUpdate.TrainingDayId); if (trToUpdate == null) throw new Exception("Training to edit not found - from UpdateTraining"); TrainingDays.Remove(trToUpdate); db.TrainingDays.DeleteOnSubmit(trToUpdate); db.ExTrDayConnectors.DeleteAllOnSubmit( db.ExTrDayConnectors.Where(x => x._trainingDayId == trainingToUpdate.TrainingDayId)); foreach (TrainingDay training in TrainingDays.ToList()) { if (trainingToUpdate.StartTime <= training.StartTime) break; ++index; } TrainingDays.Insert(index, trainingToUpdate); trainingToUpdate.TrainingDayId = 0; db.TrainingDays.InsertOnSubmit(trainingToUpdate); Deployment.Current.Dispatcher.BeginInvoke(() => db.SubmitChanges()); }
public void DeleteTraining(TrainingDay trainingToDelete) { TrainingDay trToDelete = GetTrainingById(trainingToDelete.TrainingDayId); if (trToDelete == null) throw new Exception("Training to delete not found - from DeleteTraining"); TrainingDays.Remove(trToDelete); NotifyPropertyChanged("IncomingTrainingDays"); db.TrainingDays.DeleteOnSubmit(trToDelete); db.ExTrDayConnectors.DeleteAllOnSubmit( db.ExTrDayConnectors.Where(x => x._trainingDayId == trainingToDelete.TrainingDayId)); db.SubmitChanges(); }
public TrainingDay Copy() { var copiedTraining = new TrainingDay() { TrainingDayId = 0, DurationInMinutes = this.DurationInMinutes, TrainingDayName = this.TrainingDayName, Hydration = this.Hydration, StartTime = this.StartTime, OtherInfo = this.OtherInfo, }; foreach (ExTrDayConn item in this.ExConns) copiedTraining.ExConns.Add(new ExTrDayConn() { Exercise = item.Exercise, TrainingDay = copiedTraining }); return copiedTraining; }
private void CheckIfEditOrAddActionRequiredAsync() { string action; if (NavigationContext.QueryString.TryGetValue("action", out action)) { if (action == "edit") { string trIdStr; int trId; if (NavigationContext.QueryString.TryGetValue("trId", out trIdStr) && Int32.TryParse(trIdStr, out trId)) { _trToEdit = App.FitAndGymViewModel.GetTrainingById(trId); if (_trToEdit != null) { _viewModel = new TrainingPageViewModel(_trToEdit); DataContext = _viewModel; } else throw new Exception(String.Format("Not found Training with id = {0} in database invoked from TrainingPage!", trId)); } else throw new Exception("Wrong NavigationContext.QueryString 'trId' in TrainingPage"); } else if (action == "add") { _viewModel = new TrainingPageViewModel(); DataContext = _viewModel; } else throw new Exception(String.Format("Wrong NavigationContext.QueryString (action) in TrainingPage. Action = '{0}'", action)); _viewModel.ValidationError += _viewModel_ValidationError; } }