public static void DownloadConfigurationTemplates(TemplatesDownloaded onDownloaded)
 {
     // first resolve the Guid to the correct type ID
     ApplicationApi.GetDefinedTypeIdForGuid(FamilyManagerApi.ConfigurationTemplateDefinedTypeGuid,
                                            delegate(System.Net.HttpStatusCode statusCode, string statusDescription, List <Rock.Client.DefinedType> definedTypeModel)
     {
         // if the request for the defined type worked
         if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true && definedTypeModel != null && definedTypeModel.Count > 0)
         {
             // now get the actual values
             FamilyManagerApi.GetConfigurationTemplates(definedTypeModel[0].Id, 0,
                                                        delegate(System.Net.HttpStatusCode configStatusCode, string configStatusDescription, List <Rock.Client.DefinedValue> definedValueModels)
             {
                 if (Rock.Mobile.Network.Util.StatusInSuccessRange(configStatusCode) == true && definedValueModels != null)
                 {
                     onDownloaded(definedValueModels);
                 }
                 else
                 {
                     // fail
                     onDownloaded(null);
                 }
             });
         }
         else
         {
             // fail
             onDownloaded(null);
         }
     });
 }
        public static void UpdateTemplate(Rock.Client.DefinedValue templateDefinedValue, OnTemplateUpdated onUpdated)
        {
            // get the Type and Specific Ids so we can request this specific template.
            int typeId   = TemplateTypeId(templateDefinedValue);
            int uniqueId = TemplateUniqueId(templateDefinedValue);

            FamilyManagerApi.GetConfigurationTemplates(typeId, uniqueId,
                                                       delegate(System.Net.HttpStatusCode statusCode, string statusDescription, List <Rock.Client.DefinedValue> definedValueModels)
            {
                if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true && definedValueModels != null && definedValueModels.Count > 0)
                {
                    // extract the ConfigurationTemplate itself from both, and compare them.
                    ConfigurationTemplate currentTemplate = Template(templateDefinedValue);
                    currentTemplate.SortAttributeLists( );

                    ConfigurationTemplate downloadedTemplate = Template(definedValueModels[0]);
                    downloadedTemplate.SortAttributeLists( );

                    // is it different?
                    string currentVersion    = JsonConvert.SerializeObject(currentTemplate);
                    string downloadedVersion = JsonConvert.SerializeObject(downloadedTemplate);

                    if (string.Compare(currentVersion, downloadedVersion) != 0)
                    {
                        // they're different, so provide the latest one
                        onUpdated(true, definedValueModels[0]);
                    }
                    else
                    {
                        onUpdated(true, null);
                    }
                }
                else
                {
                    onUpdated(false, null);
                }
            });
        }