public ModalAssignMemberWorkoutPage (TemplateViewModel viewModel) { _viewModel = viewModel; this.BindingContext = _viewModel; InitializeComponent (); listView.ItemTemplate = new DataTemplate (typeof(CustomViewThreeTextCell)); listView.ItemSelected += listView_ItemSelected; cancel2Button.Clicked += async (sender2, args2) => { submitButton.IsEnabled = true; activityIndicator.IsRunning = false; activityIndicator.IsVisible = false; await Navigation.PopAsync (true); }; submitButton.Clicked += async (sender2, args2) => { if ((addMemberEntry.Text != null && addMemberEntry.Text != "") && selectedUser == null) { DependencyService.Get<ICustomDialog> ().Display ("Select another member. This member is not recognized.", "OK"); } else { if (selectedUser != null) { String[] nameArray = addMemberEntry.Text.Split (' '); if (nameArray.Count () > 0) { if (!(selectedUser.FName == nameArray [0] && selectedUser.LName == nameArray [1])) { DependencyService.Get<ICustomDialog> ().Display ("Select another member or delete the member entirely.", "OK"); } else { await WriteToRepository (); } } } else { DependencyService.Get<ICustomDialog> ().Display ("Select another member. This member is not recognized.", "OK"); } } }; addMemberEntry.TextChanged += async (sender, args) => { if (_textChangedViaListSelection) { listView.IsVisible = false; _textChangedViaListSelection = false; } else { var searchResults = await UserDAL.UserSeach (addMemberEntry.Text, App.WorkoutCreatorContext.StaffMember.GymID); listView.ItemsSource = searchResults; var rowHeight = 40; listView.RowHeight = rowHeight; listView.HeightRequest = (rowHeight * searchResults.Count ()); modalStack.WidthRequest = this.Width * .7; listView.VerticalOptions = LayoutOptions.Start; listView.HorizontalOptions = LayoutOptions.StartAndExpand; listView.IsVisible = true; } }; listView.ItemTapped += (sender, e) => { ((ListView)sender).SelectedItem = null; // de-select the row }; }
public TemplateFolder() { if (this.Template == null) { Template = new TemplateViewModel (); } if (this.Exercises == null) { this.Exercises = new ObservableCollection<ExerciseViewModel> (); } }
public void Setup(){ mockStaffMemberDataRepository = new Mock<IStaffMember> (); //Set up a template folder templateFolder = new TemplateFolder (); //Create a simple template TemplateViewModel simpleTemplate = new TemplateViewModel (); simpleTemplate.TemplateName = "Back Blaster"; simpleTemplate.TemplateDescription = "Back Blaster Description"; templateFolder.Template = simpleTemplate; //Create 2 simple exercise objects ExerciseViewModel exercise1 = new ExerciseViewModel (); exercise1.SetsIndex = 1; exercise1.RepsIndex = 2; exercise1.WeightIndex = 2; exercise1.SeatPosition1Label = 1; exercise1.SeatPosition1Value = 1; ExerciseViewModel exercise2 = new ExerciseViewModel (); exercise1.SetsIndex = 2; exercise1.RepsIndex = 1; exercise1.WeightIndex = 2; exercise1.SeatPosition1Label = 2; exercise1.SeatPosition1Value = 1; //Add exercises to observable collectin in the template folder templateFolder.Exercises.Add (exercise1); templateFolder.Exercises.Add (exercise2); StaffMember staffMember = new StaffMember (); staffMember.FirstName = "Clay"; staffMember.LastName = "Martin"; staffMember.GymID = 8; staffMember.PhoneNumber = "5024171595"; staffMember.StaffID = 132; templateFolder.StaffMember = staffMember; primaryOptionsViewModel = new PrimaryOptionsViewModel (mockStaffMemberDataRepository.Object, templateFolder); }
public TemplateListPage (User selectedUser = null) { _viewModel = new TemplateViewModel (selectedUser); if (selectedUser != null) { _viewModel.Title = "Assign Template to " + selectedUser.FullMemberName; if (_viewModel.ProfileID == 0) { _viewModel.ProfileID = selectedUser.ProfileID; } } else { _viewModel.Title = "Assign Template"; } //Sync templates with the server var templatesTask = Task.Run (async () => { await _viewModel.SyncTemplateDataWithServer (); }); InitializeComponent (); this.BindingContext = _viewModel; Action<Task> action = (actionResult) => Device.BeginInvokeOnMainThread (() => { listView.ItemsSource = _viewModel.SimpleTemplateGroups; }); templatesTask.ContinueWith (action); listView.ItemTemplate = new DataTemplate (typeof(CustomViewCellTwoTextTwoButton)); listView.ItemTemplate.SetBinding (CustomViewCellTwoTextTwoButton.SimpleTemplateProperty, "."); listView.IsGroupingEnabled = true; listView.GroupDisplayBinding = new Binding ("Key"); listView.GroupShortNameBinding = new Binding ("Key"); listView.GroupHeaderTemplate = new DataTemplate (typeof(TemplateListHeaderCell)); listView.ItemSelected += (sender, args) => { if (args.SelectedItem != null) { listView.SelectedItem = null; //TODO: Add message to profile if (selectedUser != null) { TemplateViewModel selectedViewModel = args.SelectedItem as TemplateViewModel; _viewModel.AssignTemplateCommand.Execute (selectedViewModel); } } }; ToolbarItem syncItem = new ToolbarItem { Text = "Sync", Order = ToolbarItemOrder.Primary }; syncItem.Clicked += syncItem_Clicked; ToolbarItems.Add (syncItem); _viewModel.DataSyncEvent += _viewModel_DataSyncEvent; }
public async Task<ObservableCollection<MemberTemplateViewModel>> GetAllSimpleMemberTemplates () { ObservableCollection<MemberTemplateViewModel> templateList = new ObservableCollection<MemberTemplateViewModel> (); List<User> userList = await UserDAL.GetAllUsersWithExerciseMappings (this.GymID); foreach (User userMapping in userList) { List<UserExerciseGroup> userExerciseGroupList = await UserExerciseGroupDAL.GetExerciseGroupsByProfileIDNotDeleted (userMapping.ProfileID); MemberTemplateViewModel memberTemplateViewModel = new MemberTemplateViewModel (WorkoutTemplate, this.GymID, User); TemplateViewModel templateViewModel = new TemplateViewModel (); User user = await UserDAL.GetUserByID (userMapping.ProfileID); //Process even if there are no exercise groups assigned to the member if (userExerciseGroupList == null || userExerciseGroupList.Count == 0) { templateViewModel.TemplateName = "No Workouts"; templateViewModel.TemplateDescription = "No workouts assigned"; //When a member is assigned a template, will be assigned a server template id from the server. If this id = 0, template assignment has not been made on the server templateViewModel.ServerUserExerciseGroupID = 0; templateViewModel.LocalUserExerciseGroupID = 0; templateViewModel.ProfileID = userMapping.ProfileID; templateViewModel.HasMultipleWorkouts = false; memberTemplateViewModel.TemplateName = "No Workouts"; } else { if (userExerciseGroupList.Count == 1) { UserExerciseGroup onlyExerciseGroup = userExerciseGroupList [0]; templateViewModel.TemplateName = onlyExerciseGroup.TemplateName; templateViewModel.TemplateDescription = onlyExerciseGroup.TemplateDescription; if (templateViewModel.TemplateDescription == null) { templateViewModel.TemplateDescription = ""; } templateViewModel.Id = onlyExerciseGroup.Id; //ServerExerciseGroupID must be assigned to the exercise group in order for the local client to be in sync with the server if (onlyExerciseGroup.UserWorkoutGroupID != 0) { templateViewModel.ServerUserExerciseGroupID = onlyExerciseGroup.UserWorkoutGroupID; } else { memberTemplateViewModel.IsDirty = true; } templateViewModel.LocalUserExerciseGroupID = onlyExerciseGroup.Id; templateViewModel.HasMultipleWorkouts = false; if (onlyExerciseGroup.ExerisesDirty || onlyExerciseGroup.UserWorkoutGroupID == 0) { memberTemplateViewModel.IsDirty = true; } } else { templateViewModel.TemplateName = "Multiple Workouts"; templateViewModel.TemplateDescription = "Multiple Workouts Assigned"; templateViewModel.Id = 0; templateViewModel.ServerUserExerciseGroupID = 0; templateViewModel.LocalUserExerciseGroupID = 0; templateViewModel.HasMultipleWorkouts = true; //If there are multiple userExerciseGroups assigned to the user, we need to evaluate and decide if any of them are dirty foreach (var userExerciseGroup in userExerciseGroupList) { if (userExerciseGroup.ExerisesDirty || userExerciseGroup.UserWorkoutGroupID == 0) { memberTemplateViewModel.IsDirty = true; break; } } } } memberTemplateViewModel.Id = userMapping.Id; memberTemplateViewModel.MemberName = Utility.FirstLetterToUpper (user.FName) + " " + user.LName; memberTemplateViewModel.MemberPhoneNumber = user.PhoneNumber; memberTemplateViewModel.TemplateName = templateViewModel.TemplateName; //Try to assign profileid to templateViewModel if it hasn't been assigned already if (templateViewModel.ProfileID == 0) { if (userMapping.ProfileID != 0) { templateViewModel.ProfileID = userMapping.ProfileID; } } memberTemplateViewModel.TemplateViewModelProperty = templateViewModel; templateList.Add (memberTemplateViewModel); } return templateList; }
public ReviewPage(ReviewPageViewModel viewModel, TemplateViewModel optionalTemplate = null) { this.Title = "Review Workouts"; _viewModel = viewModel; if (optionalTemplate != null) { _viewModel.SimpleExerciseCollection = new ObservableCollection<ExerciseViewModel>(); var exerciseListTask = WorkoutTemplateMappingDAL.GetMappingsByTemplateID(optionalTemplate.Id); Action<Task<List<WorkoutTemplateMapping>>> action = (actionResult) => Device.BeginInvokeOnMainThread(async () => { foreach (var mapping in actionResult.Result) { ExerciseViewModel simpleExercise = new ExerciseViewModel(); var exercise = await ExerciseDAL.GetExercisesByExerciseID(App.WorkoutCreatorContext.StaffMember.GymID, mapping.ExerciseID); if (exercise != null && exercise.Id != 0) { simpleExercise.Exercise = exercise; simpleExercise.ImageSource = exercise.ImageSource; simpleExercise.Reps = mapping.Reps; simpleExercise.Sets = mapping.Sets; //simpleExercise.TargetHRMin = mapping.TargetHRMin; //simpleExercise.TargetHRMax = mapping.TargetHRMax; simpleExercise.Duration = mapping.TargetDurationMin; simpleExercise.IsCardioExercise = exercise.CardioExID != 0 ? true : false; _viewModel.SimpleExerciseCollection.Add(simpleExercise); } else { //If exercise is not available manually throw error and log to insights try { throw new Exception("Exercise id " + mapping.ExerciseID.ToString() + "is not in the phone's database"); } catch (Exception e) { Insights.Report(e); } } } }); exerciseListTask.ContinueWith(action); } else { _viewModel.SimpleExerciseCollection = App.WorkoutCreatorContext.Exercises; allowExerciseEdits = true; } //Add reference of review page view model to each exercise view model foreach (var exerciseVM in _viewModel.SimpleExerciseCollection) { exerciseVM.SimpleExerciseCollection = _viewModel.SimpleExerciseCollection; } ListView listView = new ListView { ItemsSource = _viewModel.SimpleExerciseCollection, VerticalOptions = LayoutOptions.FillAndExpand, RowHeight = 100 }; if (allowExerciseEdits) { listView.ItemTemplate = new DataTemplate(typeof(CustomExerciseImageCell)); listView.ItemSelected += (sender, args) => { if (args.SelectedItem != null) { listView.SelectedItem = null; ExerciseViewModel exercise = (ExerciseViewModel)args.SelectedItem; this.Navigation.PushAsync(new ExercisePage(exercise, true, 1, _viewModel.CreateWorkoutOnly, _viewModel.FeedbackOnlyUser)); } }; } else { if (allowExerciseDetailsView) { listView.ItemTemplate = new DataTemplate(typeof(CustomExerciseImageCell)); listView.ItemSelected += (sender, args) => { if (args.SelectedItem != null) { listView.SelectedItem = null; ExerciseViewModel exercise = (ExerciseViewModel)args.SelectedItem; this.Navigation.PushAsync(new ExercisePage(exercise, false, 1, _viewModel.CreateWorkoutOnly, _viewModel.FeedbackOnlyUser), true); } }; } else { listView.ItemTemplate = new DataTemplate(typeof(ImageCell)); } } listView.ItemTemplate.SetBinding(ImageCell.TextProperty, "Identity"); listView.ItemTemplate.SetBinding(ImageCell.ImageSourceProperty, "ImageSource"); this.Content = listView; }
public void Setup(){ mockStaffMemberDataRepository = new Mock<IStaffMember> (); //mockCurrentConnecitivity = new Mock<IConnectivity> (); mockExercise = new Mock<IExercise> (); //Set up a template folder templateFolder = new TemplateFolder (); //Create a simple template TemplateViewModel simpleTemplate = new TemplateViewModel (); simpleTemplate.TemplateName = "Back Blaster"; simpleTemplate.TemplateDescription = "Back Blaster Description"; templateFolder.Template = simpleTemplate; //Create 2 simple exercise objects ExerciseViewModel exercise1 = new ExerciseViewModel (); exercise1.SetsIndex= 1; exercise1.RepsIndex = 2; exercise1.WeightIndex = 2; exercise1.SeatPosition1Label = 1; exercise1.SeatPosition1Value = 1; ExerciseViewModel exercise2 = new ExerciseViewModel (); exercise1.SetsIndex = 2; exercise1.RepsIndex = 1; exercise1.WeightIndex = 2; exercise1.SeatPosition1Label = 2; exercise1.SeatPosition1Value = 1; //Add exercises to observable collectin in the template folder templateFolder.Exercises.Add (exercise1); templateFolder.Exercises.Add (exercise2); StaffMember staffMember = new StaffMember (); staffMember.FirstName = "Clay"; staffMember.LastName = "Martin"; staffMember.GymID = 8; staffMember.PhoneNumber = "5024171595"; staffMember.StaffID = 132; templateFolder.StaffMember = staffMember; exercise = new Exercise (); exercise.ExerciseName = "Barbell Bench Press"; exercise.Bodypart = "Chest"; exerciseList = new List<Exercise> (); exerciseList.Add (exercise); exercise = new Exercise (); exercise.ExerciseName = "Barbell Inclie Bench Press"; exercise.Bodypart = "Chest"; exerciseList = new List<Exercise> (); exerciseList.Add (exercise); exercise = new Exercise (); exercise.ExerciseName = "Barbell Row"; exercise.Bodypart = "Back"; exerciseList = new List<Exercise> (); exerciseList.Add (exercise); exercise = new Exercise (); exercise.ExerciseName = "DB Row"; exercise.Bodypart = "Back"; exerciseList = new List<Exercise> (); exerciseList.Add (exercise); exercise = new Exercise (); exercise.ExerciseName = "DB Shoulder Press"; exercise.Bodypart = "Shoulders"; exerciseList = new List<Exercise> (); exerciseList.Add (exercise); workoutCreatorViewModel = new WorkoutContainerViewModel (templateFolder, mockExercise.Object, new mockCurrentConnectivity()); mockExercise.Setup (x => x.GetAllExercises (staffMember.GymID)).ReturnsAsync(exerciseList); }
private async void ExecuteAssignTemplateCommand (TemplateViewModel selectedViewModel) { if (IsBusy) return; IsBusy = true; //Assign member template in the local database bool successfulAssignment = await UserDAL.AssignUserTemplate (SelectedUser.ProfileID, selectedViewModel.Id); if (successfulAssignment) { int gymID = App.WorkoutCreatorContext.StaffMember.GymID; //Retrieve WorkoutTemplate serverTemplateID WorkoutTemplate workoutTemplate = await WorkoutTemplateDAL.GetWorkoutTemplateByID (gymID, selectedViewModel.Id); int serverTemplateID = workoutTemplate.WorkoutTemplateID; UserExerciseGroup userExerciseGroup = new UserExerciseGroup (); if (CrossConnectivity.Current.IsConnected) { //Attempt to assign workout template to the member on the server userExerciseGroup = await UserDAL.AddServerTemplateIDLocalAndServer (gymID, SelectedUser.ProfileID, serverTemplateID, false); } if (userExerciseGroup.Id == 0) { //Still need to map userexercisegroups (and exercises) to the user if the API cannot be accessed or the application is not connected to a network userExerciseGroup.TemplateDescription = selectedViewModel.TemplateDescription; userExerciseGroup.TemplateName = selectedViewModel.TemplateName; userExerciseGroup.ExerisesDirty = true; userExerciseGroup.LastUpdatedTime = DateTime.UtcNow; userExerciseGroup.ProfileID = SelectedUser.ProfileID; userExerciseGroup.UserWorkoutGroupID = 0; userExerciseGroup.GymID = SelectedUser.GymID; userExerciseGroup.LocalTemplateID = selectedViewModel.Id; await UserExerciseGroupDAL.AddModify (userExerciseGroup); } //Create the user exercise mapping in the local database //Assumes template exercise mappings were already made locally await UserWorkoutTemplateMappingDAL.CreateUserWorkoutTemplateMappingByTemplateID (SelectedUser.ProfileID, gymID, selectedViewModel.Id, userExerciseGroup.Id, selectedViewModel.TemplateName, selectedViewModel.TemplateDescription); //Uses session tracking Insights.Track ("Assign member", new Dictionary<string, string> () { { "template", selectedViewModel.TemplateName }, { "template id", selectedViewModel.LocalUserExerciseGroupID.ToString () }, { "Member name", SelectedUser.FName + " " + SelectedUser.LName }, { "Profile id", SelectedUser.ProfileID.ToString () } }); MessagingCenter.Send<TemplateListPage> (Application.Current.MainPage.Navigation.NavigationStack.Last () as TemplateListPage, "WorkoutAssigned"); await Application.Current.MainPage.Navigation.PopAsync (true); } else { DependencyService.Get<ICustomDialog> ().Display ("A problem occurred during assignment of the workout. Please try again.", "OK"); } IsBusy = false; }
public async Task<ObservableCollection<TemplateViewModel>> GetAllTemplates (int gymID) { ObservableCollection<TemplateViewModel> templateList = new ObservableCollection<TemplateViewModel> (); List<WorkoutTemplate> workoutTemplateList = await WorkoutTemplateDAL.GetAllTemplates (gymID); foreach (WorkoutTemplate workoutTemplate in workoutTemplateList) { if (workoutTemplate.TemplateName != "") { TemplateViewModel simpleTemplate = new TemplateViewModel (this.SelectedUser, this); simpleTemplate.TemplateName = Utility.FirstLetterToUpper (workoutTemplate.TemplateName); simpleTemplate.TemplateDescription = workoutTemplate.TemplateDescription; simpleTemplate.Id = workoutTemplate.Id; simpleTemplate.LocalUserExerciseGroupID = workoutTemplate.WorkoutTemplateID; templateList.Add (simpleTemplate); } } return templateList; }
public TemplateViewModel (User selectedUser = null, TemplateViewModel templateViewModel = null) { SimpleTemplateGroups = new ObservableCollection<Grouping<string, TemplateViewModel>> (); if (selectedUser != null) { SelectedUser = selectedUser; ProfileID = selectedUser.ProfileID; if (ProfileID != 0) { IsAssignVisible = true; } } if (templateViewModel != null) { ParentTemplateViewModel = templateViewModel; } }
public void RemoveTemplateAndExercises() { this.Template = new TemplateViewModel (); this.Exercises = new ObservableCollection<ExerciseViewModel>(); }