예제 #1
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);
     }
 }
예제 #2
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, "");
            }
        }
예제 #3
0
        public static void CreateNewFamily(Rock.Client.Group groupModel, HttpRequest.RequestResult resultHandler)
        {
            // give the group model required values
            groupModel.Guid        = Guid.NewGuid( );
            groupModel.GroupTypeId = FamilyGroupTypeId;
            groupModel.IsActive    = true;
            groupModel.IsPublic    = true;

            RockApi.Post_Groups(groupModel, Config.Instance.CurrentPersonAliasId, resultHandler);
        }
예제 #4
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);
         }
     });
 }
예제 #5
0
        public static void GetFamilyGroupModelByGuid(Guid guid, HttpRequest.RequestResult <Rock.Client.Group> resultHandler)
        {
            string oDataFilter = string.Format("?$filter=Guid eq guid'{0}'", guid.ToString( ));

            RockApi.Get_Groups <List <Rock.Client.Group> >(oDataFilter,
                                                           delegate(HttpStatusCode statusCode, string statusDescription, List <Rock.Client.Group> groupList)
            {
                Rock.Client.Group returnGroup = null;

                if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true)
                {
                    returnGroup = groupList[0];
                }

                resultHandler(statusCode, statusDescription, returnGroup);
            });
        }
예제 #6
0
            public static void Post_Groups(Rock.Client.Group group, int modifiedById, HttpRequest.RequestResult resultHandler)
            {
                Rock.Client.GroupEntity groupEntity = new Rock.Client.GroupEntity();
                groupEntity.CopyPropertiesFrom(group);

                if (modifiedById > 0)
                {
                    groupEntity.ModifiedAuditValuesAlreadyUpdated = true;
                    groupEntity.CreatedByPersonAliasId            = modifiedById;
                    groupEntity.ModifiedByPersonAliasId           = modifiedById;
                }

                RestRequest request = GetRockRestRequest(Method.POST);

                request.AddBody(groupEntity);

                Request.ExecuteAsync(BaseUrl + EndPoint_Groups, request, resultHandler);
            }
예제 #7
0
        /// <summary>
        /// Helper function to prevent GetPersonForEdit from getting crazy long. Given a list of Rock.Client.GroupMember,
        /// this gets the all families (as Rock.Client.Group) for each GroupMember.
        /// </summary>
        static void GroupMembersToFamilyGroups(Rock.Client.Person refreshedPerson, List <Rock.Client.GroupMember> groupMembers, PersonEditResponseDelegate response)
        {
            // first, we need to get the families for each group member
            int groupMembersResolved = 0;
            List <Rock.Client.Group> groupFamilies = new List <Rock.Client.Group>( );

            foreach (Rock.Client.GroupMember member in groupMembers)
            {
                RockApi.Get_FamiliesOfPerson(member.PersonId, string.Empty,
                                             delegate(HttpStatusCode statusCode, string statusDescription, List <Rock.Client.Group> groups)
                {
                    if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode))
                    {
                        // serialize the responses on the UI thread so we can be sure it's all thread safe
                        Rock.Mobile.Threading.Util.PerformOnUIThread(
                            delegate
                        {
                            // first, add the returned groups to our global list.
                            foreach (Rock.Client.Group group in groups)
                            {
                                // make sure we don't already have this group in our list
                                Rock.Client.Group resultGroup = groupFamilies.Where(g => g.Id == group.Id).FirstOrDefault( );
                                if (resultGroup == null)
                                {
                                    groupFamilies.Add(group);
                                }
                            }

                            // now see if we're done waiting for all responses.
                            groupMembersResolved++;
                            if (groupMembersResolved == groupMembers.Count)
                            {
                                GroupsToFamilies(groupFamilies, refreshedPerson, response);
                            }
                        });
                    }
                    // if any of them fail, then fail.
                    else
                    {
                        response(null, null);
                    }
                });
            }
        }
예제 #8
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);
            }
        public FamilyInfoViewController( ContainerViewController parent, Rock.Client.Family family )
        {
            SaveResult = new SaveResultView();

            Parent = parent;

            FamilyGroupObject = null;

            // support creating a NEW family by letting them pass null as the
            // family argument
            if ( family != null )
            {
                Family = family;
            }
            else
            {
                GuestFamilies = new List<Rock.Client.GuestFamily>();
                Family = new Rock.Client.Family();
            }

            Dynamic_FamilyControls = new List<IDynamic_UIView>( );
        }
        void OnNewPersonComplete( bool didSave, int workingFamilyId, bool isChild, object context )
        {
            KeyboardAdjustManager.Activate( );

            // did they make a change?
            if ( didSave == true )
            {
                BlockerView.Show( delegate
                    {
                        // Get the person that was just created.
                        ApplicationApi.GetPersonByGuid( ( (Rock.Client.Person)context ).Guid,
                            delegate(HttpStatusCode statusCode, string statusDescription, Rock.Client.Person newPerson )
                            {
                                if ( Rock.Mobile.Network.Util.StatusInSuccessRange( statusCode ) )
                                {
                                    // if our family ID is 0, we're supposed to be creating a new family
                                    if ( workingFamilyId == 0 )
                                    {
                                        // we know they were given a family when they were created. So get that family,
                                        // and we'll make that the family here that we're editing.
                                        ApplicationApi.GetFamiliesOfPerson( newPerson,
                                            delegate(System.Net.HttpStatusCode familyCode, string familyDescription, List<Rock.Client.Group> familyList )
                                            {
                                                // we expect there to be exactly ONE family, and it will be the one that was just created.
                                                if ( Rock.Mobile.Network.Util.StatusInSuccessRange( statusCode ) && familyList != null && familyList.Count == 1 )
                                                {
                                                    // take this as our family group object
                                                    FamilyGroupObject = familyList[ 0 ];

                                                    // now that they're in a family, we need to set their role appropriately (child or adult)
                                                    int adultChildMemberRoleId = isChild == true ? Config.Instance.FamilyMemberChildGroupRole.Id : Config.Instance.FamilyMemberAdultGroupRole.Id;
                                                    FamilyManagerApi.UpdatePersonRoleInFamily( FamilyGroupObject.Members.ToList( )[ 0 ], adultChildMemberRoleId, delegate(System.Net.HttpStatusCode updateRoleCode, string updateRoleDescription )
                                                        {
                                                            // if updating their role worked, continue!
                                                            if( Rock.Mobile.Network.Util.StatusInSuccessRange( updateRoleCode ) )
                                                            {
                                                                // copy over all the filled in info so we can update this newly created family.
                                                                UIToFamilyInfo( ref FamilyGroupObject, ref FamilyAddress, ref PendingAttribChanges );

                                                                // and immediately submit it. This will ensure we sync all the info they've typed
                                                                // up to Rock!
                                                                FamilyManagerApi.UpdateFullFamily( FamilyGroupObject, FamilyAddress, PendingAttribChanges, delegate(System.Net.HttpStatusCode updateFamilyCode, string updateFamilyDescription )
                                                                    {
                                                                        if ( Rock.Mobile.Network.Util.StatusInSuccessRange( updateFamilyCode ) )
                                                                        {
                                                                            // setup a family object that can be refreshed.
                                                                            Family = new Rock.Client.Family();
                                                                            Family.Id = FamilyGroupObject.Id;

                                                                            // go ahead and refresh the family
                                                                            RefreshFamily( );
                                                                        }
                                                                        else
                                                                        {
                                                                            // couldnt move them to the current family.
                                                                            BlockerView.Hide( delegate
                                                                                {
                                                                                    Rock.Mobile.Util.Debug.DisplayError( Strings.General_Error_Header, Strings.General_Error_Message );
                                                                                } );
                                                                        }
                                                                    } );
                                                            }
                                                            else
                                                            {
                                                                // couldnt move them to the current family.
                                                                BlockerView.Hide( delegate
                                                                    {
                                                                        Rock.Mobile.Util.Debug.DisplayError( Strings.General_Error_Header, Strings.General_Error_Message );
                                                                    } );
                                                            }
                                                        });
                                                }
                                                else
                                                {
                                                    // couldnt move them to the current family.
                                                    BlockerView.Hide( delegate
                                                        {
                                                            Rock.Mobile.Util.Debug.DisplayError( Strings.General_Error_Header, Strings.General_Error_Message );
                                                        } );
                                                }
                                            } );
                                    }
                                    else
                                    {
                                        // new person to existing family is easy. Simply add them to the working family,
                                        // and request that they are removed from any families they're already in (which will be the
                                        // one new one created by Rock)
                                        int adultChildMemberRoleId = isChild == true ? Config.Instance.FamilyMemberChildGroupRole.Id : Config.Instance.FamilyMemberAdultGroupRole.Id;
                                        FamilyManagerApi.AddPersonToFamily( newPerson, adultChildMemberRoleId, workingFamilyId, true, delegate(System.Net.HttpStatusCode addToFamilyCode, string addToFamilyDescription )
                                            {
                                                if ( Rock.Mobile.Network.Util.StatusInSuccessRange( statusCode ) )
                                                {
                                                    // update their status in this family (child / adult)

                                                    // go ahead and refresh the family
                                                    RefreshFamily( );
                                                }
                                                else
                                                {
                                                    // couldnt move them to the current family.
                                                    BlockerView.Hide( delegate { Rock.Mobile.Util.Debug.DisplayError( Strings.General_Error_Header, Strings.General_Error_Message );  } );
                                                }
                                            } );
                                    }
                                }
                            } );
                    } );
            }
        }
        void HandleFamilyGone( )
        {
            // this is called if we search for a family and they aren't there. If that happens,
            // notify the user, and setup values as if this is a new family
            BlockerView.Hide( delegate
                {
                    Rock.Mobile.Util.Debug.DisplayError( Strings.FamilyInfo_Header_Gone, Strings.FamilyInfo_Body_Gone );

                    FamilyGroupObject = null;

                    GuestFamilies = new List<Rock.Client.GuestFamily>();
                    Family = new Rock.Client.Family();

                    TableView.Source = new TableSource( this );
                    FamilyName.SetCurrentValue( string.Empty );
                    TableView.ReloadData( );
                } );
        }
        void GetFamilyGroup( )
        {
            // get the group object that represents this family
            ApplicationApi.GetFamilyGroupModelById( Family.Id,
                delegate(System.Net.HttpStatusCode statusCode, string statusDescription, Rock.Client.Group model)
                {
                    if( Rock.Mobile.Network.Util.StatusInSuccessRange( statusCode ) )
                    {
                        FamilyGroupObject = model;

                        GetGuestsForFamily( );
                    }
                    else
                    {
                        RefreshFamilyDone( false );
                    }
                });
        }
        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 );
                            } );
                    }
                } );
        }
예제 #14
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 );
                            }
                        });
                }
예제 #15
0
 public static void UpdateFamilyAddress(Rock.Client.Group family, Rock.Client.GroupLocation address, HttpRequest.RequestResult resultHandler)
 {
     RockApi.Put_Groups_SaveAddress(family, address, resultHandler);
 }
예제 #16
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 = "";
                }
예제 #17
0
 public static void UpdateFamilyGroup(Rock.Client.Group familyGroup, int modifiedById, HttpRequest.RequestResult resultHandler)
 {
     RockApi.Put_Groups(familyGroup, modifiedById, resultHandler);
 }