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


C# PersonService.Queryable方法代码示例

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


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

示例1: Search

        /// <summary>
        /// Returns a list of matching people
        /// </summary>
        /// <param name="searchterm"></param>
        /// <returns></returns>
        public override IQueryable<string> Search( string searchterm )
        {
            var personService = new PersonService( new RockContext() );

            return personService.Queryable().
                Where( p => p.Email.Contains( searchterm ) ).
                OrderBy( p => p.Email ).
                Select( p => p.Email ).Distinct();
        }
开发者ID:tcavaletto,项目名称:Rock-CentralAZ,代码行数:14,代码来源:Email.cs

示例2: GetPersonFromId

        protected Person GetPersonFromId(string PersonId)
        {
            int intPersonId = Int32.Parse(PersonId);
            PersonService personService = new PersonService(rockContext);

            var person = personService.Queryable().FirstOrDefault(p => p.Id == intPersonId);

            return person;
        }
开发者ID:NewPointe,项目名称:Rockit,代码行数:9,代码来源:ShapeResults.ascx.cs

示例3: GetPersonFromForm

        protected Person GetPersonFromForm(string formId)
        {
            AttributeValueService attributeValueService = new AttributeValueService(rockContext);
            PersonService personService = new PersonService(rockContext);
            PersonAliasService personAliasService = new PersonAliasService(rockContext);

            var formAttribute = attributeValueService.Queryable().FirstOrDefault(a => a.Value == formId);
            var person = personService.Queryable().FirstOrDefault(p => p.Id == formAttribute.EntityId);

            return person;
        }
开发者ID:NewPointe,项目名称:Rockit,代码行数:11,代码来源:ShapeResults.ascx.cs

示例4: RunCommand

        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void RunCommand()
        {
            gReport.CreatePreviewColumns( typeof( Person ) );

            var service = new PersonService();
            var people = service.Queryable().Where( p => p.LastName == "Turner" );
            var parents = service.Transform( people, new Rock.Reporting.DataTransform.Person.ParentTransform() );

            gReport.DataSource = parents.ToList();
            gReport.DataBind();
        }
开发者ID:pkdevbox,项目名称:Rock,代码行数:14,代码来源:TestLinqGrid.ascx.cs

示例5: BindGiversGrid

        /// <summary>
        /// Binds the attendees grid.
        /// </summary>
        private void BindGiversGrid()
        {
            // Get all the selected criteria values
            var dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues( drpSlidingDateRange.DelimitedValues );
            var start = dateRange.Start;
            var end = dateRange.End;

            var minAmount = nreAmount.LowerValue;
            var maxAmount = nreAmount.UpperValue;

            var currencyTypeIds = new List<int>();
            cblCurrencyTypes.SelectedValues.ForEach( i => currencyTypeIds.Add( i.AsInteger() ) );

            var sourceTypeIds = new List<int>();
            cblTransactionSource.SelectedValues.ForEach( i => sourceTypeIds.Add( i.AsInteger() ) );

            var accountIds = new List<int>();
            foreach ( var cblAccounts in phAccounts.Controls.OfType<RockCheckBoxList>() )
            {
                accountIds.AddRange( cblAccounts.SelectedValuesAsInt );
            }

            var dataViewId = dvpDataView.SelectedValueAsInt();

            GiversViewBy viewBy = GiversViewBy.Giver;
            if ( !HideViewByOption )
            {
                viewBy = hfViewBy.Value.ConvertToEnumOrNull<GiversViewBy>() ?? GiversViewBy.Giver;
            }

            // Clear all the existing grid columns
            var selectField = new SelectField();
            var oldSelectField = gGiversGifts.ColumnsOfType<SelectField>().FirstOrDefault();
            if (oldSelectField != null )
            {
                selectField.SelectedKeys.AddRange( oldSelectField.SelectedKeys );
            }

            gGiversGifts.Columns.Clear();

            // Add a column for selecting rows
            gGiversGifts.Columns.Add( selectField );

            // Add a column for the person's name
            gGiversGifts.Columns.Add(
                new RockBoundField
                {
                    DataField = "PersonName",
                    HeaderText = "Person",
                    SortExpression = "LastName,NickName"
                } );

            // add a column for email (but is only included on excel export)
            gGiversGifts.Columns.Add(
                new RockBoundField
                {
                    DataField = "Email",
                    HeaderText = "Email",
                    SortExpression = "Email",
                    Visible = false,
                    ExcelExportBehavior = ExcelExportBehavior.AlwaysInclude
                } );

            // Add a column for total amount
            gGiversGifts.Columns.Add(
                new CurrencyField
                {
                    DataField = "TotalAmount",
                    HeaderText = "Total",
                    SortExpression = "TotalAmount"
                } );

            // Add columns for the selected account totals
            if ( accountIds.Any() )
            {
                var accounts = new FinancialAccountService( _rockContext )
                    .Queryable().AsNoTracking()
                    .Where( a => accountIds.Contains( a.Id ) )
                    .ToList();

                foreach ( int accountId in accountIds )
                {
                    var account = accounts.FirstOrDefault( a => a.Id == accountId );
                    if ( account != null )
                    {
                        gGiversGifts.Columns.Add(
                            new CurrencyField
                            {
                                DataField = account.Id.ToString(),
                                HeaderText = account.Name,
                                SortExpression = account.Id.ToString()
                            } );
                    }
                }
            }

            // Add a column for the number of gifts
//.........这里部分代码省略.........
开发者ID:RMRDevelopment,项目名称:Rockit,代码行数:101,代码来源:GivingAnalytics.ascx.cs

示例6: GetExpression

        /// <summary>
        /// Creates a Linq Expression that can be applied to an IQueryable to filter the result set.
        /// </summary>
        /// <param name="entityType">The type of entity in the result set.</param>
        /// <param name="serviceInstance">A service instance that can be queried to obtain the result set.</param>
        /// <param name="parameterExpression">The input parameter that will be injected into the filter expression.</param>
        /// <param name="selection">A formatted string representing the filter settings.</param>
        /// <returns>
        /// A Linq Expression that can be used to filter an IQueryable.
        /// </returns>
        public override Expression GetExpression( Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection )
        {
            var settings = new FilterSettings( selection );

            var context = (RockContext)serviceInstance.Context;

            //
            // Define Candidate People.
            //

            // Get the Person Data View that defines the set of candidates from which matching Group Members can be selected.
            var dataView = DataComponentSettingsHelper.GetDataViewForFilterComponent( settings.PersonDataViewGuid, context );

            var personService = new PersonService( context );

            var personQuery = personService.Queryable();

            if (dataView != null)
            {
                personQuery = DataComponentSettingsHelper.FilterByDataView( personQuery, dataView, personService );
            }

            var personKeys = personQuery.Select( x => x.Id );

            //
            // Construct the Query to return the list of Groups matching the filter conditions.
            //
            var comparisonType = settings.PersonCountComparison;
            int memberCountValue = settings.PersonCount;

            var memberCountQuery = new GroupService( context ).Queryable();

            var memberCountEqualQuery = memberCountQuery.Where( g => g.Members.Count( gm => personKeys.Contains( gm.PersonId ) ) == memberCountValue );

            var compareEqualExpression = FilterExpressionExtractor.Extract<Model.Group>( memberCountEqualQuery, parameterExpression, "g" ) as BinaryExpression;
            var result = FilterExpressionExtractor.AlterComparisonType( comparisonType, compareEqualExpression, 0 );

            return result;
        }
开发者ID:azturner,项目名称:Rock,代码行数:49,代码来源:ContainsPeopleFilter.cs

示例7: BindGrid

        private void BindGrid()
        {
            var birthDateCol = gPeople.ColumnsOfType<DateField>().First( c => c.DataField == "BirthDate" );
            birthDateCol.Visible = GetAttributeValue( "ShowBirthdate" ).AsBoolean();

            string type = PageParameter( "SearchType" );
            string term = PageParameter( "SearchTerm" );

            if ( !string.IsNullOrWhiteSpace( type ) && !string.IsNullOrWhiteSpace( term ) )
            {
                term = term.Trim();
                type = type.Trim();
                var rockContext = new RockContext();

                var personService = new PersonService( rockContext );
                IQueryable<Person> people = null;

                switch ( type.ToLower() )
                {
                    case ( "name" ):
                        {
                            bool allowFirstNameOnly = false;
                            if ( !bool.TryParse( PageParameter( "allowFirstNameOnly" ), out allowFirstNameOnly ) )
                            {
                                allowFirstNameOnly = false;
                            }
                            people = personService.GetByFullName( term, allowFirstNameOnly, true );
                            break;
                        }
                    case ( "phone" ):
                        {
                            var phoneService = new PhoneNumberService( rockContext );
                            var personIds = phoneService.GetPersonIdsByNumber( term );
                            people = personService.Queryable().Where( p => personIds.Contains( p.Id ) );
                            break;
                        }
                    case ( "address" ):
                        {
                            var groupMemberService = new GroupMemberService( rockContext );
                            var personIds2 = groupMemberService.GetPersonIdsByHomeAddress( term );
                            people = personService.Queryable().Where( p => personIds2.Contains( p.Id ) );
                            break;
                        }
                    case ( "email" ):
                        {
                            people = personService.Queryable().Where( p => p.Email.Contains( term ) );
                            break;
                        }
                }

                var personIdList = people.Select( p => p.Id ).ToList();

                people = personService.Queryable(true).Where( p => personIdList.Contains( p.Id ) );

                SortProperty sortProperty = gPeople.SortProperty;
                if ( sortProperty != null )
                {
                    people = people.Sort( sortProperty );
                }
                else
                {
                    people = people.OrderBy( p => p.LastName ).ThenBy( p => p.FirstName );
                }

                Guid familyGuid = new Guid( Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY );
                Guid homeAddressTypeGuid = new Guid( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_HOME );

                var personList = people.Select( p => new PersonSearchResult
                {
                    Id = p.Id,
                    FirstName = p.FirstName,
                    NickName = p.NickName,
                    LastName = p.LastName,
                    BirthDate = p.BirthDate,
                    BirthYear = p.BirthYear,
                    BirthMonth = p.BirthMonth,
                    BirthDay = p.BirthDay,
                    ConnectionStatusValueId = p.ConnectionStatusValueId,
                    RecordStatusValueId = p.RecordStatusValueId,
                    RecordTypeValueId = p.RecordTypeValueId,
                    SuffixValueId = p.SuffixValueId,
                    IsDeceased = p.IsDeceased,
                    Email = p.Email,
                    Gender = p.Gender,
                    PhotoId = p.PhotoId,
                    CampusIds = p.Members
                        .Where( m =>
                            m.Group.GroupType.Guid.Equals( familyGuid ) &&
                            m.Group.CampusId.HasValue )
                        .Select( m => m.Group.CampusId.Value )
                        .ToList(),
                    HomeAddresses = p.Members
                        .Where( m => m.Group.GroupType.Guid == familyGuid )
                        .SelectMany( m => m.Group.GroupLocations )
                        .Where( gl => gl.GroupLocationTypeValue.Guid.Equals( homeAddressTypeGuid ) )
                        .Select( gl => gl.Location )
                } ).ToList();

                if ( personList.Count == 1 )
                {
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例8: FindDuplicates

        public bool FindDuplicates()
        {
            Duplicates = new Dictionary<Guid, List<Person>>();

            var rockContext = new RockContext();
            var locationService = new LocationService( rockContext );
            var groupService = new GroupService( rockContext );
            var personService = new PersonService( rockContext );

            // Find any other group members (any group) that have same location
            var othersAtAddress = new List<int>();

            string locationKey = GetLocationKey();
            if ( !string.IsNullOrWhiteSpace(locationKey) && _verifiedLocations.ContainsKey( locationKey))
            {
                int? locationId = _verifiedLocations[locationKey];
                if ( locationId.HasValue )
                {
                    var location = locationService.Get( locationId.Value );
                    if ( location != null )
                    {
                        othersAtAddress = groupService
                            .Queryable().AsNoTracking()
                            .Where( g =>
                                g.GroupTypeId == _locationType.Id &&
                                g.GroupLocations.Any( l => l.LocationId == location.Id ) )
                            .SelectMany( g => g.Members )
                            .Select( m => m.PersonId )
                            .ToList();
                    }
                }
            }

            foreach ( var person in GroupMembers
                .Where( m =>
                    m.Person != null &&
                    m.Person.FirstName != "" )
                .Select( m => m.Person ) )
            {
                bool otherCriteria = false;
                var personQry = personService
                    .Queryable().AsNoTracking()
                    .Where( p =>
                        p.FirstName == person.FirstName ||
                        p.NickName == person.FirstName );

                if ( othersAtAddress.Any() )
                {
                    personQry = personQry
                        .Where( p => othersAtAddress.Contains( p.Id ) );
                }

                if ( person.BirthDate.HasValue )
                {
                    otherCriteria = true;
                    personQry = personQry
                        .Where( p =>
                            p.BirthDate.HasValue &&
                            p.BirthDate.Value == person.BirthDate.Value );
                }

                if ( _homePhone != null )
                {
                    var homePhoneNumber = person.PhoneNumbers.Where( p => p.NumberTypeValueId == _homePhone.Id ).FirstOrDefault();
                    if ( homePhoneNumber != null )
                    {
                        otherCriteria = true;
                        personQry = personQry
                            .Where( p =>
                                p.PhoneNumbers.Any( n =>
                                    n.NumberTypeValueId == _homePhone.Id &&
                                    n.Number == homePhoneNumber.Number ) );
                    }
                }

                if ( _cellPhone != null )
                {
                    var cellPhoneNumber = person.PhoneNumbers.Where( p => p.NumberTypeValueId == _cellPhone.Id ).FirstOrDefault();
                    if ( cellPhoneNumber != null )
                    {
                        otherCriteria = true;
                        personQry = personQry
                            .Where( p =>
                                p.PhoneNumbers.Any( n =>
                                    n.NumberTypeValueId == _cellPhone.Id &&
                                    n.Number == cellPhoneNumber.Number ) );
                    }
                }

                if ( !string.IsNullOrWhiteSpace( person.Email ) )
                {
                    otherCriteria = true;
                    personQry = personQry
                        .Where( p => p.Email == person.Email );
                }

                var dups = new List<Person>();
                if ( otherCriteria )
                {
                    // If a birthday, email, phone, or address was entered, find anyone with same info and same first name
//.........这里部分代码省略.........
开发者ID:NewPointe,项目名称:Rockit,代码行数:101,代码来源:AddGroup.ascx.cs

示例9: BindGrid

        /// <summary>
        /// Binds the grid.
        /// </summary>
        protected void BindGrid()
        {
            var showProfilesViewed = GetAttributeValue( "SeeProfilesViewed" ).AsBoolean();
            var rockContext = new RockContext();

            var personViewedService = new PersonViewedService( rockContext );
            var personService = new PersonService( rockContext );
            if ( showProfilesViewed )
            {
                // This grid should show the profiles viewed by this person.
                pnlViewed.Visible = true;
                pnlViewedBy.Visible = false;

                if ( personId.HasValue )
                {
                    var viewedList = personViewedService.Queryable()
                        .Where( p => p.ViewerPersonAlias != null && p.ViewerPersonAlias.PersonId == personId )
                        .GroupBy( p => p.TargetPersonAlias.PersonId )
                        .Select( p => new
                        {
                            TargetPersonId = p.Key,
                            FirstViewed = p.Min( g => g.ViewDateTime ),
                            LastViewed = p.Max( g => g.ViewDateTime ),
                            ViewedCount = p.Count()
                        } );

                    var pQry = personService.Queryable();

                    var qry = viewedList
                        .Join( pQry, v => v.TargetPersonId, p => p.Id, ( v, p ) => new
                        {
                            p.Id,
                            FullName = p.NickName + " " + p.LastName,
                            p.BirthDate,
                            p.Gender,
                            FirstViewedDate = v.FirstViewed,
                            LastViewedDate = v.LastViewed,
                            ViewedCount = v.ViewedCount
                        } );

                    SortProperty sortProperty = gViewed.SortProperty;
                    if ( sortProperty != null )
                    {
                        qry = qry.Sort( sortProperty );
                    }
                    else
                    {
                        qry = qry.OrderByDescending( q => q.LastViewedDate );
                    }

                    gViewed.DataSource = qry.ToList();
                    gViewed.DataBind();
                }
            }
            else
            {
                // This grid should show the profiles that have viewed this person.
                pnlViewed.Visible = false;
                pnlViewedBy.Visible = true;

                if ( personId.HasValue )
                {
                    var viewedList = personViewedService.Queryable()
                        .Where( p => p.TargetPersonAlias != null && p.TargetPersonAlias.PersonId == personId )
                        .GroupBy( p => p.ViewerPersonAlias.PersonId )
                        .Select( p => new
                        {
                            ViewerPersonId = p.Key,
                            FirstViewed = p.Min( g => g.ViewDateTime ),
                            LastViewed = p.Max( g => g.ViewDateTime ),
                            ViewedCount = p.Count()
                        } );

                    var pQry = personService.Queryable();

                    var qry = viewedList
                        .Join( pQry, v => v.ViewerPersonId, p => p.Id, ( v, p ) => new
                        {
                            p.Id,
                            FullName = p.NickName + " " + p.LastName,
                            p.BirthDate,
                            p.Gender,
                            FirstViewedDate = v.FirstViewed,
                            LastViewedDate = v.LastViewed,
                            ViewedCount = v.ViewedCount
                        } );

                    SortProperty sortProperty = gViewedBy.SortProperty;
                    if ( sortProperty != null )
                    {
                        qry = qry.Sort( sortProperty );
                    }
                    else
                    {
                        qry = qry.OrderByDescending( q => q.LastViewedDate );
                    }

//.........这里部分代码省略.........
开发者ID:Higherbound,项目名称:Higherbound-2016-website-upgrades,代码行数:101,代码来源:PersonViewedSummary.ascx.cs

示例10: BindGrid

        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            RockContext rockContext = new RockContext();
            PersonService personService = new PersonService( rockContext );

            // sample query to display a few people
            var qry = personService.Queryable()
                        .Where( p => p.Gender == Gender.Male)
                        .Take(10);

            gList.DataSource = qry.ToList();
            gList.DataBind();
        }
开发者ID:tcavaletto,项目名称:Rock-CentralAZ,代码行数:16,代码来源:StarkList.ascx.cs

示例11: GetChartData

        /// <summary>
        /// Gets the chart data.
        /// </summary>
        /// <param name="groupBy">The group by.</param>
        /// <param name="graphBy">The graph by.</param>
        /// <param name="startDate">The start date.</param>
        /// <param name="endDate">The end date.</param>
        /// <param name="groupIds">The group ids.</param>
        /// <param name="campusIds">The campus ids. Include the keyword 'null' in the list to include CampusId is null</param>
        /// <param name="scheduleIds">The schedule ids.</param>
        /// <param name="dataViewId">The data view identifier.</param>
        /// <returns></returns>
        public IEnumerable<IChartData> GetChartData( ChartGroupBy groupBy = ChartGroupBy.Week, AttendanceGraphBy graphBy = AttendanceGraphBy.Total, DateTime? startDate = null, DateTime? endDate = null, string groupIds = null, string campusIds = null, int? dataViewId = null, string scheduleIds = null )
        {
            var qryAttendance = Queryable().AsNoTracking()
                .Where( a =>
                    a.DidAttend.HasValue &&
                    a.DidAttend.Value &&
                    a.PersonAlias != null );

            if ( startDate.HasValue )
            {
                qryAttendance = qryAttendance.Where( a => a.StartDateTime >= startDate.Value );
            }

            if ( endDate.HasValue )
            {
                qryAttendance = qryAttendance.Where( a => a.StartDateTime < endDate.Value );
            }

            if ( dataViewId.HasValue )
            {
                var rockContext = (RockContext)this.Context;

                var dataView = new DataViewService( rockContext ).Get( dataViewId.Value );
                if ( dataView != null )
                {
                    var personService = new PersonService( rockContext );

                    var errorMessages = new List<string>();
                    ParameterExpression paramExpression = personService.ParameterExpression;
                    Expression whereExpression = dataView.GetExpression( personService, paramExpression, out errorMessages );

                    Rock.Web.UI.Controls.SortProperty sort = null;
                    var dataViewPersonIdQry = personService
                        .Queryable().AsNoTracking()
                        .Where( paramExpression, whereExpression, sort )
                        .Select( p => p.Id );

                    qryAttendance = qryAttendance.Where( a => dataViewPersonIdQry.Contains( a.PersonAlias.PersonId ) );
                }
            }

            if ( !string.IsNullOrWhiteSpace( groupIds ) )
            {
                var groupIdList = groupIds.Split( ',' ).AsIntegerList();
                qryAttendance = qryAttendance.Where( a => a.GroupId.HasValue && groupIdList.Contains( a.GroupId.Value ) );
            }

            // If campuses were included, filter attendances by those that have selected campuses
            // if 'null' is one of the campuses, treat that as a 'CampusId is Null'
            var includeNullCampus = ( campusIds ?? "" ).Split( ',' ).ToList().Any( a => a.Equals( "null", StringComparison.OrdinalIgnoreCase ) );
            var campusIdList = ( campusIds ?? "" ).Split( ',' ).AsIntegerList();

            // remove 0 from the list, just in case it is there
            campusIdList.Remove( 0 );

            if ( campusIdList.Any() )
            {
                if ( includeNullCampus )
                {
                    // show records that have a campusId in the campusIdsList + records that have a null campusId
                    qryAttendance = qryAttendance.Where( a => ( a.CampusId.HasValue && campusIdList.Contains( a.CampusId.Value ) ) || !a.CampusId.HasValue );
                }
                else
                {
                    // only show records that have a campusId in the campusIdList
                    qryAttendance = qryAttendance.Where( a => a.CampusId.HasValue && campusIdList.Contains( a.CampusId.Value ) );
                }
            }
            else if ( includeNullCampus )
            {
                // 'null' was the only campusId in the campusIds parameter, so only show records that have a null CampusId
                qryAttendance = qryAttendance.Where( a => !a.CampusId.HasValue );
            }

            // If schedules were included, filter attendances by those that have selected schedules
            var scheduleIdList = ( scheduleIds ?? "" ).Split( ',' ).AsIntegerList();
            scheduleIdList.Remove( 0 );
            if ( scheduleIdList.Any() )
            {
                qryAttendance = qryAttendance.Where( a => a.ScheduleId.HasValue && scheduleIdList.Contains( a.ScheduleId.Value ) );
            }

            var qryAttendanceWithSummaryDateTime = qryAttendance.GetAttendanceWithSummaryDateTime( groupBy );

            var summaryQry = qryAttendanceWithSummaryDateTime.Select( a => new
            {
                a.SummaryDateTime,
                Campus = new
//.........这里部分代码省略.........
开发者ID:SparkDevNetwork,项目名称:Rock,代码行数:101,代码来源:AttendanceService.Partial.cs

示例12: GetExpression

        /// <summary>
        /// Creates a Linq Expression that can be applied to an IQueryable to filter the result set.
        /// </summary>
        /// <param name="entityType">The type of entity in the result set.</param>
        /// <param name="serviceInstance">A service instance that can be queried to obtain the result set.</param>
        /// <param name="parameterExpression">The input parameter that will be injected into the filter expression.</param>
        /// <param name="selection">A formatted string representing the filter settings.</param>
        /// <returns>
        /// A Linq Expression that can be used to filter an IQueryable.
        /// </returns>
        public override Expression GetExpression( Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection )
        {
            var settings = new FilterSettings( selection );

            var context = (RockContext)serviceInstance.Context;

            //
            // Define Candidate People.
            //

            var dataView = DataComponentSettingsHelper.GetDataViewForFilterComponent( settings.PersonDataViewGuid, context );

            var personService = new PersonService( context );

            var personQuery = personService.Queryable();

            if ( dataView != null )
            {
                personQuery = DataComponentSettingsHelper.FilterByDataView( personQuery, dataView, personService );
            }

            var personKeys = personQuery.Select( x => x.Id );

            //
            // Construct the Query to return the list of Group Members matching the filter conditions.
            //
            var groupMemberQuery = new GroupMemberService( context ).Queryable();

            groupMemberQuery = groupMemberQuery.Where( gm => personKeys.Contains( gm.PersonId ) );

            var result = FilterExpressionExtractor.Extract<Rock.Model.GroupMember>( groupMemberQuery, parameterExpression, "gm" );

            return result;
        }
开发者ID:NewSpring,项目名称:Rock,代码行数:44,代码来源:ContainsPeopleFilter.cs

示例13: BindGrid

        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            using ( var rockContext = new RockContext() )
            {
                var personService = new PersonService( rockContext );

                var qry = personService.Queryable().AsNoTracking()
                    .Select( p => new
                    {
                        p.Id,
                        p.NickName,
                        p.LastName
                    } );

                AddGridColumns( qry.FirstOrDefault() );

                SortProperty sortProperty = gReport.SortProperty;
                if ( sortProperty != null )
                {
                    gReport.SetLinqDataSource( qry.Sort( sortProperty ) );
                }
                else
                {
                    gReport.SetLinqDataSource( qry.OrderBy( p => p.LastName ).ThenBy( p => p.LastName ) );
                }

                gReport.DataBind();
            }
        }
开发者ID:NewPointe,项目名称:Rockit,代码行数:32,代码来源:SampleLinqReport.ascx.cs

示例14: Authenticate

        /// <summary>
        /// Authenticates the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="username">The username.</param>
        /// <param name="returnUrl">The return URL.</param>
        /// <returns></returns>
        public override Boolean Authenticate( HttpRequest request, out string username, out string returnUrl )
        {
            var fbClient = new FacebookClient();
            FacebookOAuthResult oAuthResult;

            if ( fbClient.TryParseOAuthCallbackUrl( request.Url, out oAuthResult ) && oAuthResult.IsSuccess )
            {
                try
                {
                    var redirectUri = new Uri( GetRedirectUrl( request ) );

                    dynamic parameters = new ExpandoObject();
                    parameters.client_id = GetAttributeValue( "AppID" );
                    parameters.client_secret = GetAttributeValue( "AppSecret" );
                    parameters.redirect_uri = redirectUri.AbsoluteUri; 
                    parameters.code = oAuthResult.Code;

                    dynamic result = fbClient.Post( "oauth/access_token", parameters );

                    string accessToken = result.access_token;

                    fbClient = new FacebookClient( accessToken );
                    dynamic me = fbClient.Get( "me" );
                    string facebookId = "FACEBOOK_" + me.id.ToString();

                    // query for matching id in the user table 
                    var userLoginService = new UserLoginService();
                    var user = userLoginService.GetByUserName( facebookId );

                    // if not user was found see if we can find a match in the person table
                    if ( user == null )
                    {
                        try
                        {
                            // determine if we can find a match and if so add an user login record

                            // get properties from Facebook dynamic object
                            string lastName = me.last_name.ToString();
                            string firstName = me.first_name.ToString();
                            string email = me.email.ToString();

                            var personService = new PersonService();
                            var person = personService.Queryable().FirstOrDefault( u => u.LastName == lastName && u.FirstName == firstName && u.Email == email );

                            if ( person != null )
                            {
                                // since we have the data enter the birthday from Facebook to the db if we don't have it yet
                                DateTime birthdate = Convert.ToDateTime( me.birthday.ToString() );

                                if ( person.BirthDay == null )
                                {
                                    person.BirthDate = birthdate;
                                    personService.Save( person, person.Id );
                                }

                            }
                            else
                            {

                                var dvService = new DefinedValueService();

                                person = new Person();
                                person.IsSystem = false;
                                person.RecordTypeValueId = dvService.GetIdByGuid( new Guid( SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON ) );
                                person.RecordStatusValueId = dvService.GetIdByGuid( new Guid( SystemGuid.DefinedValue.PERSON_RECORD_STATUS_ACTIVE ) );

                                person.FirstName = me.first_name.ToString();
                                person.LastName = me.last_name.ToString();
                                person.Email = me.email.ToString();

                                if ( me.gender.ToString() == "male" )
                                    person.Gender = Gender.Male;
                                else if ( me.gender.ToString() == "female" )
                                    person.Gender = Gender.Female;
                                else
                                    person.Gender = Gender.Unknown;

                                person.BirthDate = Convert.ToDateTime( me.birthday.ToString() );
                                person.DoNotEmail = false;

                                personService.Add( person, null );
                                personService.Save( person, null );
                            }

                            user = userLoginService.Create( person, AuthenticationServiceType.External, this.TypeId, facebookId, "fb", true, person.Id );
                        }
                        catch ( Exception ex )
                        {
                            string msg = ex.Message;
                            // TODO: probably should report something...
                        }

                        // TODO: Show label indicating inability to find user corresponding to facebook id
//.........这里部分代码省略.........
开发者ID:pkdevbox,项目名称:Rock,代码行数:101,代码来源:Facebook.cs

示例15: AddFamilies

        /// <summary>
        /// Handles adding families from the given XML element snippet
        /// </summary>
        /// <param name="elemFamilies">The xml element containing all the families.</param>
        /// <param name="rockContext">The rock context.</param>
        private void AddFamilies( XElement elemFamilies, RockContext rockContext )
        {
            if ( elemFamilies == null )
            {
                return;
            }

            bool fabricateAttendance = GetAttributeValue( "FabricateAttendance" ).AsBoolean();
            GroupService groupService = new GroupService( rockContext );
            var allFamilies = rockContext.Groups;

            List<Group> allGroups = new List<Group>();

            // Next create the family along with its members.
            foreach ( var elemFamily in elemFamilies.Elements( "family" ) )
            {
                Guid guid = elemFamily.Attribute( "guid" ).Value.Trim().AsGuid();
                var familyMembers = BuildFamilyMembersFromXml( elemFamily.Element( "members" ), rockContext );

                // Call replica of groupService's SaveNewFamily method in an attempt to speed things up
                Group family = CreateNewFamily( familyMembers, campusId: 1 );
                family.Guid = guid;

                // add the family to the context's list of groups
                allFamilies.Add( family );

                // add the families address(es)
                AddFamilyAddresses( groupService, family, elemFamily.Element( "addresses" ), rockContext );

                // add their attendance data
                if ( fabricateAttendance )
                {
                    AddFamilyAttendance( family, elemFamily, rockContext );
                }

                allGroups.Add( family );

                _stopwatch.Stop();
                _sb.AppendFormat( "{0:00}:{1:00}.{2:00} added {3}<br/>", _stopwatch.Elapsed.Minutes, _stopwatch.Elapsed.Seconds, _stopwatch.Elapsed.Milliseconds / 10, family.Name );
                _stopwatch.Start();
            }
            rockContext.ChangeTracker.DetectChanges();
            rockContext.SaveChanges( disablePrePostProcessing: true );

            // Now save each person's attributevalues (who had them defined in the XML)
            // and add each person's ID to a dictionary for use later.
            AttributeValueService attributeValueService = new AttributeValueService( rockContext );
            foreach ( var gm in allGroups.SelectMany( g => g.Members ) )
            {
                // Put the person's id into the people dictionary for later use.
                if ( !_peopleDictionary.ContainsKey( gm.Person.Guid ) )
                {
                    _peopleDictionary.Add( gm.Person.Guid, gm.Person.Id );
                }

                // Only save if the person had attributes, otherwise it will error.
                if ( _personWithAttributes.ContainsKey( gm.Person.Guid ) )
                {
                    foreach ( var attributeCache in gm.Person.Attributes.Select( a => a.Value ) )
                    {
                        var newValue = gm.Person.AttributeValues[attributeCache.Key].FirstOrDefault();
                        if ( newValue != null )
                        {
                            newValue.EntityId = gm.Person.Id;
                            rockContext.AttributeValues.Add( newValue );
                        }
                    }
                }
            }

            _stopwatch.Stop();
            _sb.AppendFormat( "{0:00}:{1:00}.{2:00} saved attributes for everyone <br/>", _stopwatch.Elapsed.Minutes, _stopwatch.Elapsed.Seconds, _stopwatch.Elapsed.Milliseconds / 10 );
            _stopwatch.Start();

            // Create person alias records for each person
            PersonService personService = new PersonService( rockContext );
            foreach ( var person in personService.Queryable( "Aliases" )
                .Where( p =>
                    _peopleDictionary.Keys.Contains( p.Guid ) &&
                    !p.Aliases.Any() ) )
            {
                person.Aliases.Add( new PersonAlias { AliasPersonId = person.Id, AliasPersonGuid = person.Guid } );
            }

            _stopwatch.Stop();
            _sb.AppendFormat( "{0:00}:{1:00}.{2:00} added person aliases<br/>", _stopwatch.Elapsed.Minutes, _stopwatch.Elapsed.Seconds, _stopwatch.Elapsed.Milliseconds / 10 );
            _stopwatch.Start();
        }
开发者ID:CentralAZ,项目名称:Rockit-CentralAZ,代码行数:93,代码来源:SampleData.ascx.cs


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