/// <summary> /// Checks the API to get a new list of muscle groups /// </summary> private void ResetMuscleGroupView() { MuscleGroup.GetMusclegroups(); dataGridViewMuscleGroups.DataSource = ""; dataGridViewMuscleGroups.DataSource = MuscleGroup.muscleGroupList; }
public int UpdateMuscleGroup(MuscleGroup muscleGroup) { lock (locker) { return(database.Update(muscleGroup)); } }
private void buttonSaveChanges_Click(object sender, EventArgs e) { // 1. Get details int muscleGroupId = Convert.ToInt32(textBoxId.Text); string muscleGroupName = textBoxEditName.Text; // 2. Create object MuscleGroup muscleGroup = new MuscleGroup(muscleGroupId, muscleGroupName); // 3. Convert to JSON var jsonData = JsonConvert.SerializeObject(muscleGroup); // 4. Create request, send it, and get response APIRequests request = new APIRequests(); string url = $"{request.allMuscleGroupsEndpoint}/{muscleGroupId}/{muscleGroupName}"; var response = request.SendPathRequestData(url); // 5. Handle response if (response.Contains("Successfully")) { MessageBox.Show("Successfully modified the muscle group"); textBoxEditName.Text = ""; ResetMuscleGroupView(); } else { MessageBox.Show("Something went wrong, and we couldn't edit the muscle group"); } }
public async Task AssignMuscleGroupsShouldAssignCorrectMuscleGroupsToExercise() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var dbContext = new ApplicationDbContext(optionsBuilder.Options); var workoutService = new WorkoutsService(dbContext); var muscleGroup = new MuscleGroup { Name = "testName", }; await dbContext.MuscleGroups.AddAsync(muscleGroup); await dbContext.SaveChangesAsync(); var exerciseToAdd = new ExerciseInputModel(); var result = workoutService.AssignMuscleGroups(exerciseToAdd); Assert.NotNull(result.MuscleGroups); Assert.Equal("testName", result.MuscleGroups.FirstOrDefault().Text); Assert.Equal("1", result.MuscleGroups.FirstOrDefault().Value); }
public IHttpActionResult PutMuscleGroup(int id, MuscleGroup muscleGroup) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != muscleGroup.MuscleGroupId) { return(BadRequest()); } db.Entry(muscleGroup).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MuscleGroupExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult SearchForExercises(MuscleGroup muscleGroup) { ExerciseType searchCriteria = new ExerciseType { muscleGroup = muscleGroup }; //if (muscleGroup != null) // searchCriteria.muscleGroup = (MuscleGroup)muscleGroup; //if (equipment != null) // searchCriteria.equipment = (Equipment)equipment; //if (intensity != null) // searchCriteria.intensity = (Intensity)intensity; //if (ysnAccessibility != null) // searchCriteria.ysnAccessibility = (bool)ysnAccessibility; ExerciseResultsVM model = new ExerciseResultsVM { possibleExercises = ExerciseTypeDAL.GetSearchResults(searchCriteria) }; if (!model.possibleExercises.Any()) { model.strSearchMessage = "No results for that search. Please select another."; } return(PartialView("_ExerciseSearchResults", model)); }
private void initMuscleGroup() { muscleGroups = new MuscleGroup[7] { new MuscleGroup("Head", HumanoidParts.MucleGroupIndex.HEAD, bodyDic[HumanBodyBones.Head] ), new MuscleGroup("Body", HumanoidParts.MucleGroupIndex.BODY, bodyDic[HumanBodyBones.Chest], bodyDic[HumanBodyBones.Hips] ), new MuscleGroup("RightHand", HumanoidParts.MucleGroupIndex.RHAND, bodyDic[HumanBodyBones.RightUpperArm], bodyDic[HumanBodyBones.RightLowerArm], bodyDic[HumanBodyBones.RightHand] ), new MuscleGroup("LeftHand", HumanoidParts.MucleGroupIndex.LHAND, bodyDic[HumanBodyBones.LeftUpperArm], bodyDic[HumanBodyBones.LeftLowerArm], bodyDic[HumanBodyBones.LeftHand] ), new MuscleGroup("RightFoot", HumanoidParts.MucleGroupIndex.RFOOT, bodyDic[HumanBodyBones.RightUpperLeg], bodyDic[HumanBodyBones.RightLowerLeg], bodyDic[HumanBodyBones.RightFoot] ), new MuscleGroup("LeftFoot", HumanoidParts.MucleGroupIndex.LFOOT, bodyDic[HumanBodyBones.LeftUpperLeg], bodyDic[HumanBodyBones.LeftLowerLeg], bodyDic[HumanBodyBones.LeftFoot] ), null }; }
public async Task<IActionResult> PutMuscleGroup(int id, MuscleGroup muscleGroup) { if (id != muscleGroup.Id) { return BadRequest(); } _context.Entry(muscleGroup).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MuscleGroupExists(id)) { return NotFound(); } else { throw; } } return NoContent(); }
public async Task<ActionResult<MuscleGroup>> PostMuscleGroup(MuscleGroup muscleGroup) { _context.MuscleGroups.Add(muscleGroup); await _context.SaveChangesAsync(); return muscleGroup; }
public async Task <IActionResult> Edit(int id, MuscleGroup obj) { if (ModelState.IsValid) { try { await _muscleGroupService.UpdateAsync(obj); TempData["confirm"] = obj.Name + " foi editado com sucesso."; (_cache.Get("muscleGroup") as List <MuscleGroup>).Find(x => x.Id == obj.Id).Name = obj.Name; return(RedirectToAction(nameof(Index))); } catch (ApplicationException e) { return(RedirectToAction(nameof(Error), new { message = e.Message })); } } if (id != obj.Id) { return(RedirectToAction(nameof(Error), new { message = "Id's não correspondem" })); } TempData["erro"] = "Erro ao editar."; return(RedirectToAction(nameof(Index))); }
public async Task CreateExerciseAsync(string name, string videoUrl, MuscleGroup muscleGroup, string description, string creatorName, bool isAdmin) { var exercise = new Exercise { Name = name, CreatedOn = DateTime.UtcNow, VideoUrl = videoUrl, MuscleGroup = muscleGroup, Description = description, CreatorName = creatorName, }; if (isAdmin) { exercise.IsCustom = false; } else { exercise.IsCustom = true; } await this.exercisesRepository.AddAsync(exercise); await this.exercisesRepository.SaveChangesAsync(); }
public IActionResult Add(AddExerciseViewModel addExerciseViewModel) { string user = User.Identity.Name; ApplicationUser userLoggedIn = context.Users.Single(c => c.UserName == user); if (ModelState.IsValid) { //Create user id connection to put into new exercise, linking ApplciationUser and Exercise // Add the new Exercise to my existing exercises MuscleGroup newMuscleGroup = context.MuscleGroups.Single(c => c.MuscleGroupID == addExerciseViewModel.MuscleGroupID); DateTime datecreated = DateTime.Now; //Created outside so if I use for loop in future, all iterations will be the same. Exercise newExercise = new Exercise { Name = addExerciseViewModel.Name, Description = addExerciseViewModel.Description, MuscleGroup = newMuscleGroup, OwnerId = userLoggedIn.Id, DateCreated = datecreated//Pay attention to this, creates time stamp for creation of entry }; context.Exercises.Add(newExercise); context.SaveChanges(); return(Redirect("/Exercise")); } else { AddExerciseViewModel populateFields = new AddExerciseViewModel(context.MuscleGroups.Where(c => c.OwnerId == userLoggedIn.Id).ToList()); //This is needed in case the ModelState is not valid, it will keep the categories drop down populated. return(View(populateFields)); } }
public async Task <IActionResult> Edit(int id, [Bind("Name,IsDeleted,DeletedOn,Id,CreatedOn,ModifiedOn")] MuscleGroup muscleGroup) { if (id != muscleGroup.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(muscleGroup); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MuscleGroupExists(muscleGroup.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(muscleGroup)); }
public async Task <IActionResult> Edit(int id, [Bind("muscleGroupID,WorkoutsID,name,description,muscleCategory")] MuscleGroup muscleGroup) { if (id != muscleGroup.muscleGroupID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(muscleGroup); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MuscleGroupExists(muscleGroup.muscleGroupID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(muscleGroup)); }
public async Task <IActionResult> Create([Bind("muscleGroupID,WorkoutsID,name,description, muscleCategory")] MuscleGroup muscleGroup) { //AppMuscleDbContext db = new AppMuscleDbContext(); // bool IsMuscleNameExist = db.MuscleGroup.Any //(x => x.muscle == muscleGroup.muscle && x.muscleGroupID != muscleGroup.muscleGroupID); // if (IsMuscleNameExist == true) // { // ModelState.AddModelError("muscle", "muscle already exists"); // } if (string.IsNullOrEmpty(muscleGroup.name)) { ModelState.AddModelError(nameof(muscleGroup.name), "Please enter a WorkOut"); } //if (ModelState.GetFieldValidationState(nameof(muscleGroup.muscle)) // == ModelValidationState.Valid // && muscleGroup.muscle.Contains("")) if (ModelState.IsValid) { _context.Add(muscleGroup); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(muscleGroup)); }
private static List <MuscleGroup> GetMuscleGroupList(int intExerciseTypeID) { List <MuscleGroup> retval = new List <MuscleGroup>(); // create and open connection NpgsqlConnection conn = DatabaseConnection.GetConnection(); conn.Open(); // define a query string query = "SELECT \"muscleGroup\" FROM \"muscleExercise\" WHERE intExerciseTypeID = " + intExerciseTypeID; NpgsqlCommand cmd = new NpgsqlCommand(query, conn); // execute query NpgsqlDataReader dr = cmd.ExecuteReader(); // read all rows and output the first column in each row while (dr.Read()) { MuscleGroup muscleGroup = (MuscleGroup)Enum.Parse(typeof(MuscleGroup), dr["muscleGroup"].ToString()); retval.Add(muscleGroup); } conn.Close(); return(retval); }
// TODO: correct insert public int SaveMuscleGroup(MuscleGroup muscleGroup) { lock (locker) { return(database.Insert(muscleGroup)); } }
public Exercise(int exerciseId, string exerciseName, MuscleGroup muscleGroup, string description, string photoAbbv) : base(exerciseId) { ExerciseName = exerciseName; MuscleGroup = muscleGroup; Description = description; PhotoAbbv = photoAbbv; }
public ActionResult DeleteConfirmed(int id) { MuscleGroup muscleGroup = db.MuscleGroups.Find(id); db.MuscleGroups.Remove(muscleGroup); db.SaveChanges(); return(RedirectToAction("Index")); }
public void AddMuscleGroup_EmptyOrNullSet_GoesToPrimary() { var m = new MuscleGroup(); exercise.AddMuscleGroup(m); Assert.Equal(exercise.PrimaryMuscleGroup, m); Assert.NotNull(exercise.PrimaryMuscleGroupId); }
private void CustomExerciseForm_ContentLoaded(object sender, DataFormContentLoadEventArgs e) { ComboBox exerciseTypes = CustomExerciseForm.FindNameInContent("ExerciseTypes") as ComboBox; ComboBox muscleGroups = CustomExerciseForm.FindNameInContent("MuscleGroups") as ComboBox; context.Load <ExerciseType>(context.GetExerciseTypesQuery(), LoadBehavior.RefreshCurrent, (ExerciseTypesLoaded) => { if (!ExerciseTypesLoaded.HasError) { exerciseTypes.ItemsSource = ExerciseTypesLoaded.Entities; exerciseTypes.SelectedIndex = 0; } }, null); context.Load <MuscleGroup>(context.GetMuscleGroupsQuery(), LoadBehavior.RefreshCurrent, (MuscleGroupsLoaded) => { if (!MuscleGroupsLoaded.HasError) { muscleGroups.ItemsSource = MuscleGroupsLoaded.Entities; muscleGroups.SelectedIndex = 0; } }, null); exerciseTypes.SelectionChanged += (sev, eve) => { ExerciseType selected = exerciseTypes.SelectedItem as ExerciseType; if (selected != null) { if (selected.id > 0) { if (selected.type_name == "Weight Training") { muscleGroups.Visibility = Visibility.Visible; } else { muscleGroups.Visibility = Visibility.Collapsed; } } else { muscleGroups.Visibility = Visibility.Collapsed; } // The exercise_type field is required so you must set this in order to pass validation if (selected.id > 0) { (CustomExerciseForm.CurrentItem as FitnessTrackerPlus.Web.Data.Exercise).exercise_type = selected.id; } } }; muscleGroups.SelectionChanged += (sev, eve) => { selectedGroup = muscleGroups.SelectedItem as MuscleGroup; }; }
// <summary> Creating model pairs from all available model instances.</summary> private void CreateModelPairs() { for (int i = 0; i < MuscleGroups.Count; i += 2) { MuscleGroup item1 = MuscleGroups[i]; MuscleGroup item2 = i + 1 < MuscleGroups.Count ? MuscleGroups[i + 1] : null; ModelPairs.Add(new ModelPair(item1, item2)); } }
private ExerciseType(MuscleGroup muscleGroup, string strName, int intCaloriesBurned, bool ysnAccessibility, Intensity intensity, Equipment equipment, int intTime) { this.muscleGroup = muscleGroup; this.strName = strName; this.intCaloriesBurned = intCaloriesBurned; this.ysnAccessibility = ysnAccessibility; this.intensity = intensity; this.equipment = equipment; this.intTime = intTime; }
// // GET: /MuscleGroup/Delete/5 public ActionResult Delete(int id = 0) { MuscleGroup musclegroup = db.MuscleGroups.Find(id); if (musclegroup == null) { return(HttpNotFound()); } return(View(musclegroup)); }
public void AddMuscleGroup_HasPrimary_GoesToSecondary() { var m1 = new MuscleGroup(); var m2 = new MuscleGroup(); exercise.AddMuscleGroup(m1); exercise.AddMuscleGroup(m2); Assert.Equal(exercise.SecondaryMuscleGroups.Count, 1); Assert.Equal(exercise._exerciseSecondaryMuscleGroups.Count, 1); }
public ActionResult Edit([Bind(Include = "GroupId,GroupName")] MuscleGroup muscleGroup) { if (ModelState.IsValid) { db.Entry(muscleGroup).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(muscleGroup)); }
internal MuscleGroup Create(MuscleGroup newMuscleGroup) { string sql = @" INSERT INTO musclegroups(userId, name) VALUES(@UserId, @Name); SELECT LAST_INSERT_ID() "; newMuscleGroup.Id = _db.ExecuteScalar <int>(sql, newMuscleGroup); return(newMuscleGroup); }
public IHttpActionResult GetMuscleGroup(int id) { MuscleGroup muscleGroup = db.MuscleGroups.Find(id); if (muscleGroup == null) { return(NotFound()); } return(Ok(muscleGroup)); }
public async Task <ActionResult <MuscleGroup> > GetMuscleGroupByMuscleGroupIdAsync(int muscleGroupId) { MuscleGroup dbMuscleGroup = await _repository.GetMuscleGroupAsync(muscleGroupId); if (dbMuscleGroup == null) { return(NotFound()); } return(Ok(_mapper.Map <Data.Models.MuscleGroup>(dbMuscleGroup))); }
public ActionResult Create([Bind(Include = "GroupId,GroupName")] MuscleGroup muscleGroup) { if (ModelState.IsValid) { db.MuscleGroups.Add(muscleGroup); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(muscleGroup)); }
private void AddColumnParams(OracleCommand command, MuscleGroup entity) { command.Parameters.Add("name", entity.Name); }
private MuscleGroup InstantiateEntityFromReader(OracleDataReader reader) { var entity = new MuscleGroup(reader.GetString(1)) { Id = reader.GetInt64(0) }; return entity; }
private IDomainIdentifiable<long> CreateMuscleGroup(string name = "Neck") { var muscleGroup = new MuscleGroup(name); IDomainIdentifiable<long> createdMuscleGroup = _service.Create(muscleGroup); return createdMuscleGroup; }