Пример #1
0
        static void UpdateFamilyAttributes(Rock.Client.Group family, Rock.Client.GroupLocation address, List <KeyValuePair <string, string> > attributes, HttpRequest.RequestResult resultHandler)
        {
            // are there attributes?
            int pendingCompleteCount = 0;

            if (attributes != null && attributes.Count > 0)
            {
                // update each attribute
                foreach (KeyValuePair <string, string> attribValue in attributes)
                {
                    // just fire and forget these values.
                    FamilyManagerApi.UpdateOrAddFamilyAttribute(family.Id, attribValue.Key, attribValue.Value,
                                                                delegate
                    {
                        // once we complete updating them (whether successful or not) we're done.
                        pendingCompleteCount++;
                        if (pendingCompleteCount == attributes.Count)
                        {
                            resultHandler(HttpStatusCode.OK, "");
                        }
                    });
                }
            }
            // no, so we're done
            else
            {
                resultHandler(HttpStatusCode.OK, "");
            }
        }
Пример #2
0
 static void UpdateFamilyAddress(Rock.Client.Group family, Rock.Client.GroupLocation address, List <KeyValuePair <string, string> > attributes, HttpRequest.RequestResult resultHandler)
 {
     // is there an address?
     if (address != null)
     {
         ApplicationApi.UpdateFamilyAddress(family, address,
                                            delegate(System.Net.HttpStatusCode statusCode, string statusDescription)
         {
             // if it updated ok, go to family attributes
             if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode))
             {
                 UpdateFamilyAttributes(family, address, attributes, resultHandler);
             }
             // address failed
             else
             {
                 resultHandler(statusCode, statusDescription);
             }
         });
     }
     // no, go to family attrubutes
     else
     {
         UpdateFamilyAttributes(family, address, attributes, resultHandler);
     }
 }
Пример #3
0
 // UpdateFullFamily will update the family, address and attributes.
 // For simplicity, it's broken into 3 functions. This one,  and two private ones.
 public static void UpdateFullFamily(Rock.Client.Group family, Rock.Client.GroupLocation address, List <KeyValuePair <string, string> > attributes, HttpRequest.RequestResult resultHandler)
 {
     // start by updating the family group
     ApplicationApi.UpdateFamilyGroup(family, Config.Instance.CurrentPersonAliasId,
                                      delegate(System.Net.HttpStatusCode statusCode, string statusDescription)
     {
         if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode))
         {
             UpdateFamilyAddress(family, address, attributes, resultHandler);
         }
         else
         {
             resultHandler(statusCode, statusDescription);
         }
     });
 }
Пример #4
0
            public static void Put_Groups_SaveAddress(Rock.Client.Group group, Rock.Client.GroupLocation groupLocation, HttpRequest.RequestResult resultHandler)
            {
                RestRequest request = GetRockRestRequest(Method.PUT);

                string requestUrl = string.Format(BaseUrl + EndPoint_Groups_SaveAddress, group.Id,
                                                  groupLocation.GroupLocationTypeValueId);


                // append all valid params (since they're not all required)
                if (string.IsNullOrWhiteSpace(groupLocation.Location.Street1) == false)
                {
                    requestUrl = Rock.Mobile.Util.Strings.Parsers.AddParamToURL(requestUrl, string.Format("street1=" + System.Net.WebUtility.UrlEncode(groupLocation.Location.Street1)));
                }

                if (string.IsNullOrWhiteSpace(groupLocation.Location.Street2) == false)
                {
                    requestUrl = Rock.Mobile.Util.Strings.Parsers.AddParamToURL(requestUrl, string.Format("street2=" + System.Net.WebUtility.UrlEncode(groupLocation.Location.Street2)));
                }

                if (string.IsNullOrWhiteSpace(groupLocation.Location.City) == false)
                {
                    requestUrl = Rock.Mobile.Util.Strings.Parsers.AddParamToURL(requestUrl, string.Format("city=" + System.Net.WebUtility.UrlEncode(groupLocation.Location.City)));
                }

                if (string.IsNullOrWhiteSpace(groupLocation.Location.State) == false)
                {
                    requestUrl = Rock.Mobile.Util.Strings.Parsers.AddParamToURL(requestUrl, string.Format("state=" + System.Net.WebUtility.UrlEncode(groupLocation.Location.State)));
                }

                if (string.IsNullOrWhiteSpace(groupLocation.Location.PostalCode) == false)
                {
                    requestUrl = Rock.Mobile.Util.Strings.Parsers.AddParamToURL(requestUrl, string.Format("postalCode=" + System.Net.WebUtility.UrlEncode(groupLocation.Location.PostalCode)));
                }

                if (string.IsNullOrWhiteSpace(groupLocation.Location.Country) == false)
                {
                    requestUrl = Rock.Mobile.Util.Strings.Parsers.AddParamToURL(requestUrl, string.Format("country=" + System.Net.WebUtility.UrlEncode(groupLocation.Location.Country)));
                }

                // make sure the URL pieces are fully encoded, but still use spaces
                requestUrl = requestUrl.Replace("+", " ");

                Request.ExecuteAsync(requestUrl, request, resultHandler);
            }
        void AddPeopleToNewFamily( List<Rock.Client.GroupMember> familyMembers, bool removeFromOtherFamilies )
        {
            // first create a new family
            Rock.Client.Group familyGroup = new Rock.Client.Group();
            Rock.Client.GroupLocation familyAddress = new Rock.Client.GroupLocation();
            List<KeyValuePair<string, string>> pendingAttribChanges = new List<KeyValuePair<string, string>>( );

            UIToFamilyInfo( ref familyGroup, ref familyAddress, ref pendingAttribChanges );

            // if the family name field wasn't set, the family will still have no name, so we'll use the
            // person to add's last name.
            if ( UI.FamilySuffixManager.FamilyNameBlankOrSuffix( familyGroup.Name ) == true )
            {
                familyGroup.Name = FamilySuffixManager.FamilyNameWithSuffix( familyMembers[ 0 ].Person.LastName );
            }

            FamilyManagerApi.CreateNewFamily( familyGroup,
                delegate(System.Net.HttpStatusCode statusCode, string statusDescription )
                {
                    if ( Rock.Mobile.Network.Util.StatusInSuccessRange( statusCode ) )
                    {
                        // now get that group
                        ApplicationApi.GetFamilyGroupModelByGuid( familyGroup.Guid,
                            delegate(HttpStatusCode getFamilyCode, string getFamilyDesc, Rock.Client.Group model )
                            {
                                // now take the model returned and copy that into our familyGroup, because
                                // it should be everything that was plus new data like the ID.
                                familyGroup = model;

                                if ( Rock.Mobile.Network.Util.StatusInSuccessRange( getFamilyCode ) )
                                {
                                    FamilyManagerApi.UpdateFullFamily( familyGroup, familyAddress, pendingAttribChanges,
                                        delegate(System.Net.HttpStatusCode updateFamilyCode, string updateFamilyDesc )
                                        {
                                            if ( Rock.Mobile.Network.Util.StatusInSuccessRange( updateFamilyCode ) )
                                            {
                                                // take the model from the GetFamily as our family. Our address can be
                                                // the address we got from the UI.
                                                FamilyGroupObject = model;
                                                FamilyAddress = familyAddress;

                                                // setup a family object that can be refreshed.
                                                Family = new Rock.Client.Family();
                                                Family.Id = FamilyGroupObject.Id;

                                                // now use the standard addPeopleToFamily
                                                AddPeopleToFamily( familyMembers, Family.Id, removeFromOtherFamilies );
                                            }
                                            // Error retrieving the newly created family
                                            else
                                            {
                                                BlockerView.Hide( delegate
                                                    {
                                                        Rock.Mobile.Util.Debug.DisplayError( Strings.General_Error_Header, Strings.General_Error_Message );
                                                    } );
                                            }
                                        });
                                }
                                // Error retrieving the newly created family
                                else
                                {
                                    BlockerView.Hide( delegate
                                        {
                                            Rock.Mobile.Util.Debug.DisplayError( Strings.General_Error_Header, Strings.General_Error_Message );
                                        } );
                                }
                            } );
                    }
                    // Error creating the new family
                    else
                    {
                        BlockerView.Hide( delegate
                            {
                                Rock.Mobile.Util.Debug.DisplayError( Strings.General_Error_Header, Strings.General_Error_Message );
                            } );
                    }
                } );
        }
Пример #6
0
                public void GetFamilyAndAddress( HttpRequest.RequestResult< List<Rock.Client.Group> > addressResult )
                {
                    // for the address (which implicitly is their primary residence address), first get all group locations associated with them
                    RockApi.Instance.GetFamiliesOfPerson( Person,

                        delegate(System.Net.HttpStatusCode statusCode, string statusDescription, List<Rock.Client.Group> model)
                        {
                            if( Rock.Mobile.Network.Util.StatusInSuccessRange( statusCode ) == true )
                            {
                                // find what we'll consider their primary address.

                                // look thru each group (family)
                                foreach( Rock.Client.Group personGroup in model )
                                {
                                    // If we find a groupType of family, that should be their primary family.
                                    if( personGroup.GroupType.Guid.ToString( ).ToLower( ) == Rock.Client.SystemGuid.GroupType.GROUPTYPE_FAMILY.ToLower( ) )
                                    {
                                        // store the family
                                        PrimaryFamily = personGroup;

                                        // look at each location within the family
                                        foreach( Rock.Client.GroupLocation groupLocation in personGroup.GroupLocations )
                                        {
                                            // find their "Home Location" within the family group type.
                                            if( groupLocation.GroupLocationTypeValue.Guid.ToString( ).ToLower( ) == Rock.Client.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME.ToLower( ) )
                                            {
                                                PrimaryAddress = groupLocation;
                                                break;
                                            }
                                        }
                                    }
                                }

                                // on retrieval, convert this version for dirty compares later
                                LastSyncdAddressJson = JsonConvert.SerializeObject( PrimaryAddress );
                                LastSyncdFamilyJson = JsonConvert.SerializeObject( PrimaryFamily );

                                // save!
                                SaveToDevice( );
                            }

                            // notify the caller
                            if( addressResult != null )
                            {
                                addressResult( statusCode, statusDescription, model );
                            }
                        });
                }
Пример #7
0
                /// <summary>
                /// Resets all the values related to the Person, but won't reset things like
                /// IsFirstRun
                /// </summary>
                void SetDefaultPersonValues( )
                {
                    Person = new Person();

                    PrimaryFamily = new Group();

                    PrimaryAddress = new GroupLocation();
                    PrimaryAddress.GroupLocationTypeValueId = PrivateGeneralConfig.GroupLocationTypeHomeValueId;

                    _CellPhoneNumber = null;

                    ViewingCampus = RockGeneralData.Instance.Data.Campuses[ 0 ].Id;

                    // for the address location, default the country to the built in country code.
                    PrimaryAddress.Location = new Location();
                    PrimaryAddress.Location.Country = App.Shared.Config.GeneralConfig.CountryCode;

                    LastSyncdPersonJson = JsonConvert.SerializeObject( Person );
                    LastSyncdFamilyJson = JsonConvert.SerializeObject( PrimaryFamily );
                    LastSyncdAddressJson = JsonConvert.SerializeObject( PrimaryAddress );
                    LastSyncdCellPhoneNumberJson = "";
                }
Пример #8
0
 public static void UpdateFamilyAddress(Rock.Client.Group family, Rock.Client.GroupLocation address, HttpRequest.RequestResult resultHandler)
 {
     RockApi.Put_Groups_SaveAddress(family, address, resultHandler);
 }