Ejemplo n.º 1
0
        public void UpdateTrainingGoal(TrainingGoalDetails goal)
        {
            foreach (var exercise in goal.Exercises)
            {
                exercise.Id = Guid.NewGuid();
            }

            using (var conn = CreateConnection())
                using (var tran = conn.BeginTransaction())
                {
                    try
                    {
                        conn.Execute("DELETE FROM TrainingGoalExercise WHERE TrainingGoalId=@Id", goal, tran);

                        conn.Execute("UPDATE TrainingGoal SET Name=@Name WHERE Id=@Id", goal, tran);
                        conn.Execute("INSERT TrainingGoalExercise(Id,TrainingGoalId,[Index],ExerciseId,Sets,Reps,Frequency) VALUES (@Id,@TrainingGoalId,@index,@ExerciseId,@Sets,@Reps,@Frequency)", goal.Exercises.Select((e, index) => new
                        {
                            e.Id,
                            TrainingGoalId = goal.Id,
                            index,
                            e.ExerciseId,
                            e.Sets,
                            e.Reps,
                            e.Frequency
                        }), tran);
                        tran.Commit();
                    }
                    catch
                    {
                        tran.Rollback();
                        throw;
                    }
                }
        }
Ejemplo n.º 2
0
        public void CreateTrainingGoal(TrainingGoalDetails goal)
        {
            goal.Id = Guid.NewGuid();
            foreach (var exercise in goal.Exercises)
            {
                exercise.Id = Guid.NewGuid();
            }

            using (var conn = CreateConnection())
                using (var tran = conn.BeginTransaction())
                {
                    try
                    {
                        conn.Execute("INSERT INTO TrainingGoal(Id,UserId,Name,Created) VALUES(@Id,@UserId,@Name,@Created)", goal, tran);
                        conn.Execute("INSERT TrainingGoalExercise(Id,TrainingGoalId,[Index],ExerciseId,Sets,Reps,Frequency) VALUES (@Id,@TrainingGoalId,@index,@ExerciseId,@Sets,@Reps,@Frequency)", goal.Exercises.Select((e, index) => new
                        {
                            e.Id,
                            TrainingGoalId = goal.Id,
                            index,
                            e.ExerciseId,
                            e.Sets,
                            e.Reps,
                            e.Frequency
                        }), tran);
                        tran.Commit();
                    }
                    catch
                    {
                        tran.Rollback();
                        throw;
                    }
                }
        }