private ContactPreferences getContactPreferencesToUpdate(ContactPreferencesViewModel preferences,
            string[] selectedPreferences, string[] allPreferences)
        {
            //first get list of selected prefences
            var listofSelectedPreferences = new List<Preference>();
            foreach (string preference in selectedPreferences)
            {
                string[] splitPreferences = preference.Split('/');
                listofSelectedPreferences.Add(new Preference
                {
                    Category = splitPreferences[0],
                    Value = splitPreferences[1]
                });
            }

            //manual mapping from ContactPreferencesViewModel to ContactPreferences
            var preferencesToUpdate = new ContactPreferences();
            preferencesToUpdate.Preferences = new List<Preference>();
            preferencesToUpdate.ExternalContactNumber = preferences.ExternalContactNumber;
            preferencesToUpdate.ExternalAddressNumber = preferences.ExternalAddressNumber;

            //loop through each preference
            foreach (string preference in allPreferences)
            {
                string[] splitPreferences = preference.Split('/');
                string preferenceCategory = splitPreferences[0];
                string preferenceValue = splitPreferences[1];
                //check if was actually selected..
                bool selected =
                    listofSelectedPreferences.Any(
                        s => s.Category.Equals(preferenceCategory) && s.Value.Equals(preferenceValue));
                preferencesToUpdate.Preferences.Add(new Preference
                {
                    Category = preferenceCategory,
                    Value = preferenceValue,
                    Selected = selected
                });
            }
            return preferencesToUpdate;
        }
 public ActionResult SavePreferences(ContactPreferencesViewModel preferences, string[] selectedPreferences,
     string[] allPreferences)
 {
     if (ModelState.IsValid)
     {
         //check if synchronisation is possible
         //TODO: need to do this properly outside of the controller..
         //if (ContactSynchroniser.CanContactBeSynced(contact))
         //{
         if (preferences.ExternalContactNumber > 0 & preferences.ExternalAddressNumber > 0)
         {
             ContactPreferences preferencesToUpdate = getContactPreferencesToUpdate(preferences,
                 selectedPreferences, allPreferences);
             ContactPreferencesOperationStatus savePreferenceStatus =
                 _contactSynchroniser.SaveContactPreferences(preferencesToUpdate);
             if (savePreferenceStatus.Status)
             {
                 return RedirectToCurrentUmbracoPage();
             }
             //TODO:what to do if getting details fails - NOT this..
             return CurrentUmbracoPage();
             //}
         }
     }
     return CurrentUmbracoPage();
 }