public void UpdateWorkout(WorkoutDetails workout)
        {
            foreach (var set in workout.Sets.Where(r => r.Id == Guid.Empty))
            {
                set.Id = Guid.NewGuid();
            }
            using (var conn = CreateConnection())
                using (var tran = conn.BeginTransaction())
                {
                    try
                    {
                        conn.Execute("DELETE FROM WorkoutSet WHERE WorkoutId=@Id", new { workout.Id }, tran);

                        conn.Execute("UPDATE Workout SET Time=@Time, Duration=@Duration, Comment=@Comment WHERE Id=@Id", workout, tran);
                        conn.Execute("INSERT INTO WorkoutSet(Id,WorkoutId,[Index],ExerciseId,Reps,Weights,WeightsBW,Load,LoadBW) VALUES(@Id,@WorkoutId,@Index,@ExerciseId,@Reps,@Weights,@WeightsBW,@Load,@LoadBW)", workout.Sets.Select((s, i) => new
                        {
                            s.Id,
                            WorkoutId = workout.Id,
                            Index     = i,
                            s.ExerciseId,
                            s.Reps,
                            s.Weights,
                            s.WeightsBW,
                            s.Load,
                            s.LoadBW
                        }), tran);
                        tran.Commit();
                    }
                    catch
                    {
                        tran.Rollback();
                        throw;
                    }
                }
        }
 public void CreateWorkout(WorkoutDetails workout)
 {
     workout.Id      = Guid.NewGuid();
     workout.Created = DateTimeOffset.Now;
     foreach (var set in workout.Sets ?? Enumerable.Empty <WorkoutSet>())
     {
         set.Id = Guid.NewGuid();
     }
     using (var conn = CreateConnection())
         using (var tran = conn.BeginTransaction())
         {
             try
             {
                 conn.Execute("INSERT INTO Workout(Id, UserId, Time, Duration, Comment) VALUES(@Id, @UserId, @Time, @Duration, @Comment)", workout, tran);
                 if (workout.Sets != null)
                 {
                     conn.Execute("INSERT INTO WorkoutSet(Id,WorkoutId,[Index],ExerciseId,Reps,Weights,WeightsBW,Load,LoadBW) VALUES(@Id,@WorkoutId,@Index,@ExerciseId,@Reps,@Weights,@WeightsBW,@Load,@LoadBW)", workout.Sets.Select((s, i) => new
                     {
                         s.Id,
                         WorkoutId = workout.Id,
                         Index     = i,
                         s.ExerciseId,
                         s.Reps,
                         s.Weights,
                         s.WeightsBW,
                         s.Load,
                         s.LoadBW
                     }), tran);
                 }
                 tran.Commit();
             }
             catch
             {
                 workout.Id = Guid.Empty;
                 foreach (var set in workout.Sets ?? Enumerable.Empty <WorkoutSet>())
                 {
                     set.Id = Guid.Empty;
                 }
                 tran.Rollback();
                 throw;
             }
         }
 }
 public void RestoreWorkout(Guid id, out WorkoutDetails workout)
 {
     throw new NotImplementedException();
 }