예제 #1
0
        public static void UpdateFullPerson(bool isNewPerson,
                                            Rock.Client.Person person,
                                            bool isNewPhoneNumber,
                                            Rock.Client.PhoneNumber phoneNumber,
                                            List <KeyValuePair <string, string> > attributes,
                                            MemoryStream personImage,
                                            HttpRequest.RequestResult resultHandler)
        {
            // first, we need to resolve their graduation year (if they have a valid grade offset set)
            if (person.GradeOffset.HasValue && person.GradeOffset.Value >= 0)
            {
                RockApi.Get_People_GraduationYear(person.GradeOffset.Value,
                                                  delegate(HttpStatusCode statusCode, string statusDescription, int graduationYear)
                {
                    // now set that and update the person
                    if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true)
                    {
                        person.GraduationYear = graduationYear;

                        TryUpdatePerson(isNewPerson, person, isNewPhoneNumber, phoneNumber, attributes, personImage, resultHandler);
                    }
                    else
                    {
                        // error
                        resultHandler(statusCode, statusDescription);
                    }
                });
            }
            else
            {
                TryUpdatePerson(isNewPerson, person, isNewPhoneNumber, phoneNumber, attributes, personImage, resultHandler);
            }
        }
예제 #2
0
        public static void AddPersonToFamily(Rock.Client.Person person, int childAdultRoleMemberId, int toFamilyId, bool removeFromOtherFamilies, HttpRequest.RequestResult result)
        {
            // setup the oData. childAdultRoleMemberId describes whether this person should be an adult or child in the family.
            string oDataFilter = string.Format("?personId={0}&familyId={1}&groupRoleId={2}&removeFromOtherFamilies={3}", person.Id, toFamilyId, childAdultRoleMemberId, removeFromOtherFamilies);

            RockApi.Post_People_AddExistingPersonToFamily(oDataFilter, result);
        }
예제 #3
0
        /// <summary>
        /// Second helper method for GetPersonForEdit. This basically takes a list of Rock.Client.Group and gets the Rock.Client.Family for each one.
        /// </summary>
        static void GroupsToFamilies(List <Rock.Client.Group> groupFamilies, Rock.Client.Person refreshedPerson, PersonEditResponseDelegate response)
        {
            List <Rock.Client.Family> families = new List <Rock.Client.Family>( );
            int groupsResolved = 0;

            // now get all the FAMILY objects for these family GROUPS
            foreach (Rock.Client.Group group in groupFamilies)
            {
                RockApi.Get_Groups_GetFamily(group.Id,
                                             delegate(HttpStatusCode statusCode, string statusDescription, Rock.Client.Family model)
                {
                    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
                        {
                            families.Add(model);

                            groupsResolved++;
                            if (groupsResolved == groupFamilies.Count)
                            {
                                response(refreshedPerson, families);
                            }
                        });
                    }
                    else
                    {
                        response(null, null);
                    }
                });
            }
        }
 public void ProfileComplete(System.Net.HttpStatusCode code, string desc, Rock.Client.Person model)
 {
     Rock.Mobile.Threading.Util.PerformOnUIThread(delegate
     {
         UIThread_ProfileComplete(code, desc, model);
     });
 }
예제 #5
0
        void RegisterUser()
        {
            if (State == RegisterState.None)
            {
                // make sure they entered all required fields
                if (ValidateInput( ))
                {
                    ToggleControls(false);

                    ProgressBarBlocker.Visibility = ViewStates.Visible;
                    State = RegisterState.Trying;

                    // create a new user and submit them
                    Rock.Client.Person newPerson = new Rock.Client.Person();

                    // copy all the edited fields into the person object
                    newPerson.Email = EmailText.Text;

                    // set the nickName AND firstName to NickName
                    newPerson.NickName  = NickNameText.Text;
                    newPerson.FirstName = NickNameText.Text;

                    newPerson.LastName = LastNameText.Text;

                    MobileAppApi.RegisterNewUser(UserNameText.Text, PasswordText.Text, NickNameText.Text, LastNameText.Text, EmailText.Text, CellPhoneText.Text,
                                                 delegate(System.Net.HttpStatusCode statusCode, string statusDescription)
                    {
                        ProgressBarBlocker.Visibility = ViewStates.Gone;

                        // scroll to the top so the Result is visible
                        ScrollView.Post(new Action(delegate
                        {
                            ScrollView.ScrollTo(0, 0);
                        }));

                        if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true)
                        {
                            ProfileAnalytic.Instance.Trigger(ProfileAnalytic.Register);

                            State = RegisterState.Success;
                            ResultView.Show(RegisterStrings.RegisterStatus_Success,
                                            PrivateControlStylingConfig.Result_Symbol_Success,
                                            RegisterStrings.RegisterResult_Success,
                                            GeneralStrings.Done);
                        }
                        else
                        {
                            State = RegisterState.Fail;
                            ResultView.Show(RegisterStrings.RegisterStatus_Failed,
                                            PrivateControlStylingConfig.Result_Symbol_Failed,
                                            statusDescription,
                                            GeneralStrings.Done);
                        }

                        ResultView.SetBounds(new System.Drawing.RectangleF(0, 0, NavbarFragment.GetFullDisplayWidth( ), this.Resources.DisplayMetrics.HeightPixels));
                    });
                }
            }
        }
예제 #6
0
        static void TryUpdatePerson(bool isNewPerson,
                                    Rock.Client.Person person,
                                    bool isNewPhoneNumber,
                                    Rock.Client.PhoneNumber phoneNumber,
                                    List <KeyValuePair <string, string> > attributes,
                                    MemoryStream personImage,
                                    HttpRequest.RequestResult resultHandler)
        {
            // if they're a new person, flag them as a pending visitor.
            if (isNewPerson == true)
            {
                person.RecordStatusValueId     = Settings.Rock_RecordStatusValueId_Pending;
                person.ConnectionStatusValueId = Settings.Rock_ConnectionStatusValueId_Visitor;
            }

            ApplicationApi.UpdateOrAddPerson(person, isNewPerson, Config.Instance.CurrentPersonAliasId,
                                             delegate(System.Net.HttpStatusCode statusCode, string statusDescription)
            {
                if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true)
                {
                    // was this a new person?
                    if (isNewPerson == true)
                    {
                        // then we need to get their profile so we know the ID to use for updating the rest of their stuff.
                        TryGetNewlyCreatedProfile(person, isNewPhoneNumber, phoneNumber, attributes, personImage, resultHandler);
                    }
                    else
                    {
                        // now update pending attributes.
                        foreach (KeyValuePair <string, string> attribValue in attributes)
                        {
                            // just fire and forget these values.
                            FamilyManagerApi.UpdateOrAddPersonAttribute(person.Id, attribValue.Key, attribValue.Value, null);
                        }

                        // are we deleting an existing number?
                        if (string.IsNullOrWhiteSpace(phoneNumber.Number) == true && isNewPhoneNumber == false)
                        {
                            TryDeleteCellPhone(person, phoneNumber, personImage, resultHandler);
                        }
                        // are we updating or adding an existing?
                        else if (string.IsNullOrWhiteSpace(phoneNumber.Number) == false)
                        {
                            TryUpdateCellPhone(person, isNewPhoneNumber, phoneNumber, personImage, resultHandler);
                        }
                        else
                        {
                            TryUpdateProfilePic(person, personImage, resultHandler);
                        }
                    }
                }
                else
                {
                    // error
                    resultHandler(statusCode, statusDescription);
                }
            });
        }
예제 #7
0
        void RegisterUser()
        {
            if (State == RegisterState.None)
            {
                // make sure they entered all required fields
                if (ValidateInput( ))
                {
                    BlockerView.Show(
                        delegate
                    {
                        // force the UI to scroll back up
                        ScrollView.ContentOffset = CGPoint.Empty;
                        ScrollView.ScrollEnabled = false;

                        State = RegisterState.Trying;

                        // create a new user and submit them
                        Rock.Client.Person newPerson = new Rock.Client.Person();

                        // copy all the edited fields into the person object
                        newPerson.Email = EmailText.Field.Text;

                        // set both the nick name and first name to NickName
                        newPerson.NickName  = NickNameText.Field.Text;
                        newPerson.FirstName = NickNameText.Field.Text;

                        newPerson.LastName = LastNameText.Field.Text;

                        MobileAppApi.RegisterNewUser(UserNameText.Field.Text, PasswordText.Field.Text, NickNameText.Field.Text, LastNameText.Field.Text, EmailText.Field.Text, CellPhoneText.Field.Text,
                                                     delegate(System.Net.HttpStatusCode statusCode, string statusDescription)
                        {
                            if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true)
                            {
                                ProfileAnalytic.Instance.Trigger(ProfileAnalytic.Register);

                                State = RegisterState.Success;
                                ResultView.Show(RegisterStrings.RegisterStatus_Success,
                                                PrivateControlStylingConfig.Result_Symbol_Success,
                                                RegisterStrings.RegisterResult_Success,
                                                GeneralStrings.Done);
                            }
                            else
                            {
                                State = RegisterState.Fail;
                                ResultView.Show(RegisterStrings.RegisterStatus_Failed,
                                                PrivateControlStylingConfig.Result_Symbol_Failed,
                                                statusDescription,
                                                GeneralStrings.Done);
                            }

                            BlockerView.Hide(null);
                        });
                    });
                }
            }
        }
예제 #8
0
        public static void GetGroupsForPerson(Rock.Client.Person person, GroupsForPersonDelegate onResult)
        {
            string groupQuery = string.Format("?$filter=Members/any(o: o/PersonId eq {0})", person.Id);

            RockApi.Get_Groups <List <Rock.Client.Group> >(groupQuery,
                                                           delegate(HttpStatusCode groupCode, string groupDesc, List <Rock.Client.Group> groupList)
            {
                onResult(groupList);
            });
        }
예제 #9
0
 public static void UpdateOrAddPerson(Rock.Client.Person person, bool isNew, int modifiedById, HttpRequest.RequestResult resultHandler)
 {
     if (isNew == true)
     {
         person.Guid = Guid.NewGuid( );
         RockApi.Post_People(person, modifiedById, resultHandler);
     }
     else
     {
         RockApi.Put_People(person, modifiedById, resultHandler);
     }
 }
예제 #10
0
        public static void GetGroupMembersForPerson(Rock.Client.Person person, GroupMembersForPersonDelegate onResult)
        {
            // get all the groupMembers that are this person.
            string query = string.Format("?$filter=PersonId eq {0}", person.Id);

            RockApi.Get_GroupMembers(query,
                                     delegate(HttpStatusCode statusCode, string statusDescription, List <Rock.Client.GroupMember> groupMemberList)
            {
                if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true)
                {
                    onResult(groupMemberList);
                }
            });
        }
예제 #11
0
        static void UpdatePersonImageGroup(Rock.Client.Person person, int modifiedById, HttpRequest.RequestResult resultHandler)
        {
            string oDataFilter = string.Format("?$filter=PersonId eq {0} and GroupId eq {1}", person.Id, ApplicationGroup_PhotoRequest_ValueId);

            RockApi.Get_GroupMembers(oDataFilter, delegate(HttpStatusCode statusCode, string statusDescription, List <Rock.Client.GroupMember> model)
            {
                if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true)
                {
                    // if it's null, they are NOT in the group and we should POST. if it's valid,
                    // we can simply update the existing.
                    if (model.Count == 0)
                    {
                        Rock.Client.GroupMember groupMember = new Rock.Client.GroupMember();
                        groupMember.Guid              = Guid.NewGuid( );
                        groupMember.PersonId          = person.Id;
                        groupMember.GroupMemberStatus = GroupMemberStatus_Pending_ValueId;
                        groupMember.GroupId           = ApplicationGroup_PhotoRequest_ValueId;
                        groupMember.GroupRoleId       = GroupMemberRole_Member_ValueId;

                        RockApi.Post_GroupMembers(groupMember, modifiedById, resultHandler);
                    }
                    else
                    {
                        // otherwise, we'll do a PUT
                        Rock.Client.GroupMember groupMember = new Rock.Client.GroupMember();

                        // set the status to pending
                        groupMember.GroupMemberStatus = GroupMemberStatus_Pending_ValueId;

                        // and copy over all the other data
                        groupMember.PersonId    = model[0].PersonId;
                        groupMember.Guid        = model[0].Guid;
                        groupMember.GroupId     = model[0].GroupId;
                        groupMember.GroupRoleId = model[0].GroupRoleId;
                        groupMember.Id          = model[0].Id;
                        groupMember.IsSystem    = model[0].IsSystem;

                        RockApi.Put_GroupMembers(groupMember, modifiedById, resultHandler);
                    }
                }
                else
                {
                    // fail...
                    resultHandler(statusCode, statusDescription);
                }
            });
        }
예제 #12
0
        public static void GetPersonByGuid(Guid guid, HttpRequest.RequestResult <Rock.Client.Person> resultHandler)
        {
            string oDataFilter = string.Format("?$filter=Guid eq guid'{0}'", guid.ToString( ));

            RockApi.Get_People <List <Rock.Client.Person> >(oDataFilter,
                                                            delegate(HttpStatusCode statusCode, string statusDescription, List <Rock.Client.Person> personList)
            {
                Rock.Client.Person returnPerson = null;

                if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true && personList != null && personList.Count > 0)
                {
                    returnPerson = personList[0];
                }

                resultHandler(statusCode, statusDescription, returnPerson);
            });
        }
예제 #13
0
 static void TryUpdateProfilePic(Rock.Client.Person person, MemoryStream personImage, HttpRequest.RequestResult resultHandler)
 {
     // is there a picture needing to be uploaded?
     if (personImage != null)
     {
         // upload
         ApplicationApi.UploadSavedProfilePicture(person, personImage, Config.Instance.CurrentPersonAliasId,
                                                  delegate(System.Net.HttpStatusCode statusCode, string statusDescription)
         {
             resultHandler(statusCode, statusDescription);
         });
     }
     else
     {
         resultHandler(HttpStatusCode.OK, "");
     }
 }
예제 #14
0
            public static void Post_People(Rock.Client.Person person, int modifiedById, HttpRequest.RequestResult resultHandler)
            {
                // create a person object that can go up to rock, and copy the relavant data from the passed in arg
                Rock.Client.PersonEntity personEntity = PackagePersonForUpload(person);

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

                RestRequest request = GetRockRestRequest(Method.POST);

                request.AddBody(personEntity);

                Request.ExecuteAsync(BaseUrl + EndPoint_People, request, resultHandler);
            }
예제 #15
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);
                    }
                });
            }
        }
예제 #16
0
        static void TryGetNewlyCreatedProfile(Rock.Client.Person person,
                                              bool isNewPhoneNumber,
                                              Rock.Client.PhoneNumber phoneNumber,
                                              List <KeyValuePair <string, string> > attributes,
                                              MemoryStream personImage,
                                              HttpRequest.RequestResult resultHandler)
        {
            ApplicationApi.GetPersonByGuid(person.Guid,
                                           delegate(System.Net.HttpStatusCode statusCode, string statusDescription, Rock.Client.Person model)
            {
                if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true)
                {
                    person = model;

                    // see if we should set their first time visit status
                    if (Config.Instance.RecordFirstVisit == true)
                    {
                        FamilyManagerApi.UpdateOrAddPersonAttribute(person.Id, Config.Instance.FirstTimeVisitAttrib.Key, DateTime.Now.ToString( ), null);
                    }

                    // now update pending attributes.
                    foreach (KeyValuePair <string, string> attribValue in attributes)
                    {
                        // just fire and forget these values.
                        FamilyManagerApi.UpdateOrAddPersonAttribute(person.Id, attribValue.Key, attribValue.Value, null);
                    }

                    // if there's a phone number to send, send it.
                    if (string.IsNullOrWhiteSpace(phoneNumber.Number) == false)
                    {
                        TryUpdateCellPhone(person, isNewPhoneNumber, phoneNumber, personImage, resultHandler);
                    }
                    else
                    {
                        TryUpdateProfilePic(person, personImage, resultHandler);
                    }
                }
                else
                {
                    resultHandler(statusCode, statusDescription);
                }
            });
        }
예제 #17
0
        public static void AddOrUpdateCellPhoneNumber(Rock.Client.Person person, Rock.Client.PhoneNumber phoneNumber, bool isNew, int modifiedById, HttpRequest.RequestResult resultHandler)
        {
            // update the phone number
            phoneNumber.PersonId          = person.Id;
            phoneNumber.NumberTypeValueId = CellPhoneValueId;

            // now we can upload it.
            if (isNew)
            {
                // set the required values for a new phone number
                phoneNumber.Guid = Guid.NewGuid( );
                RockApi.Post_PhoneNumbers(phoneNumber, modifiedById, resultHandler);
            }
            else
            {
                // or just update the existing number
                RockApi.Put_PhoneNumbers(phoneNumber, modifiedById, resultHandler);
            }
        }
예제 #18
0
 static void TryDeleteCellPhone(Rock.Client.Person person,
                                Rock.Client.PhoneNumber phoneNumber,
                                MemoryStream personImage,
                                HttpRequest.RequestResult resultHandler)
 {
     // remove the current number
     ApplicationApi.DeleteCellPhoneNumber(phoneNumber,
                                          delegate(System.Net.HttpStatusCode statusCode, string statusDescription)
     {
         if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true)
         {
             TryUpdateProfilePic(person, personImage, resultHandler);
         }
         else
         {
             resultHandler(statusCode, statusDescription);
         }
     });
 }
        void UIThread_ProfileComplete(System.Net.HttpStatusCode code, string desc, Rock.Client.Person model)
        {
            switch (code)
            {
            case System.Net.HttpStatusCode.OK:
            {
                // make sure they have an alias ID. if they don't, it's a huge bug, and we can't
                // let them proceed.
                if (model.PrimaryAliasId.HasValue)
                {
                    Config.Instance.CurrentPersonAliasId = model.PrimaryAliasId.Value;

                    // now ensure they are authorized
                    FamilyManagerApi.GetAppAuthorization(model.Id, AuthorizationComplete);
                }
                else
                {
                    // if we couldn't get their profile, that should still count as a failed login.
                    SetUIState(LoginState.Out);

                    // failed to login for some reason
                    FadeLoginResult(true);
                    LoginResult.Text = Strings.General_Error_Message;
                    LoginResult.SizeToFit( );
                }

                break;
            }

            default:
            {
                // if we couldn't get their profile, that should still count as a failed login.
                SetUIState(LoginState.Out);

                // failed to login for some reason
                FadeLoginResult(true);
                LoginResult.Text = Strings.General_Error_Message;
                LoginResult.SizeToFit( );

                break;
            }
            }
        }
예제 #20
0
 static void TryUpdateCellPhone(Rock.Client.Person person,
                                bool isNewPhoneNumber,
                                Rock.Client.PhoneNumber phoneNumber,
                                MemoryStream personImage,
                                HttpRequest.RequestResult resultHandler)
 {
     // is their phone number new or existing?
     ApplicationApi.AddOrUpdateCellPhoneNumber(person, phoneNumber, isNewPhoneNumber, Config.Instance.CurrentPersonAliasId,
                                               delegate(System.Net.HttpStatusCode statusCode, string statusDescription)
     {
         if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true)
         {
             TryUpdateProfilePic(person, personImage, resultHandler);
         }
         else
         {
             resultHandler(statusCode, statusDescription);
         }
     });
 }
예제 #21
0
            const int ConnectionStatusTypeValueId = 67; // This represents "Web Prospect", and is the safest default to use.
            static Rock.Client.PersonEntity PackagePersonForUpload(Rock.Client.Person person)
            {
                // there are certain values that cannot be sent up to Rock, so
                // this will ensure that the 'person' object is setup for a clean upload to Rock.
                Rock.Client.PersonEntity newPerson = new Rock.Client.PersonEntity( );
                newPerson.CopyPropertiesFrom(person);
                newPerson.FirstName         = person.NickName;   //ALWAYS SET THE FIRST NAME TO NICK NAME
                newPerson.RecordTypeValueId = RecordTypeValueId; //ALWAYS SET THE RECORD TYPE TO PERSON

                // set the record / connection status values only if they aren't already set.
                if (newPerson.RecordStatusValueId == null)
                {
                    newPerson.RecordStatusValueId = RecordStatusTypeValueId;
                }

                if (newPerson.ConnectionStatusValueId == null)
                {
                    newPerson.ConnectionStatusValueId = ConnectionStatusTypeValueId;
                }

                return(newPerson);
            }
        void RegisterUser()
        {
            if ( State == RegisterState.None )
            {
                // make sure they entered all required fields
                if ( ValidateInput( ) )
                {
                    BlockerView.Show( 
                        delegate
                        {
                            // force the UI to scroll back up
                            ScrollView.ContentOffset = CGPoint.Empty;
                            ScrollView.ScrollEnabled = false;

                            State = RegisterState.Trying;

                            // create a new user and submit them
                            Rock.Client.Person newPerson = new Rock.Client.Person();
                            Rock.Client.PhoneNumber newPhoneNumber = null;

                            // copy all the edited fields into the person object
                            newPerson.Email = EmailText.Field.Text;

                            // set both the nick name and first name to NickName
                            newPerson.NickName = NickNameText.Field.Text;
                            newPerson.FirstName = NickNameText.Field.Text;

                            newPerson.LastName = LastNameText.Field.Text;
                            //newPerson.ConnectionStatusValueId = PrivateGeneralConfig.PersonConnectionStatusValueId;
                            //newPerson.RecordStatusValueId = PrivateGeneralConfig.PersonRecordStatusValueId;

                            // Update their cell phone. 
                            if ( string.IsNullOrEmpty( CellPhoneText.Field.Text ) == false )
                            {
                                // update the phone number
                                string digits = CellPhoneText.Field.Text.AsNumeric( );
                                newPhoneNumber = new Rock.Client.PhoneNumber();
                                newPhoneNumber.Number = digits;
                                newPhoneNumber.NumberFormatted = digits.AsPhoneNumber( );
                            }

                            MobileAppApi.RegisterNewUser( newPerson, newPhoneNumber, UserNameText.Field.Text, PasswordText.Field.Text,
                                delegate(System.Net.HttpStatusCode statusCode, string statusDescription )
                                {
                                    if ( Rock.Mobile.Network.Util.StatusInSuccessRange( statusCode ) == true )
                                    {
                                        ProfileAnalytic.Instance.Trigger( ProfileAnalytic.Register );

                                        State = RegisterState.Success;
                                        ResultView.Show( RegisterStrings.RegisterStatus_Success, 
                                            PrivateControlStylingConfig.Result_Symbol_Success, 
                                            RegisterStrings.RegisterResult_Success,
                                            GeneralStrings.Done );
                                    }
                                    else
                                    {
                                        State = RegisterState.Fail;
                                        ResultView.Show( RegisterStrings.RegisterStatus_Failed, 
                                            PrivateControlStylingConfig.Result_Symbol_Failed, 
                                            statusDescription == RegisterStrings.RegisterResult_BadLogin ? RegisterStrings.RegisterResult_LoginUsed : RegisterStrings.RegisterResult_Failed,
                                            GeneralStrings.Done );
                                    }

                                    BlockerView.Hide( null );
                                } );
                        } );
                }
            }
        }
예제 #23
0
        /// <summary>
        /// Handles the Click event of the btnLogin control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            lblLoginWarning.Visibility = Visibility.Hidden;
            txtUsername.Text           = txtUsername.Text.Trim();
            txtRockUrl.Text            = txtRockUrl.Text.Trim();
            Uri rockUri      = new Uri(txtRockUrl.Text);
            var validSchemes = new string[] { Uri.UriSchemeHttp, Uri.UriSchemeHttps };

            if (!validSchemes.Contains(rockUri.Scheme))
            {
                txtRockUrl.Text = "https://" + rockUri.AbsoluteUri;
            }

            RestClient restClient = new RestClient(txtRockUrl.Text);

            string userName = txtUsername.Text;
            string password = txtPassword.Password;
            string rockUrl  = txtRockUrl.Text;

            if (string.IsNullOrWhiteSpace(userName))
            {
                lblLoginWarning.Content    = "Username cannot be blank";
                lblLoginWarning.Visibility = Visibility.Visible;
                return;
            }

            // start a background thread to Login since this could take a little while and we want a Wait cursor
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += delegate(object s, DoWorkEventArgs ee)
            {
                ee.Result = null;
                restClient.LoginToRock(userName, password);
            };

            // when the Background Worker is done with the Login, run this
            bw.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs ee)
            {
                this.Cursor        = null;
                btnLogin.IsEnabled = true;

                if (ee.Error != null)
                {
                    lblRockUrl.Visibility      = Visibility.Visible;
                    txtRockUrl.Visibility      = Visibility.Visible;
                    lblLoginWarning.Content    = ee.Error.Message;
                    lblLoginWarning.Visibility = Visibility.Visible;
                    return;
                }

                var getByUserNameRequest  = new RestRequest(string.Format("api/People/GetByUserName/{0}", userName));
                var getByUserNameResponse = restClient.Execute <Rock.Client.Person>(getByUserNameRequest);
                if (getByUserNameResponse.ErrorException != null)
                {
                    string message = getByUserNameResponse.ErrorException.Message;
                    if (getByUserNameResponse.ErrorException.InnerException != null)
                    {
                        message += "\n" + getByUserNameResponse.ErrorException.InnerException.Message;
                    }

                    lblRockUrl.Visibility      = Visibility.Visible;
                    txtRockUrl.Visibility      = Visibility.Visible;
                    lblLoginWarning.Content    = message;
                    lblLoginWarning.Visibility = Visibility.Visible;
                    return;
                }

                Rock.Client.Person person     = getByUserNameResponse.Data;
                RockConfig         rockConfig = RockConfig.Load();
                rockConfig.RockBaseUrl = rockUrl;
                rockConfig.Username    = userName;
                rockConfig.Password    = password;

                // Load any stored configuration settings
                rockConfig = this.LoadConfigurationFromSystemSetting(rockConfig);
                rockConfig.Save();

                if (this.NavigationService.CanGoBack)
                {
                    // if we got here from some other Page, go back
                    this.NavigationService.GoBack();
                }
                else
                {
                    StartPage startPage = new StartPage();
                    this.NavigationService.Navigate(startPage);
                }
            };

            // set the cursor to Wait, disable the login button, and start the login background process
            this.Cursor        = Cursors.Wait;
            btnLogin.IsEnabled = false;
            bw.RunWorkerAsync();
        }
예제 #24
0
        /// <summary>
        /// Handles the Click event of the btnLogin control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            txtUsername.Text = txtUsername.Text.Trim();
            txtRockUrl.Text  = txtRockUrl.Text.Trim();
            RockRestClient rockRestClient = new RockRestClient(txtRockUrl.Text);

            string userName = txtUsername.Text;
            string password = txtPassword.Password;

            // start a background thread to Login since this could take a little while and we want a Wait cursor
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += delegate(object s, DoWorkEventArgs ee)
            {
                ee.Result = null;
                rockRestClient.Login(userName, password);
            };

            // when the Background Worker is done with the Login, run this
            bw.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs ee)
            {
                this.Cursor        = null;
                btnLogin.IsEnabled = true;
                try
                {
                    if (ee.Error != null)
                    {
                        throw ee.Error;
                    }

                    Rock.Client.Person person     = rockRestClient.GetData <Rock.Client.Person>(string.Format("api/People/GetByUserName/{0}", userName));
                    RockConfig         rockConfig = RockConfig.Load();
                    rockConfig.RockBaseUrl = txtRockUrl.Text;
                    rockConfig.Username    = txtUsername.Text;
                    rockConfig.Password    = txtPassword.Password;
                    rockConfig.Save();

                    if (this.NavigationService.CanGoBack)
                    {
                        // if we got here from some other Page, go back
                        this.NavigationService.GoBack();
                    }
                    else
                    {
                        StartPage startPage = new StartPage();
                        this.NavigationService.Navigate(startPage);
                    }
                }
                catch (WebException wex)
                {
                    // show WebException on the form, but any others should end up in the ExceptionDialog
                    HttpWebResponse response = wex.Response as HttpWebResponse;
                    if (response != null)
                    {
                        if (response.StatusCode.Equals(HttpStatusCode.Unauthorized))
                        {
                            lblLoginWarning.Content    = "Invalid Login";
                            lblLoginWarning.Visibility = Visibility.Visible;
                            return;
                        }
                    }

                    string message = wex.Message;
                    if (wex.InnerException != null)
                    {
                        message += "\n" + wex.InnerException.Message;
                    }

                    lblRockUrl.Visibility      = Visibility.Visible;
                    txtRockUrl.Visibility      = Visibility.Visible;
                    lblLoginWarning.Content    = message;
                    lblLoginWarning.Visibility = Visibility.Visible;
                    return;
                }
            };

            // set the cursor to Wait, disable the login button, and start the login background process
            this.Cursor        = Cursors.Wait;
            btnLogin.IsEnabled = false;
            bw.RunWorkerAsync();
        }
        public void PresentAnimated( int workingFamilyId,
                                     string workingFamilyLastName,
                                     Rock.Client.Person workingPerson, 
                                     bool isChild,
                                     Dictionary<string, Rock.Client.AttributeValue> attributeValues, 
                                     NSData profilePicBuffer, 
                                     List<Rock.Client.Family> allowedCheckinList,
                                     FamilyInfoViewController.OnPersonInfoCompleteDelegate onComplete )
        {
            OnCompleteDelegate = onComplete;

            WorkingFamilyId = workingFamilyId;

            KeyboardAdjustManager.Activate( );

            // take the provided person as our working person
            if ( workingPerson == null )
            {
                IsNewPerson = true;
                WorkingPerson = new Rock.Client.Person( );

                // since it's a new person, put the last name of the family in there.
                WorkingPerson.LastName = workingFamilyLastName;
            }
            else
            {
                IsNewPerson = false;
                WorkingPerson = workingPerson;
            }

            // we need to know now what values AREN'T set, so we don't inadvertantly set them to defaults.
            WorkingPhoneNumber = RockActions.TryGetPhoneNumber( WorkingPerson, RockActions.CellPhoneValueId );
            if ( WorkingPhoneNumber == null )
            {
                IsNewPhoneNumber = true;
                WorkingPhoneNumber = new Rock.Client.PhoneNumber();
            }
            else
            {
                IsNewPhoneNumber = false;
            }

            PersonInfoToUI( WorkingPerson, WorkingPhoneNumber, isChild, attributeValues, allowedCheckinList );

            // set their profile picture
            UpdateProfilePic( profilePicBuffer );

            View.Hidden = false;

            // animate the background to dark
            BackgroundPanel.Layer.Opacity = 0;

            SimpleAnimator_Float alphaAnim = new SimpleAnimator_Float( BackgroundPanel.Layer.Opacity, Settings.DarkenOpacity, .33f,
                delegate(float percent, object value )
                {
                    BackgroundPanel.Layer.Opacity = (float)value;
                }, null );

            alphaAnim.Start( SimpleAnimator.Style.CurveEaseOut );

            // update the main panel
            MainPanel.Layer.Position = new CoreGraphics.CGPoint( ( View.Bounds.Width - MainPanel.Bounds.Width ) / 2, View.Bounds.Height );

            // animate UP the main panel
            nfloat visibleHeight = Parent.GetVisibleHeight( );
            PointF endPos = new PointF( (float)( View.Bounds.Width - MainPanel.Bounds.Width ) / 2,
                (float)( visibleHeight - MainPanel.Bounds.Height ) / 2 );

            SimpleAnimator_PointF posAnim = new SimpleAnimator_PointF( MainPanel.Layer.Position.ToPointF( ), endPos, .33f,
                delegate(float percent, object value )
                {
                    MainPanel.Layer.Position = (PointF)value;
                },
                null);

            posAnim.Start( SimpleAnimator.Style.CurveEaseOut );

            ViewDidLayoutSubviews( );
        }
예제 #26
0
        void RegisterUser()
        {
            if ( State == RegisterState.None )
            {
                // make sure they entered all required fields
                if ( ValidateInput( ) )
                {
                    ToggleControls( false );

                    ProgressBarBlocker.Visibility = ViewStates.Visible;
                    State = RegisterState.Trying;

                    // create a new user and submit them
                    Rock.Client.Person newPerson = new Rock.Client.Person();
                    Rock.Client.PhoneNumber newPhoneNumber = null;

                    // copy all the edited fields into the person object
                    newPerson.Email = EmailText.Text;

                    newPerson.NickName = NickNameText.Text;
                    newPerson.LastName = LastNameText.Text;
                    newPerson.ConnectionStatusValueId = PrivateGeneralConfig.PersonConnectionStatusValueId;
                    newPerson.RecordStatusValueId = PrivateGeneralConfig.PersonRecordStatusValueId;

                    // Update their cell phone.
                    if ( string.IsNullOrEmpty( CellPhoneText.Text ) == false )
                    {
                        // update the phone number
                        string digits = CellPhoneText.Text.AsNumeric( );
                        newPhoneNumber = new Rock.Client.PhoneNumber();
                        newPhoneNumber.Number = digits;
                        newPhoneNumber.NumberFormatted = digits.AsPhoneNumber( );
                        newPhoneNumber.NumberTypeValueId = PrivateGeneralConfig.CellPhoneValueId;
                    }

                    RockApi.Instance.RegisterNewUser( newPerson, newPhoneNumber, UserNameText.Text, PasswordText.Text,
                        delegate(System.Net.HttpStatusCode statusCode, string statusDescription )
                        {
                            ProgressBarBlocker.Visibility = ViewStates.Gone;
                             ToggleControls( true );

                            if ( Rock.Mobile.Network.Util.StatusInSuccessRange( statusCode ) == true )
                            {
                                ProfileAnalytic.Instance.Trigger( ProfileAnalytic.Register );

                                State = RegisterState.Success;
                                ResultView.Show( RegisterStrings.RegisterStatus_Success,
                                    PrivateControlStylingConfig.Result_Symbol_Success,
                                    RegisterStrings.RegisterResult_Success,
                                    GeneralStrings.Done );
                            }
                            else
                            {
                                State = RegisterState.Fail;
                                ResultView.Show( RegisterStrings.RegisterStatus_Failed,
                                    PrivateControlStylingConfig.Result_Symbol_Failed,
                                    statusDescription == RegisterStrings.RegisterResult_BadLogin ? RegisterStrings.RegisterResult_LoginUsed : RegisterStrings.RegisterResult_Failed,
                                    GeneralStrings.Done );
                            }

                            ResultView.SetBounds( new System.Drawing.RectangleF( 0, 0, NavbarFragment.GetFullDisplayWidth( ), this.Resources.DisplayMetrics.HeightPixels ) );
                        } );
                }
            }
        }
예제 #27
0
        public static void GetFamiliesOfPerson(Rock.Client.Person person, HttpRequest.RequestResult <List <Rock.Client.Group> > resultHandler)
        {
            string oDataFilter = "?$expand=GroupType,Campus,Members/GroupRole,GroupLocations/Location,GroupLocations/GroupLocationTypeValue,GroupLocations/Location/LocationTypeValue";

            RockApi.Get_FamiliesOfPerson(person.Id, oDataFilter, resultHandler);
        }
예제 #28
0
        public static void UploadSavedProfilePicture(Rock.Client.Person person, MemoryStream imageStream, int modifiedById, HttpRequest.RequestResult result)
        {
            // verify it's valid and not corrupt, or otherwise unable to load. If it is, we'll stop here.
            if (imageStream != null)
            {
                // this is a big process. The profile picture being updated also requires the user's
                // profile be updated AND they need to be placed into a special group.
                // So, until ALL THOSE succeed in order, we will not consider the profile image "clean"


                // attempt to upload it
                UploadPersonPicture(imageStream,

                                    delegate(System.Net.HttpStatusCode statusCode, string statusDesc, int photoId)
                {
                    // if the upload went ok
                    if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true)
                    {
                        // now update the profile
                        person.PhotoId = photoId;

                        // attempt to sync the profile
                        UpdateOrAddPerson(person, false, modifiedById,
                                          delegate(System.Net.HttpStatusCode profileStatusCode, string profileStatusDesc)
                        {
                            if (Rock.Mobile.Network.Util.StatusInSuccessRange(profileStatusCode) == true)
                            {
                                // now (and only now) that we know the profile was updated correctly,
                                // we can update the image group.
                                UpdatePersonImageGroup(person, modifiedById,
                                                       delegate(System.Net.HttpStatusCode resultCode, string resultDesc)
                                {
                                    if (result != null)
                                    {
                                        result(statusCode, statusDesc);
                                    }
                                });
                            }
                            else
                            {
                                if (result != null)
                                {
                                    result(statusCode, statusDesc);
                                }
                            }
                        });
                    }
                    else
                    {
                        if (result != null)
                        {
                            result(statusCode, statusDesc);
                        }
                    }
                });
            }
            else
            {
                // the picture failed to save
                result(System.Net.HttpStatusCode.BadRequest, "");
            }
        }
예제 #29
0
 public static void UpdatePerson(Rock.Client.Person person, int modifiedById, HttpRequest.RequestResult resultHandler)
 {
     RockApi.Put_People(person, modifiedById, resultHandler);
 }