/// <summary> /// adds created workout from specific user /// </summary> /// <param name="workout"></param> /// <param name="user"></param> public void AddWorkouts(Workout workout, User user) { using (SqlConnection connection = new SqlConnection(connectionString)) if (workout.GetType() == typeof(Strength)) { connection. Query($"dbo.InsertWorkout {workout.WorkoutType}, {user.ID}, " + $"'{workout.WhenWorkOutOccured}', {workout.MinutesWorkedOut}, " + $"'{workout.PointsForWorkout.ToString()}', '{null}'"); } else if (workout.GetType() == typeof(Walking) || workout.GetType() == typeof(Running) || workout.GetType() == typeof(Swimming)) { WorkoutWithDistance workout1 = workout as WorkoutWithDistance; connection. Query($"dbo.InsertWorkout {workout1.WorkoutType}, {user.ID}, " + $"'{workout1.WhenWorkOutOccured}', {workout1.MinutesWorkedOut}, " + $"'{workout1.PointsForWorkout.ToString()}', '{workout1.DistanceKM.ToString()}'"); } }
/// <summary> /// sends back a string for specific workout the way it should be printed /// </summary> /// <param name="workout"></param> /// <returns></returns> public string PrintStatistic(Workout workout) { List <String> listToSend = new List <String>(); string textPrint = ""; if (workout.GetType() == typeof(Strength)) { textPrint = $"\n{TypeOfWorkout.Strength.ToString()}\n"; } else if (workout.GetType() == typeof(Walking) || workout.GetType() == typeof(Running) || workout.GetType() == typeof(Swimming)) { WorkoutWithDistance workout1 = workout as WorkoutWithDistance; if (workout.GetType() == typeof(Walking)) { textPrint = $"\n{TypeOfWorkout.Walking.ToString()}\n"; } else if (workout.GetType() == typeof(Running)) { textPrint = $"\n{TypeOfWorkout.Running.ToString()}\n"; } else if (workout.GetType() == typeof(Swimming)) { textPrint = $"\n{TypeOfWorkout.Swimming.ToString()}\n"; } textPrint += $"Distans: {workout1.DistanceKM}\n"; } textPrint += $"Datum: {workout.WhenWorkOutOccured.ToString("yyyy/MM/dd")}\n" + $"Minuter: {workout.MinutesWorkedOut}\n" + $"Poäng: {workout.PointsForWorkout}\n"; return(textPrint); }