Simple Client Model for PhoneNumber
        public static Rock.Client.PhoneNumber TryGetPhoneNumber(Rock.Client.Person person, int phoneTypeId)
        {
            Rock.Client.PhoneNumber requestedNumber = null;

            // if the user has phone numbers
            if (person.PhoneNumbers != null)
            {
                // get an enumerator
                IEnumerator <Rock.Client.PhoneNumber> enumerator = person.PhoneNumbers.GetEnumerator( );
                enumerator.MoveNext( );

                // search for the phone number type requested
                while (enumerator.Current != null)
                {
                    Rock.Client.PhoneNumber phoneNumber = enumerator.Current as Rock.Client.PhoneNumber;

                    // is this the right type?
                    if (phoneNumber.NumberTypeValueId == phoneTypeId)
                    {
                        requestedNumber = phoneNumber;
                        break;
                    }
                    enumerator.MoveNext( );
                }
            }

            return(requestedNumber);
        }
Example #2
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;
                    PrimaryAddress.IsMappedLocation         = true;

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

                    _CellPhoneNumber = new PhoneNumber( );
                    SetPhoneNumberDigits("");

                    IsBaptised         = false;
                    IsERA              = false;
                    IsGiving           = false;
                    TakenStartingPoint = false;
                    IsMember           = false;
                    IsServing          = false;
                    IsPeerLearning     = false;
                    IsMentored         = false;
                    IsTeaching         = false;

                    // Don't reset the viewing campus, because we force them to pick one at
                    // first run, and don't want to lose their choice.
                    //ViewingCampus = 0;
                }
Example #3
0
                public void GetPersonData(HttpRequest.RequestResult onResult)
                {
                    MobileAppApi.GetPersonData(UserID,
                                               delegate(MobileAppApi.PersonData personData, HttpStatusCode statusCode)
                    {
                        if (personData != null)
                        {
                            // take the person (clear out the cell numbers since we manage those seperately)
                            Person = personData.Person;
                            Person.PhoneNumbers = null;

                            // search for a phone number (which should match whatever we already have, unless this is a new login)
                            if (personData.CellPhoneNumber != null)
                            {
                                _CellPhoneNumber = personData.CellPhoneNumber;

                                HasCellNumber = true;
                            }
                            else
                            {
                                // no longer has a phone number, so clear it
                                _CellPhoneNumber = new PhoneNumber( );

                                SetPhoneNumberDigits("");

                                HasCellNumber = false;
                            }

                            // we're always safe to take family--it cannot be null
                            PrimaryFamily = personData.Family;

                            // only take the address if it's valid. otherwise, we want
                            // to use the default, empty one.
                            if (personData.FamilyAddress != null)
                            {
                                PrimaryAddress = personData.FamilyAddress;
                            }

                            // set the person's current actions
                            IsBaptised         = personData.IsBaptised;
                            IsERA              = personData.IsERA;
                            IsGiving           = personData.IsGiving;
                            TakenStartingPoint = personData.TakenStartingPoint;
                            IsMember           = personData.IsMember;
                            IsServing          = personData.IsServing;
                            IsPeerLearning     = personData.IsPeerLearning;
                            IsMentored         = personData.IsMentored;
                            IsTeaching         = personData.IsTeaching;

                            // save!
                            SaveToDevice( );
                        }

                        if (onResult != null)
                        {
                            onResult(statusCode, "");
                        }
                    });
                }
Example #4
0
 public static void UpdateOrAddPhoneNumber(Rock.Client.Person person, Rock.Client.PhoneNumber phoneNumber, bool isNew, HttpRequest.RequestResult <Rock.Client.PhoneNumber> resultHandler)
 {
     // is it blank?
     if (string.IsNullOrEmpty(phoneNumber.Number) == true)
     {
         // if it's not new, we should delete an existing
         if (isNew == false)
         {
             ApplicationApi.DeleteCellPhoneNumber(phoneNumber,
                                                  delegate(System.Net.HttpStatusCode statusCode, string statusDescription)
             {
                 if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true)
                 {
                     // return the blank number back to them
                     resultHandler(statusCode, statusDescription, phoneNumber);
                 }
             });
         }
         // otherwise, simply ignore it and say we're done.
         else
         {
             resultHandler(System.Net.HttpStatusCode.OK, "", phoneNumber);
         }
     }
     // not blank, so we're adding or updating
     else
     {
         // send it to the server
         ApplicationApi.AddOrUpdateCellPhoneNumber(person, phoneNumber, isNew, 0,
                                                   delegate(System.Net.HttpStatusCode statusCode, string statusDescription)
         {
             if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true)
             {
                 // if it was new, get it so we have its ID
                 if (isNew == true)
                 {
                     ApplicationApi.GetPhoneNumberByGuid(phoneNumber.Guid, resultHandler);
                 }
                 else
                 {
                     // it's updated, so now just return what we updated.
                     resultHandler(statusCode, statusDescription, phoneNumber);
                 }
             }
             // something went wrong, so return.
             else
             {
                 resultHandler(statusCode, statusDescription, null);
             }
         });
     }
 }
Example #5
0
                public void UpdateOrAddPhoneNumber(HttpRequest.RequestResult phoneResult)
                {
                    // if they currently have a cell number, OR their number is non-empty
                    if (HasCellNumber == true || string.IsNullOrEmpty(_CellPhoneNumber.Number) == false)
                    {
                        // if they DON'T have a cell number, then yes, this will be a new number.
                        bool addNewPhoneNumber = !HasCellNumber;

                        MobileAppApi.UpdateOrAddPhoneNumber(Person, _CellPhoneNumber, addNewPhoneNumber,
                                                            delegate(System.Net.HttpStatusCode statusCode, string statusDescription, PhoneNumber model)
                        {
                            if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true)
                            {
                                // if we got back a model with an actual number, it's updated.
                                if (model != null && string.IsNullOrEmpty(model.Number) == false)
                                {
                                    _CellPhoneNumber = model;

                                    HasCellNumber = true;
                                }
                                else
                                {
                                    // otherwise the user is deleting it
                                    _CellPhoneNumber = new PhoneNumber( );
                                    SetPhoneNumberDigits("");

                                    HasCellNumber = false;
                                }

                                SaveToDevice( );
                            }

                            if (phoneResult != null)
                            {
                                phoneResult(statusCode, statusDescription);
                            }
                        });
                    }
                    else
                    {
                        if (phoneResult != null)
                        {
                            phoneResult(System.Net.HttpStatusCode.OK, "");
                        }
                    }
                }
Example #6
0
 /// <summary>
 /// Copies the base properties from a source PhoneNumber object
 /// </summary>
 /// <param name="source">The source.</param>
 public void CopyPropertiesFrom( PhoneNumber source )
 {
     this.Id = source.Id;
     this.CountryCode = source.CountryCode;
     this.Description = source.Description;
     this.Extension = source.Extension;
     this.ForeignGuid = source.ForeignGuid;
     this.ForeignKey = source.ForeignKey;
     this.IsMessagingEnabled = source.IsMessagingEnabled;
     this.IsSystem = source.IsSystem;
     this.IsUnlisted = source.IsUnlisted;
     this.ModifiedAuditValuesAlreadyUpdated = source.ModifiedAuditValuesAlreadyUpdated;
     this.Number = source.Number;
     this.NumberFormatted = source.NumberFormatted;
     this.NumberTypeValueId = source.NumberTypeValueId;
     this.PersonId = source.PersonId;
     this.CreatedDateTime = source.CreatedDateTime;
     this.ModifiedDateTime = source.ModifiedDateTime;
     this.CreatedByPersonAliasId = source.CreatedByPersonAliasId;
     this.ModifiedByPersonAliasId = source.ModifiedByPersonAliasId;
     this.Guid = source.Guid;
     this.ForeignId = source.ForeignId;
 }
Example #7
0
 /// <summary>
 /// Copies the base properties from a source PhoneNumber object
 /// </summary>
 /// <param name="source">The source.</param>
 public void CopyPropertiesFrom( PhoneNumber source )
 {
     this.Id = source.Id;
     this.CountryCode = source.CountryCode;
     this.Description = source.Description;
     this.Extension = source.Extension;
     this.IsMessagingEnabled = source.IsMessagingEnabled;
     this.IsSystem = source.IsSystem;
     this.IsUnlisted = source.IsUnlisted;
     this.Number = source.Number;
     this.NumberFormatted = source.NumberFormatted;
     this.NumberTypeValueId = source.NumberTypeValueId;
     this.PersonId = source.PersonId;
     this.Guid = source.Guid;
     this.ForeignId = source.ForeignId;
 }
 public static void SetPhoneNumberDigits(Rock.Client.PhoneNumber phoneNumber, string digits)
 {
     phoneNumber.Number          = digits;
     phoneNumber.NumberFormatted = digits.AsPhoneNumber( );
 }
                public void UpdateOrAddPhoneNumber( HttpRequest.RequestResult phoneResult )
                {   
                    //bool addNewPhoneNumber = string.IsNullOrEmpty( LastSyncdCellPhoneNumberJson ) ? true : false;

                    // we know if it's a new phone number based on whether our sync'd cell number is blank or not.
                    bool addNewPhoneNumber = false;
                    PhoneNumber lastSyncdNumber = JsonConvert.DeserializeObject<PhoneNumber>( LastSyncdCellPhoneNumberJson ) as PhoneNumber;
                    if ( lastSyncdNumber != null && string.IsNullOrEmpty( lastSyncdNumber.Number ) == true )
                    {
                        addNewPhoneNumber = true;
                    }

                    MobileAppApi.UpdateOrAddPhoneNumber( Person, _CellPhoneNumber, addNewPhoneNumber, 
                        delegate(System.Net.HttpStatusCode statusCode, string statusDescription, PhoneNumber model )
                        {
                            if ( Rock.Mobile.Network.Util.StatusInSuccessRange( statusCode ) == true && model != null )
                            {
                                _CellPhoneNumber = model;
                                //LastSyncdCellPhoneNumberJson = _CellPhoneNumber != null ? JsonConvert.SerializeObject( _CellPhoneNumber ) : "";
                                LastSyncdCellPhoneNumberJson = JsonConvert.SerializeObject( _CellPhoneNumber );
                            }

                            // save either way!
                            SaveToDevice( );

                            if ( phoneResult != null )
                            {
                                phoneResult( statusCode, statusDescription );
                            }   
                        } );
                }
Example #10
0
                public void GetProfileAndCellPhone( HttpRequest.RequestResult profileResult )
                {
                    MobileAppApi.GetProfileAndCellPhone( UserID, 
                        delegate(System.Net.HttpStatusCode statusCode, string statusDescription, Person person, PhoneNumber cellPhoneNumber )
                        {
                            if( Rock.Mobile.Network.Util.StatusInSuccessRange( statusCode ) == true )
                            {
                                // take the person
                                Person = person;

                                // search for a phone number (which should match whatever we already have, unless this is a new login)
                                if( cellPhoneNumber != null )
                                {
                                    _CellPhoneNumber = cellPhoneNumber;
                                    LastSyncdCellPhoneNumberJson = JsonConvert.SerializeObject( _CellPhoneNumber );
                                }

                                // now before storing the person, clear their phone list, as we need to store and manage
                                // the number seperately.
                                Person.PhoneNumbers = null;
                                LastSyncdPersonJson = JsonConvert.SerializeObject( Person );

                                // save!
                                SaveToDevice( );
                            }
                            
                            // notify the caller
                            if( profileResult != null )
                            {
                                profileResult( statusCode, statusDescription );
                            }
                        } );
                }
Example #11
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;
                    _CellPhoneNumber = new PhoneNumber( );
                    SetPhoneNumberDigits( "" );

                    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 = JsonConvert.SerializeObject( _CellPhoneNumber );
                }