当前位置: 首页>>代码示例>>C#>>正文


C# PersonAliasService.GetHomeLocation方法代码示例

本文整理汇总了C#中Rock.Model.PersonAliasService.GetHomeLocation方法的典型用法代码示例。如果您正苦于以下问题:C# PersonAliasService.GetHomeLocation方法的具体用法?C# PersonAliasService.GetHomeLocation怎么用?C# PersonAliasService.GetHomeLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rock.Model.PersonAliasService的用法示例。


在下文中一共展示了PersonAliasService.GetHomeLocation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute( RockContext rockContext, WorkflowAction action, Object entity, out List<string> errorMessages )
        {
            errorMessages = new List<string>();

            var mergeFields = GetMergeFields( action );

            var homePhoneValueId = DefinedValueCache.Read( SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME ).Id;
            var mobilePhoneValueId = DefinedValueCache.Read( SystemGuid.DefinedValue.PERSON_PHONE_TYPE_MOBILE ).Id;
            var workPhoneValueId = DefinedValueCache.Read( SystemGuid.DefinedValue.PERSON_PHONE_TYPE_WORK ).Id;

            // get requester
            var requestPerson = new PersonAliasService( rockContext ).Get( GetAttributeValue( action, "Person", true ).AsGuid() ).Person;
            if (requestPerson == null )
            {
                var errorMessage = "Could not determine the person for the request.";
                errorMessages.Add( errorMessage );
                action.AddLogEntry( errorMessage, true );
                return false;
            }

            // get case worker
            var caseWorker = new PersonAliasService( rockContext ).Get( GetAttributeValue( action, "CaseWorker", true ).AsGuid() )?.Person;

            // get request status
            var statusValue = DefinedValueCache.Read( GetAttributeValue( action, "RequestStatus" ) );
            if ( statusValue == null )
            {
                var errorMessage = "Invalid request status provided.";
                errorMessages.Add( errorMessage );
                action.AddLogEntry( errorMessage, true );
                return false;
            }

            // get request description
            var requestDescription = GetAttributeValue( action, "RequestDescription", true ).ResolveMergeFields( mergeFields );
            if ( string.IsNullOrWhiteSpace( requestDescription ) )
            {
                var errorMessage = "Request description is requried.";
                errorMessages.Add( errorMessage );
                action.AddLogEntry( errorMessage, true );
                return false;
            }

            // get government id
            var governmentId = GetAttributeValue( action, "GovernmentId", true ).ResolveMergeFields( mergeFields );

            // get campus
            int? campusId = CampusCache.Read( GetAttributeValue( action, "Campus" ).AsGuid() )?.Id;

            // create benevolence request
            BenevolenceRequestService benevolenceRequestService = new BenevolenceRequestService( rockContext );

            BenevolenceRequest request = new BenevolenceRequest();
            benevolenceRequestService.Add( request );

            request.RequestDateTime = RockDateTime.Now;
            request.RequestText = requestDescription;
            request.RequestedByPersonAliasId = requestPerson.PrimaryAliasId;
            request.FirstName = requestPerson.NickName;
            request.LastName = requestPerson.LastName;
            request.Email = requestPerson.Email;
            request.LocationId = requestPerson.GetHomeLocation()?.Id;
            request.GovernmentId = governmentId;

            if ( campusId.HasValue )
            {
                request.CampusId = campusId.Value;
            }
            else
            {
                request.CampusId = requestPerson.GetCampus()?.Id;
            }

            var requestorPhoneNumbers = requestPerson.PhoneNumbers;

            if ( requestorPhoneNumbers != null )
            {
                request.HomePhoneNumber = requestorPhoneNumbers.Where( p => p.NumberTypeValueId == homePhoneValueId ).FirstOrDefault()?.NumberFormatted;
                request.CellPhoneNumber = requestorPhoneNumbers.Where( p => p.NumberTypeValueId == mobilePhoneValueId ).FirstOrDefault()?.NumberFormatted;
                request.WorkPhoneNumber = requestorPhoneNumbers.Where( p => p.NumberTypeValueId == workPhoneValueId ).FirstOrDefault()?.NumberFormatted;
            }

            if( caseWorker != null )
            {
                request.CaseWorkerPersonAliasId = caseWorker.PrimaryAliasId;
            }

            request.ConnectionStatusValueId = requestPerson.ConnectionStatusValueId;
            request.RequestStatusValueId = statusValue.Id;

            rockContext.SaveChanges();

//.........这里部分代码省略.........
开发者ID:NewSpring,项目名称:Rock,代码行数:101,代码来源:BenevolenceRequestAdd.cs


注:本文中的Rock.Model.PersonAliasService.GetHomeLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。