public static SaveModelResult SaveModel(IList<MappingModel> model, Device device)
        {
            SaveModelResult result = SaveModelResult.Success;
            foreach (MappingModel map in model.Where(m => m.HasChanges))
            {
                if (map.TraktorCommand == "Unknown")
                {
                    // We don't know this command so we won't save anything against it. At some point we need to complete the list of known traktor commands
                    result = SaveModelResult.SuccessWithNonSavedUnknownMappings;
                    continue;
                }


                // TODO: This will not work for new mappings as single will throw an exception
                var mappings = device.Data.Mappings.List.Mappings;
                Mapping deviceMap = mappings.Single(m => m.MidiNoteBindingId == map.Id && m.Type == map.Type);
                deviceMap.TraktorControlId = TraktorControl.AllIn.First(c => c.Name == map.TraktorCommand).Id;
                deviceMap.Settings.Comment = map.Comment;
                deviceMap.Settings.Deck = map.Deck;
                deviceMap.Settings.ControllerType = map.ControllerType;
                deviceMap.Settings.InteractionMode = map.InteractionMode;
                deviceMap.Settings.AutoRepeat = map.AutoRepeat;
                deviceMap.Settings.Invert = map.Invert;
                deviceMap.Settings.SoftTakeover = map.SoftTakeover;
                deviceMap.Settings.RotarySensitivity = map.RotarySensitivity;
                deviceMap.Settings.RotaryAcceleration = map.RotaryAcceleration;
                deviceMap.Settings.LedInvert = map.LedInvert;
                deviceMap.Settings.Resolution = map.Resolution;
            }

            return result;
        }
        public static List<MappingModel> CreateModel(Device device)
        {
            List<MappingModel> models = new List<MappingModel>();

            foreach (Mapping mapping in device.Data.Mappings.List.Mappings)
            {
                string midinote = device.Data.Mappings.MidiBindings.Bindings.First(b => b.BindingId == mapping.MidiNoteBindingId).MidiNote;

                models.Add(new MappingModel(mapping.MidiNoteBindingId,
                    midinote,
                    mapping.TraktorControl.Name,
                    mapping.TraktorControl.Target,
                    mapping.Settings.Comment,
                    mapping.Settings.Deck,
                    mapping.Type,
                    mapping.Settings.ControllerType,
                    mapping.Settings.InteractionMode,
                    mapping.Settings.AutoRepeat,
                    mapping.Settings.Invert,
                    mapping.Settings.SoftTakeover,
                    mapping.Settings.RotarySensitivity,
                    mapping.Settings.RotaryAcceleration,
                    mapping.Settings.LedInvert,
                    mapping.Settings.Resolution));
            }

            return models;
        }