public IActionResult AddStrengthActivity([FromBody] StrengthActivityRequest strengthActivityRequest) { var user = GetUserFromToken(); if (user is null) { return(BadRequest()); } var set = os.GetObject <StrengthActivitySet>(strengthActivityRequest.StrenghtActivitySetID, true); if (set is null || !user.ID.Equals(set?.ActivityWorkout?.Owner)) { return(BadRequest()); } StrengthActivity strengthActivity = new StrengthActivity(os); strengthActivity.Start = strengthActivityRequest.StartDate; strengthActivity.End = strengthActivityRequest.EndDate; strengthActivity.ActivityType = os.GetObjects <ActivityCatalog>(new WhereClause(nameof(ActivityCatalog.Name), strengthActivityRequest.Name, ComparisonOperator.Equal)).FirstOrDefault(); strengthActivity.SortIndex = strengthActivityRequest.SortIndex; strengthActivity.Reps = strengthActivityRequest.Reps; set.StrenghtActivities.Add(strengthActivity); os.CommitChanges(); return(Ok()); }
public IActionResult UpdateStrengthActivity([FromBody] StrengthActivityRequest strengthActivityRequest) { var user = GetUserFromToken(); if (user is null) { return(BadRequest()); } var activity = os.GetObject <StrengthActivity>(strengthActivityRequest.ID, true); if (activity is null || !user.ID.Equals(activity?.ActivitySet?.ActivityWorkout?.Owner)) { return(BadRequest()); } activity.Start = strengthActivityRequest.StartDate; activity.End = strengthActivityRequest.EndDate; activity.ActivityType = os.GetObjects <ActivityCatalog>(new WhereClause(nameof(ActivityCatalog.Name), strengthActivityRequest.Name, ComparisonOperator.Equal)).FirstOrDefault(); activity.Reps = strengthActivityRequest.Reps; os.CommitChanges(); return(Ok()); }