public IActionResult AddCardioActivities([FromBody] CardioActivityRequest cardioActivityRequest) { var user = GetUserFromToken(); if (user is null) { return(BadRequest()); } var workout = os.GetObject <Workout>(cardioActivityRequest.WorkoutID, true); if (workout is null || !user.ID.Equals(workout.Owner)) { return(BadRequest()); } CardioActivity ca = new CardioActivity(os); ca.Start = cardioActivityRequest.StartDate; ca.End = cardioActivityRequest.EndDate; ca.ActivityType = os.GetObjects <ActivityCatalog>(new WhereClause(nameof(ActivityCatalog.Name), cardioActivityRequest.Name, ComparisonOperator.Equal)).FirstOrDefault(); ca.Distance = cardioActivityRequest.Distance; workout.CardioActivities.Add(ca); os.CommitChanges(); return(Ok()); }
public void ValidCardioActivityCreated() { //--Arrange CardioActivity expected = new CardioActivity(); expected.Name = "Running"; expected.Duration = 30; expected.DistanceGoal = 12; expected.Reps = 3; expected.Rest = 10; //--Act CardioActivity actual = new CardioActivity("Running", 30, 12, 3, 10); //--Assert Assert.AreEqual(expected.Name, actual.Name); Assert.AreEqual(expected.Duration, actual.Duration); Assert.AreEqual(expected.DistanceGoal, actual.DistanceGoal); Assert.AreEqual(expected.Reps, actual.Reps); Assert.AreEqual(expected.Rest, actual.Rest); }