本文整理汇总了C#中Group.SaveAttributeValues方法的典型用法代码示例。如果您正苦于以下问题:C# Group.SaveAttributeValues方法的具体用法?C# Group.SaveAttributeValues怎么用?C# Group.SaveAttributeValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Group
的用法示例。
在下文中一共展示了Group.SaveAttributeValues方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddGroups
//.........这里部分代码省略.........
group.LoadAttributes( rockContext );
// Set the study topic
if ( elemGroup.Attribute( "studyTopic" ) != null )
{
var topic = elemGroup.Attribute( "studyTopic" ).Value;
DefinedValue smallGroupTopicDefinedValue = _smallGroupTopicDefinedType.DefinedValues.FirstOrDefault( a => a.Value == topic );
// add it as new if we didn't find it.
if ( smallGroupTopicDefinedValue == null )
{
smallGroupTopicDefinedValue = AddDefinedTypeValue( topic, _smallGroupTopicDefinedType, rockContext );
}
group.SetAttributeValue( "Topic", smallGroupTopicDefinedValue.Guid.ToString() );
}
// Set the schedule and meeting time
if ( elemGroup.Attribute( "groupSchedule" ) != null )
{
string[] schedule = elemGroup.Attribute( "groupSchedule" ).Value.SplitDelimitedValues( whitespace: false );
if ( schedule[0] == "weekly" )
{
var dow = schedule[1];
var time = schedule[2];
AddWeeklySchedule( group, dow, time );
}
}
// Add each person as a member
foreach ( var elemPerson in elemGroup.Elements( "person" ) )
{
Guid personGuid = elemPerson.Attribute( "guid" ).Value.Trim().AsGuid();
GroupMember groupMember = new GroupMember();
groupMember.GroupMemberStatus = GroupMemberStatus.Active;
if ( elemPerson.Attribute( "isLeader" ) != null )
{
bool isLeader = elemPerson.Attribute( "isLeader" ).Value.Trim().AsBoolean();
if ( isLeader )
{
var gtLeaderRole = groupType.Roles.Where( r => r.IsLeader ).FirstOrDefault();
if ( gtLeaderRole != null )
{
groupMember.GroupRoleId = gtLeaderRole.Id;
}
}
}
else
{
groupMember.GroupRoleId = roleId ?? -1;
}
groupMember.PersonId = _peopleDictionary[personGuid];
group.Members.Add( groupMember );
}
groupService.Add( group );
// Now we have to save changes in order for the attributes to be saved correctly.
rockContext.SaveChanges();
group.SaveAttributeValues( rockContext );
if ( !_groupDictionary.ContainsKey( group.Guid ) )
{
_groupDictionary.Add( group.Guid, group.Id );
}
// Now add any group location schedules
LocationService locationService = new LocationService( rockContext );
ScheduleService scheduleService = new ScheduleService( rockContext );
Guid locationTypeMeetingLocationGuid = new Guid( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_MEETING_LOCATION );
var locationTypeMeetingLocationId = Rock.Web.Cache.DefinedValueCache.Read( locationTypeMeetingLocationGuid ).Id;
foreach ( var elemLocation in elemGroup.Elements( "location" ) )
{
Guid locationGuid = elemLocation.Attribute( "guid" ).Value.Trim().AsGuid();
Location location = locationService.Get( locationGuid );
GroupLocation groupLocation = new GroupLocation();
groupLocation.Location = location;
groupLocation.GroupLocationTypeValueId = locationTypeMeetingLocationId;
group.GroupLocations.Add( groupLocation );
foreach ( var elemSchedule in elemLocation.Elements( "schedule" ) )
{
try
{
Guid scheduleGuid = elemSchedule.Attribute( "guid" ).Value.Trim().AsGuid();
Schedule schedule = scheduleService.Get( scheduleGuid );
groupLocation.Schedules.Add( schedule );
}
catch
{ }
}
TimeSpan ts = _stopwatch.Elapsed;
AppendFormat( "{0:00}:{1:00}.{2:00} group location schedules added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );
}
}
}
示例2: AddGroups
//.........这里部分代码省略.........
GroupService groupService = new GroupService( rockContext );
// Next create the group along with its members.
foreach ( var elemGroup in elemGroups.Elements( "group" ) )
{
Guid guid = elemGroup.Attribute( "guid" ).Value.Trim().AsGuid();
string type = elemGroup.Attribute( "type" ).Value;
Group group = new Group()
{
Guid = guid,
Name = elemGroup.Attribute( "name" ).Value.Trim()
};
// skip any where there is no group type given -- they are invalid entries.
if ( string.IsNullOrEmpty( elemGroup.Attribute( "type" ).Value.Trim() ) )
{
return;
}
int? roleId;
GroupTypeCache groupType;
switch ( elemGroup.Attribute( "type" ).Value.Trim() )
{
case "serving":
groupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_SERVING_TEAM.AsGuid() );
group.GroupTypeId = groupType.Id;
roleId = groupType.DefaultGroupRoleId;
break;
case "smallgroup":
groupType = GroupTypeCache.Read( Rock.SystemGuid.GroupType.GROUPTYPE_SMALL_GROUP.AsGuid() );
group.GroupTypeId = groupType.Id;
roleId = groupType.DefaultGroupRoleId;
break;
default:
throw new NotSupportedException( string.Format( "unknown group type {0}", elemGroup.Attribute( "type" ).Value.Trim() ) );
}
if ( elemGroup.Attribute( "description" ) != null )
{
group.Description = elemGroup.Attribute( "description" ).Value;
}
if ( elemGroup.Attribute( "parentGroupGuid" ) != null )
{
var parentGroup = groupService.Get( elemGroup.Attribute( "parentGroupGuid" ).Value.AsGuid() );
group.ParentGroupId = parentGroup.Id;
}
// Set the group's meeting location
if ( elemGroup.Attribute( "meetsAtHomeOfFamily" ) != null )
{
int meetingLocationValueId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_MEETING_LOCATION.AsGuid() ).Id;
var groupLocation = new GroupLocation()
{
IsMappedLocation = false,
IsMailingLocation = false,
GroupLocationTypeValueId = meetingLocationValueId,
LocationId = _familyLocationDictionary[elemGroup.Attribute( "meetsAtHomeOfFamily" ).Value.AsGuid()],
};
// Set the group location's GroupMemberPersonId if given (required?)
if ( elemGroup.Attribute( "meetsAtHomeOfPerson" ) != null )
{
groupLocation.GroupMemberPersonId = _peopleDictionary[elemGroup.Attribute( "meetsAtHomeOfPerson" ).Value.AsGuid()];
}
group.GroupLocations.Add( groupLocation );
}
group.LoadAttributes();
// Set the study topic
if ( elemGroup.Attribute( "studyTopic" ) != null )
{
group.SetAttributeValue( "StudyTopic", elemGroup.Attribute( "studyTopic" ).Value );
}
// Set the meeting time
if ( elemGroup.Attribute( "meetingTime" ) != null )
{
group.SetAttributeValue( "MeetingTime", elemGroup.Attribute( "meetingTime" ).Value );
}
// Add each person as a member
foreach ( var elemPerson in elemGroup.Elements( "person" ) )
{
Guid personGuid = elemPerson.Attribute( "guid" ).Value.Trim().AsGuid();
GroupMember groupMember = new GroupMember();
groupMember.GroupMemberStatus = GroupMemberStatus.Active;
groupMember.GroupRoleId = roleId ?? -1;
groupMember.PersonId = _peopleDictionary[personGuid];
group.Members.Add( groupMember );
}
groupService.Add( group );
group.SaveAttributeValues( rockContext );
}
}
示例3: AddGroups
//.........这里部分代码省略.........
roleId = groupType.DefaultGroupRoleId;
break;
default:
throw new NotSupportedException( string.Format( "unknown group type {0}", elemGroup.Attribute( "type" ).Value.Trim() ) );
}
if ( elemGroup.Attribute( "description" ) != null )
{
group.Description = elemGroup.Attribute( "description" ).Value;
}
if ( elemGroup.Attribute( "parentGroupGuid" ) != null )
{
var parentGroup = groupService.Get( elemGroup.Attribute( "parentGroupGuid" ).Value.AsGuid() );
group.ParentGroupId = parentGroup.Id;
}
// Set the group's meeting location
if ( elemGroup.Attribute( "meetsAtHomeOfFamily" ) != null )
{
int meetingLocationValueId = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_MEETING_LOCATION.AsGuid() ).Id;
var groupLocation = new GroupLocation()
{
IsMappedLocation = false,
IsMailingLocation = false,
GroupLocationTypeValueId = meetingLocationValueId,
LocationId = _familyLocationDictionary[elemGroup.Attribute( "meetsAtHomeOfFamily" ).Value.AsGuid()],
};
// Set the group location's GroupMemberPersonId if given (required?)
if ( elemGroup.Attribute( "meetsAtHomeOfPerson" ) != null )
{
groupLocation.GroupMemberPersonId = _peopleDictionary[elemGroup.Attribute( "meetsAtHomeOfPerson" ).Value.AsGuid()];
}
group.GroupLocations.Add( groupLocation );
}
group.LoadAttributes( rockContext );
// Set the study topic
if ( elemGroup.Attribute( "studyTopic" ) != null )
{
group.SetAttributeValue( "StudyTopic", elemGroup.Attribute( "studyTopic" ).Value );
}
// Set the meeting time
if ( elemGroup.Attribute( "meetingTime" ) != null )
{
group.SetAttributeValue( "MeetingTime", elemGroup.Attribute( "meetingTime" ).Value );
}
// Add each person as a member
foreach ( var elemPerson in elemGroup.Elements( "person" ) )
{
Guid personGuid = elemPerson.Attribute( "guid" ).Value.Trim().AsGuid();
GroupMember groupMember = new GroupMember();
groupMember.GroupMemberStatus = GroupMemberStatus.Active;
groupMember.GroupRoleId = roleId ?? -1;
groupMember.PersonId = _peopleDictionary[personGuid];
group.Members.Add( groupMember );
}
groupService.Add( group );
// Now we have to save changes in order for the attributes to be saved correctly.
rockContext.SaveChanges();
group.SaveAttributeValues( rockContext );
// Now add any group location schedules
LocationService locationService = new LocationService( rockContext );
ScheduleService scheduleService = new ScheduleService( rockContext );
Guid locationTypeMeetingLocationGuid = new Guid( Rock.SystemGuid.DefinedValue.GROUP_LOCATION_TYPE_MEETING_LOCATION );
var locationTypeMeetingLocationId = Rock.Web.Cache.DefinedValueCache.Read( locationTypeMeetingLocationGuid ).Id;
foreach ( var elemLocation in elemGroup.Elements( "location" ) )
{
Guid locationGuid = elemLocation.Attribute( "guid" ).Value.Trim().AsGuid();
Location location = locationService.Get( locationGuid );
GroupLocation groupLocation = new GroupLocation();
groupLocation.Location = location;
groupLocation.GroupLocationTypeValueId = locationTypeMeetingLocationId;
group.GroupLocations.Add( groupLocation );
foreach ( var elemSchedule in elemLocation.Elements( "schedule" ) )
{
try
{
Guid scheduleGuid = elemSchedule.Attribute( "guid" ).Value.Trim().AsGuid();
Schedule schedule = scheduleService.Get( scheduleGuid );
groupLocation.Schedules.Add( schedule );
}
catch
{ }
}
TimeSpan ts = _stopwatch.Elapsed;
_sb.AppendFormat( "{0:00}:{1:00}.{2:00} group location schedules added<br/>", ts.Minutes, ts.Seconds, ts.Milliseconds / 10 );
}
}
}