Exemplo n.º 1
0
        public async void Handle_ItemSelected(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
        {
            WorkoutTemplate templateSelected = (sender as ListView).SelectedItem as WorkoutTemplate;

            string       title        = "What Would You like to do?";
            string       cancel       = "Cancel";
            const string startWorkout = "Start Workout";
            const string edit         = "Edit";
            const string delete       = "Delete";
            string       action       = await DisplayActionSheet(title, cancel, null, startWorkout, edit, delete);

            switch (action)
            {
            case edit:
                await viewModel.EditTemplate(templateSelected);

                break;

            case delete:
            //Do Delete
            case startWorkout:
            //Do Start Worout
            default:
                break;
            }
        }
Exemplo n.º 2
0
		public static async Task<int> CreateTemplate(ObservableCollection<ExerciseViewModel> exercises, WorkoutTemplate template)
		{
			var dto = WorkoutTemplateExercisesDTOCreator.CreateWorkoutTemplateExercisesDTO (exercises, template);
			string uri = "WorkoutTemplates";
			int serverTemplateID = 0;
			try
			{
				string rawJSON = JsonConvert.SerializeObject(dto);

                string stringResponse = await ExerciseService.ServiceAPI.Post(uri, rawJSON);
                if (stringResponse == "401")
                {
                    await TokenManager.RefreshToken();
                    stringResponse = await ExerciseService.ServiceAPI.Post(uri, rawJSON);
                }

				string[] splitSingleQuoteFirstSplit = stringResponse.Split(' ');
				string templateIDKey = splitSingleQuoteFirstSplit[0];
				if(templateIDKey == "\"TemplateID")
				{
					string templateIDString = splitSingleQuoteFirstSplit[1];
					serverTemplateID = int.Parse(templateIDString);
				}else{
					throw new Exception("Not expected response in '" + uri + "' web service method)");
				}

			}catch(Exception e) {
				ErrorLogDAL.AddErrorLogRecord (e, DateTime.UtcNow, template.GymID, "CreateTemplate", "", e.Message, e.StackTrace);
			}
			return serverTemplateID;
		}
        public async Task <IActionResult> PutWorkoutTemplate(long id, WorkoutTemplate workoutTemplate)
        {
            if (id != workoutTemplate.Id)
            {
                return(BadRequest());
            }

            var authResult = await _authorisationService.AuthorizeAsync(User, workoutTemplate.Person, "SamePerson");

            if (!authResult.Succeeded)
            {
                return(new ForbidResult());
            }

            _context.Entry(workoutTemplate).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WorkoutTemplateExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
		public void Setup(){
			
			List<User> userList = new List<User> ();
			User user1 = new User();

			user1.ExercisesDirty = false;

			//user1.ExercisesDirty = false;

			user1.MultipleExerciseGroups = true;
			user1.FirstName = "Clay";
			user1.LastName = "Martin";
			user1.GymID = 8;
			user1.PhoneNumber = "502-417-1595";
			user1.ProfileID = 1;
			user1.ServerTemplateID = 1;
			user1.TemplateID = 1;

			User user2 = new User();

			user2.ExercisesDirty = false;

			//user2.ExercisesDirty = false;

			user2.MultipleExerciseGroups = false;
			user2.FirstName = "Sarah";
			user2.LastName = "Wallin";
			user2.GymID = 8;
			user2.PhoneNumber = "502-417-1595";
			user2.ProfileID = 2;
			user2.ServerTemplateID = 2;
			user2.TemplateID = 2;

			userList.Add (user1);
			userList.Add (user2);

			WorkoutTemplate user1WorkoutTemplate = new WorkoutTemplate ();
			user1WorkoutTemplate.Id = 1;
			WorkoutTemplate user2WorkoutTemplate = new WorkoutTemplate ();
			user2WorkoutTemplate.Id = 2;
			user2WorkoutTemplate.TemplateName = "Actual Template Name";

			mockWorkoutTemplate = new Mock<IWorkoutTemplate> ();

			mockWorkoutTemplate.Setup (m => m.GetWorkoutTemplateByID (user1.GymID,user1.TemplateID)).ReturnsAsync(user1WorkoutTemplate);
			mockWorkoutTemplate.Setup (m => m.GetWorkoutTemplateByID (user2.GymID,user2.TemplateID)).ReturnsAsync(user2WorkoutTemplate);

			mockUser = new Mock<IUser> ();

			mockUser.Setup (m => m.GetAllUsersWithExerciseMappings (user1.GymID)).ReturnsAsync(userList);

			mockUser.Setup (m => m.GetUserByID (user1.ProfileID)).ReturnsAsync(user1);
			mockUser.Setup (m => m.GetUserByID (user2.ProfileID)).ReturnsAsync(user2);

			memberTemplateViewModel = new MemberTemplateViewModel  (mockWorkoutTemplate.Object, user1.GymID, mockUser.Object);
		}
Exemplo n.º 5
0
		public static async Task<UserExercisesUpdateExerciseResponseDTO> CreateTemplateWithAssignment(ObservableCollection<ExerciseViewModel> exercises, WorkoutTemplate template, int profileID, bool logFeedback)
		{
			var dto = WorkoutTemplateWithAssignmentExercisesDTOCreator.CreateWorkoutTemplateExercisesDTO (exercises, template, profileID, logFeedback);
			string uri = "CreateTemplateWithAssignment";
			string rawJSON = JsonConvert.SerializeObject(dto);
            string stringResponse = await ExerciseService.ServiceAPI.Post(uri, rawJSON);
            if (stringResponse == "401")
            {
                await TokenManager.RefreshToken();
                stringResponse = await ExerciseService.ServiceAPI.Post(uri, rawJSON);
            }
			return  JsonConvert.DeserializeObject<UserExercisesUpdateExerciseResponseDTO>(stringResponse);
		}
        protected override void HandleCore(AddWorkoutTemplateRequest action)
        {
            var workoutTemplate = new WorkoutTemplate
            {
                TemplateName        = action.Name,
                TemplateDescription = action.Description
            };

            _dbContext.Create(workoutTemplate);
            _dbContext.DeleteWhere <WorkoutTemplateExercise>(wte => wte.TemplateName == action.Name);
            _dbContext.CreateRange(action.Exercises);
            _dbContext.SaveChanges();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Submits a new workout template that has been created by the user
        /// to the database.
        /// </summary>
        /// <param name="name">the name of the workout template</param>
        public void SubmitNewWorkoutTemplate(string name)
        {
            //add new workout template to database
            WorkoutTemplate newWorkoutTemplate = new WorkoutTemplate {
                Name = name, ListOfExercises = serializeListOfExercises()
            };

            workoutDB.WorkoutTemplate.InsertOnSubmit(newWorkoutTemplate);

            // Save changes to the database.
            workoutDB.SubmitChanges();

            //add new workout template to the "all" observable collection
            AllWorkoutTemplates.Add(newWorkoutTemplate);
        }
Exemplo n.º 8
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            string stringWorkoutTemplateID = "";

            //get the workout template for this workout and then get a list of all exercises in that workout based
            //on the that workout template id
            if (NavigationContext.QueryString.TryGetValue("workoutTemplateID", out stringWorkoutTemplateID))
            {
                int intWorkoutTemplateID = Convert.ToInt32(stringWorkoutTemplateID);
                CurrentWorkoutTemplate = App.ViewModel.GetExercisesFromWorkoutTemplate(intWorkoutTemplateID);
            }
            CreateExercisesGrid();
            workoutStartTime = DateTime.Now;
        }
        public async Task <ActionResult <WorkoutTemplateDTO> > PostWorkoutTemplate(WorkoutTemplate workoutTemplate)
        {
            var person = await _context.People.FindAsync(workoutTemplate.PersonId);

            var authResult = await _authorisationService.AuthorizeAsync(User, person, "SamePerson");

            if (!authResult.Succeeded)
            {
                return(new ForbidResult());
            }

            _context.WorkoutTemplates.Add(workoutTemplate);
            await _context.SaveChangesAsync();

            var dto = _mapper.Map <WorkoutTemplateDTO>(workoutTemplate);

            return(CreatedAtAction("GetWorkoutTemplate", new { id = workoutTemplate.Id }, dto));
        }
Exemplo n.º 10
0
        private void allWorkoutsSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            LongListSelector selector = sender as LongListSelector;

            //verifying our sender is actually a longlistselector
            if (selector == null)
            {
                return;
            }

            WorkoutTemplate data = selector.SelectedItem as WorkoutTemplate;

            //verfiying our send is actually a workout template
            if (data == null)
            {
                return;
            }

            NavigationService.Navigate(new Uri("/RecordWorkout.xaml?workoutTemplateID=" + data.ID, UriKind.RelativeOrAbsolute));
        }
Exemplo n.º 11
0
        public async Task <bool> EditTemplate(WorkoutTemplate template)
        {
            await _navigationService.Navigate <NewWTemplateViewModel, WorkoutTemplate>(template);

            return(true);
        }
Exemplo n.º 12
0
        public async Task FirstInit()
        {
            List <Excersize> x = await App.ExcersizeDatabase.GetItemsAsync();

            List <WorkoutTemplate> y = await App.WorkoutTemplateDatabase.GetItemsAsync();

            if (x.Count == 0 && y.Count == 0)
            {
                WorkoutTemplate pushTemplate = new WorkoutTemplate();
                pushTemplate.ID   = "pushTemplateID";
                pushTemplate.Name = "Push";
                await App.WorkoutTemplateDatabase.SaveItemAsync(pushTemplate);

                WorkoutTemplate pullTemplate = new WorkoutTemplate();
                pullTemplate.ID   = "pullTemplateID";
                pullTemplate.Name = "Pull";
                await App.WorkoutTemplateDatabase.SaveItemAsync(pullTemplate);

                WorkoutTemplate legsTemplate = new WorkoutTemplate();
                legsTemplate.ID   = "legsTemplateID";
                legsTemplate.Name = "Legs";
                await App.WorkoutTemplateDatabase.SaveItemAsync(legsTemplate);

                Excersize bpress = new Excersize();
                bpress.ID         = Guid.NewGuid().ToString();
                bpress.Name       = "Bench Press";
                bpress.Machine    = "Bench";
                bpress.Sets       = "3";
                bpress.RepRange   = "8-12";
                bpress.TemplateID = new List <string>();
                bpress.TemplateID.Add(pushTemplate.ID);
                await App.ExcersizeDatabase.SaveItemAsync(bpress);

                Excersize shoulderpress = new Excersize();
                shoulderpress.ID         = Guid.NewGuid().ToString();
                shoulderpress.Name       = "Shoulder press";
                shoulderpress.Machine    = "Squat Rack";
                shoulderpress.Sets       = "3";
                shoulderpress.RepRange   = "8-12";
                shoulderpress.TemplateID = new List <string>();
                shoulderpress.TemplateID.Add(pushTemplate.ID);
                await App.ExcersizeDatabase.SaveItemAsync(shoulderpress);

                Excersize squat = new Excersize();
                squat.ID         = Guid.NewGuid().ToString();
                squat.Name       = "Squat";
                squat.Machine    = "Squat Rack";
                squat.Sets       = "3";
                squat.RepRange   = "8-12";
                squat.TemplateID = new List <string>();
                squat.TemplateID.Add(legsTemplate.ID);
                await App.ExcersizeDatabase.SaveItemAsync(squat);

                Excersize deadLift = new Excersize();
                deadLift.ID         = Guid.NewGuid().ToString();
                deadLift.Name       = "Deadlift";
                deadLift.Machine    = "Straight Bar";
                deadLift.Sets       = "5";
                deadLift.RepRange   = "3-5";
                deadLift.TemplateID = new List <string>();
                deadLift.TemplateID.Add(pullTemplate.ID);
                await App.ExcersizeDatabase.SaveItemAsync(deadLift);
            }
        }
Exemplo n.º 13
0
 public Task <int> DeleteItemAsync(WorkoutTemplate item)
 {
     return(database.DeleteAsync(item));
 }
Exemplo n.º 14
0
 public Task <int> SaveItemAsync(WorkoutTemplate item)
 {
     return(database.InsertOrReplaceAsync(item));
 }
		public async Task SubmitWorkout (ObservableCollection<ExerciseViewModel> exercises, WorkoutTemplate template, int profileID, bool logFeedback = false, int localFeedbackSubmissionID = 0, int localUserExerciseGroupID = 0)
		{
			if (CrossConnectivity.Current.IsConnected) {
				await WorkoutTemplateMappingDAL.SubmitWorkout (exercises, template, profileID, logFeedback, localFeedbackSubmissionID, localUserExerciseGroupID);
			} 
		}