private void UpdateExistingTimeSlots(PracticeRoutine entity)
        {
            var dbPracticeRoutine = Get(entity.Id);

            foreach (var timeSlot in entity)
            {
                if (timeSlot.Id > 0)
                {
                    var persistedCounterPart = dbPracticeRoutine.Where(p => p.Id == timeSlot.Id).SingleOrDefault();
                    if (persistedCounterPart != null)
                    {
                        CompareLogic     compareLogic = new CompareLogic();
                        ComparisonResult result       = compareLogic.Compare(persistedCounterPart, timeSlot);
                        if (!result.AreEqual)
                        {
                            UpdateTimeSlot(timeSlot);
                        }
                    }
                }
            }
        }
        private void InsertNewTimeSlotExercises(PracticeRoutine practiceRoutine)
        {
            foreach (var timeSlot in practiceRoutine)
            {
                foreach (var exercise in timeSlot)
                {
                    if (exercise.TimeSlotId == 0 && exercise.Id > 0)
                    {
                        exercise.TimeSlotId = timeSlot.Id;

                        Connection.ExecuteScalar <int>(sql: "sp_InsertTimeSlotExercise",
                                                       param: new
                        {
                            _exerciseId         = exercise.Id,
                            _timeSlotId         = timeSlot.Id,
                            _frequencyWeighting = exercise.FrequencyWeighting
                        },
                                                       commandType: CommandType.StoredProcedure
                                                       );
                    }
                }
            }
        }
        public void Update(PracticeRoutine entity)
        {
            Connection.ExecuteScalar <int>(sql: "sp_UpdatePracticeRoutine",
                                           param: new
            {
                _id    = entity.Id,
                _title = entity.Title
            },
                                           commandType: CommandType.StoredProcedure
                                           );

            InsertNewTimeSlots(entity);
            InsertNewTimeSlotExercises(entity);
            UpdateExistingTimeSlots(entity);
            UpdateExistingTimeSlotExercises(entity);

            DeleteMissingTimeSlotExercises(entity);
            DeleteMissingTimeSlots(entity);

            var persistedEntity = Get(entity.Id);

            entity.DateCreated = persistedEntity.DateCreated;
        }
        public void PracticeRoutineRepository_Creates_A_New_PracticeRoutine_Successfully()
        {
            Funcs.RunScript("delete-all-records.sql", Settings.AppConnectionString);

            PracticeRoutine existingPracticeRoutine;

            using (var uow = Funcs.GetUnitOfWork())
            {
                PracticeRoutine newPracticeRoutine = EntityFactory.CreateEmptyPracticeRoutine("New Practice Routine");
                uow.PracticeRoutines.Add(newPracticeRoutine);
                uow.Commit();

                existingPracticeRoutine = uow.PracticeRoutines.Get(newPracticeRoutine.Id);

                uow.PracticeRoutines.Remove(newPracticeRoutine);
                uow.Commit();
            }

            Assert.IsNotNull(existingPracticeRoutine);

            Assert.That(existingPracticeRoutine.Title, Is.EqualTo("New Practice Routine"));
            Assert.That(existingPracticeRoutine.DateCreated, Is.Not.Null);
            Assert.That(existingPracticeRoutine.DateModified, Is.Null);
        }
 private void StartEditingPracticeRoutine(PracticeRoutine practiceRoutine)
 {
     practiceRoutineEditViewModel.StartEdit(practiceRoutine);
     NavigateTo("Edit");
 }
 public void Remove(PracticeRoutine entity)
 {
     var result = Connection.Execute("sp_DeletePracticeRoutine",
                                     param: new { _id = entity.Id }, commandType: CommandType.StoredProcedure);
 }
Ejemplo n.º 7
0
 public StartEditingPracticeRoutineMessage(PracticeRoutine practiceRoutine)
 {
     PracticeRoutine = practiceRoutine;
 }
        public void PracticeRoutineRepository_Existing_PracticeRoutine_Deletes_Children_Successfully()
        {
            Funcs.RunScript("delete-all-records.sql", Settings.AppConnectionString);

            using (var uow = Funcs.GetUnitOfWork())
            {
                var exercise1 = EntityFactory.CreateExercise("Exercise 1");
                var exercise2 = EntityFactory.CreateExercise("Exercise 2");
                var exercise3 = EntityFactory.CreateExercise("Exercise 3");
                var exercise4 = EntityFactory.CreateExercise("Exercise 4");

                uow.Exercises.Add(exercise1);
                uow.Exercises.Add(exercise2);
                uow.Exercises.Add(exercise3);
                uow.Exercises.Add(exercise4);

                uow.Commit();

                TimeSlotExercise timeSlotExercise1 = new TimeSlotExercise(exercise1.Id, exercise1.Title, 3);
                TimeSlotExercise timeSlotExercise2 = new TimeSlotExercise(exercise2.Id, exercise2.Title, 3);
                TimeSlotExercise timeSlotExercise3 = new TimeSlotExercise(exercise3.Id, exercise3.Title, 3);
                TimeSlotExercise timeSlotExercise4 = new TimeSlotExercise(exercise4.Id, exercise4.Title, 3);

                List <TimeSlotExercise> timeSlotExercises1 = new List <TimeSlotExercise>
                {
                    timeSlotExercise1,
                    timeSlotExercise2
                };

                List <TimeSlotExercise> timeSlotExercises2 = new List <TimeSlotExercise>
                {
                    timeSlotExercise3
                };

                List <TimeSlotExercise> timeSlotExercises3 = new List <TimeSlotExercise>
                {
                    timeSlotExercise4
                };

                List <PracticeRoutineTimeSlot> timeSlots = new List <PracticeRoutineTimeSlot>
                {
                    new PracticeRoutineTimeSlot("Time Slot 1", 300, timeSlotExercises1),
                    new PracticeRoutineTimeSlot("Time Slot 2", 300, timeSlotExercises2),
                    new PracticeRoutineTimeSlot("Time Slot 3", 300, timeSlotExercises3)
                };

                PracticeRoutine practiceRoutine = new PracticeRoutine("Created PracticeRoutine", timeSlots);
                uow.PracticeRoutines.Add(practiceRoutine);
                uow.Commit();

                PracticeRoutine existingPracticeRoutine = uow.PracticeRoutines.Get(practiceRoutine.Id);

                // --------------------- delete some ----------------------------------------------------

                existingPracticeRoutine.Remove(existingPracticeRoutine.Where(ts => ts.Title == "Time Slot 3").Single());

                var removeExercise = existingPracticeRoutine
                                     .Where(ts => ts.Title == "Time Slot 1").Single()
                                     .Where(ex => ex.Title == "Exercise 1").Single();

                existingPracticeRoutine
                .Where(ts => ts.Title == "Time Slot 1").Single()
                .Remove(removeExercise);

                // --------------------- delete some ----------------------------------------------------

                uow.PracticeRoutines.Update(existingPracticeRoutine);
                uow.Commit();

                var modifiedPracticeRoutine = uow.PracticeRoutines.Get(practiceRoutine.Id);

                var timeSlotCount = modifiedPracticeRoutine.Count();  // should be one less after deletion of timeslot.

                var removedExercise = modifiedPracticeRoutine
                                      .Where(ts => ts.Title == "Time Slot 1").Single()
                                      .Where(ex => ex.Title == "Exercise 1").SingleOrDefault();

                var timeSlot1ExerciseCount = modifiedPracticeRoutine
                                             .Where(ts => ts.Title == "Time Slot 1").Single()
                                             .Count; // should be one less after deletion of exercise.

                var timeSlot1RemainingExercise = modifiedPracticeRoutine
                                                 .Where(ts => ts.Title == "Time Slot 1").Single()
                                                 .Single(); // should be one less after deletion of exercise.

                var timeSlot2Exercise = modifiedPracticeRoutine
                                        .Where(ts => ts.Title == "Time Slot 2").Single()
                                        .Single(); // should be one less after deletion of exercise.

                Assert.AreEqual(2, timeSlotCount, "There should only be two time slots left (Time Slot 3 and its children have been deleted");

                Assert.AreEqual(1, timeSlot1ExerciseCount);
                Assert.That(timeSlot1RemainingExercise.Title, Is.EqualTo("Exercise 2"), "The last remaining exercise in Time Slot 1 should be Exercise 2");
                Assert.That(timeSlot2Exercise.Title, Is.EqualTo("Exercise 3"), "The exercise in Time Slot 2 should be Exercise 3");
            }
        }
        public void PracticeRoutineRepository_Update_New_PracticeRoutine_Updates_New_TimeSlotExercises()
        {
            Funcs.RunScript("delete-all-records.sql", Settings.AppConnectionString);

            using (var uow = Funcs.GetUnitOfWork())
            {
                var exercise1 = EntityFactory.CreateExercise("Exercise 1");
                var exercise2 = EntityFactory.CreateExercise("Exercise 2");

                uow.Exercises.Add(exercise1);
                uow.Exercises.Add(exercise2);

                uow.Commit();

                TimeSlotExercise timeSlotExercise1 = new TimeSlotExercise(exercise1.Id, exercise1.Title, 3);
                TimeSlotExercise timeSlotExercise2 = new TimeSlotExercise(exercise2.Id, exercise2.Title, 3);

                List <TimeSlotExercise> timeSlotExercises1 = new List <TimeSlotExercise>
                {
                    timeSlotExercise1,
                    timeSlotExercise2
                };

                List <PracticeRoutineTimeSlot> timeSlots = new List <PracticeRoutineTimeSlot>
                {
                    new PracticeRoutineTimeSlot("Time Slot 1", 300, timeSlotExercises1)
                };

                PracticeRoutine practiceRoutine = new PracticeRoutine("Created PracticeRoutine", timeSlots);
                uow.PracticeRoutines.Add(practiceRoutine);
                uow.Commit();

                PracticeRoutine insertedPracticeRoutine = uow.PracticeRoutines.Get(practiceRoutine.Id);

                var modifiedTimeSlot = insertedPracticeRoutine
                                       .Where(tslot => tslot.Title == "Time Slot 1").Single();

                var modifiedExercise = insertedPracticeRoutine
                                       .Where(tslot => tslot.Title == "Time Slot 1").Single()
                                       .Where(ex => ex.Title == "Exercise 1").ToList()
                                       .First();

                modifiedTimeSlot.Title           = "Modified Time Slot 1";
                modifiedTimeSlot.AssignedSeconds = 600;

                modifiedExercise.FrequencyWeighting = 10;

                uow.PracticeRoutines.Update(insertedPracticeRoutine);
                uow.Commit();

                var modifiedPracticeRoutine = uow.PracticeRoutines.Get(practiceRoutine.Id);

                var changedTimeSlot = modifiedPracticeRoutine
                                      .Where(tslot => tslot.Title == "Modified Time Slot 1").Single();

                var exerciseCount = modifiedPracticeRoutine
                                    .Where(tslot => tslot.Title == "Modified Time Slot 1").Single()
                                    .Count();

                var changedExercise = modifiedPracticeRoutine
                                      .Where(tslot => tslot.Title == "Modified Time Slot 1").Single()
                                      .Where(ex => ex.Title == "Exercise 1")
                                      .SingleOrDefault();


                var unchangedExercise = modifiedPracticeRoutine
                                        .Where(tslot => tslot.Title == "Modified Time Slot 1").Single()
                                        .Where(ex => ex.Title == "Exercise 2")
                                        .SingleOrDefault();

                Assert.That(changedTimeSlot.AssignedSeconds, Is.EqualTo(600));

                Assert.That(changedExercise.FrequencyWeighting, Is.EqualTo(10));
                Assert.That(unchangedExercise.FrequencyWeighting, Is.EqualTo(3));

                Assert.That(exerciseCount, Is.EqualTo(2));
            }
        }
Ejemplo n.º 10
0
 public void Update(PracticeRoutine entity)
 {
     throw new NotImplementedException();
 }