/// <summary>
        /// Insert a new machine and/or machine group into the database
        /// </summary>
        /// <param groupName="machineName">The groupName of the machine to insert</param>
        /// <param groupName="machineGroupName">The groupName of the machine group</param>
        public void AddMachine(string machineName, string machineGroupName)
        {
            Check.ArgumentIsNullOrEmpty(machineName, "machineName");
            Check.ArgumentIsNullOrEmpty(machineGroupName, "machineGroupName");

            machineName = machineName.Trim();
            machineGroupName = machineGroupName.Trim();

            var machine = Uow.Machines.GetMachineByMachineName(machineName);
            if (machine != null)
                throw new InvalidOperationException("Machine already exists!");

            machine = new Machine(machineName);
            Uow.Machines.Add(machine);

            // Let's see if this group exists before adding a new one
            var group = Uow.MachineGroups.GetMachineGroupByGroupName(machineGroupName);
            if (group == null)
            {
                group = new MachineGroup(machineGroupName);
                Uow.MachineGroups.Add(group);
            }

            var machineGroupMap = new MachineGroupMap
            {
                iMachineID = machine.iMachineID,
                iMachineGroupID = group.iMachineGroupID
            };
            Uow.MachineGroupMaps.Add(machineGroupMap);

            Uow.Commit();
        }
        public void UpdateMachine(string oldMachineName, string newMachineName, string machineGroupName)
        {
            Check.ArgumentIsNullOrEmpty(oldMachineName, "oldMachineName");
            Check.ArgumentIsNullOrEmpty(newMachineName, "newMachineName");
            Check.ArgumentIsNullOrEmpty(machineGroupName, "machineGroupName");

            newMachineName = newMachineName.Trim();
            machineGroupName = machineGroupName.Trim();

            if (oldMachineName != newMachineName)
            {
                var newMachine = Uow.Machines.GetMachineByMachineName(newMachineName);
                if (newMachine != null)
                    throw new InvalidOperationException("Machine already exists!");
            }

            // Get the machine to update
            var machine = Uow.Machines.GetMachineByMachineName(oldMachineName);
            machine.vchMachineName = newMachineName;
            Uow.Machines.Update(machine);

            // Get the current group for the selected machine
            var currentGroup = Uow.MachineGroups.GetMachineGroupByMachineName(oldMachineName);
            if (currentGroup.vchMachineGroupName != machineGroupName)
            {
                // Machine groups are different, delete the map and make a new map
                Uow.MachineGroupMaps.Delete(Uow.MachineGroupMaps.GetMachineGroupMapByMachineIdAndGroupId(machine.iMachineID, currentGroup.iMachineGroupID));

                var group = Uow.MachineGroups.GetMachineGroupByGroupName(machineGroupName);
                if (group == null)
                {
                    group = new MachineGroup(machineGroupName);
                    Uow.MachineGroups.Add(group);
                }

                var machineGroupMap = new MachineGroupMap
                {
                    iMachineID = machine.iMachineID,
                    iMachineGroupID = group.iMachineGroupID
                };

                Uow.MachineGroupMaps.Add(machineGroupMap);
            }

            Uow.Commit();
        }
        public void Init()
        {
            _scope = new TransactionScope();

            _machine = new Machine
            {
                vchMachineName = "TESTMACHINE"
            };

            _group = new MachineGroup
            {
                vchMachineGroupName = "TESTGROUP"
            };

            _uow.Machines.Add(_machine);
            _uow.MachineGroups.Add(_group);
            _uow.Commit();

            _map = new MachineGroupMap
            {
                iMachineGroupID = _group.iMachineGroupID,
                iMachineID = _machine.iMachineID
            };

            _uow.MachineGroupMaps.Add(_map);
            _uow.Commit();
        }