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 IActionResult UpdateCardioActivities([FromBody] CardioActivityRequest requestCardioActivity) { var user = GetUserFromToken(); if (user is null) { return(BadRequest()); } var activity = os.GetObject <CardioActivity>(requestCardioActivity.ID, true); if (activity is null || !user.ID.Equals(activity?.ActivityWorkout?.Owner)) { return(BadRequest()); } activity.Start = requestCardioActivity.StartDate; activity.End = requestCardioActivity.EndDate; activity.ActivityType = os.GetObjects <ActivityCatalog>(new WhereClause(nameof(ActivityCatalog.Name), requestCardioActivity.Name, ComparisonOperator.Equal)).FirstOrDefault(); activity.Distance = requestCardioActivity.Distance; os.CommitChanges(); return(Ok()); }