public async Task PushSync() { var LastSyncTime = Barrel.Current.Get <DateTime>(key: "sync"); if (LastSyncTime != null) { var user = Barrel.Current.Get <LoginResponse>(key: "user").User; try { if (user.LastUpdated > LastSyncTime) { await _fitnessService.PushSyncUser(user); } } catch (Exception ex) { Console.WriteLine(ex.Message); } var workouts = await _localDatabase.GetWorkouts(); try { if (workouts != null && workouts.Count != 0) { await _fitnessService.PushSyncWorkout(user.Id, workouts); var DeletedWorkouts = workouts.FindAll(w => w.IsDeleted == true); if (DeletedWorkouts != null && DeletedWorkouts.Count != 0) { foreach (var w in DeletedWorkouts) { await _localDatabase.DeleteWorkout(w); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } foreach (var v in workouts) { try { var workoutExercises = await _localDatabase.GetWorkoutExercises(v.WorkoutID); if (workoutExercises != null && workoutExercises.Count != 0) { await _fitnessService.PushSyncExercises(v.WorkoutID, workoutExercises); var DeletedExercises = workoutExercises.FindAll(w => w.IsDeleted == true); if (DeletedExercises != null && DeletedExercises.Count != 0) { foreach (var e in DeletedExercises) { await _localDatabase.DeleteExercise(e); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } } }