本文整理汇总了C#中Rock.Data.UnitOfWorkScope类的典型用法代码示例。如果您正苦于以下问题:C# Rock.Data.UnitOfWorkScope类的具体用法?C# Rock.Data.UnitOfWorkScope怎么用?C# Rock.Data.UnitOfWorkScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Rock.Data.UnitOfWorkScope类属于命名空间,在下文中一共展示了Rock.Data.UnitOfWorkScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Move
public void Move( string id, Rock.CMS.DTO.BlockInstance BlockInstance )
{
var currentUser = Rock.CMS.UserService.GetCurrentUser();
if ( currentUser == null )
throw new WebFaultException<string>( "Must be logged in", System.Net.HttpStatusCode.Forbidden );
using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
{
uow.objectContext.Configuration.ProxyCreationEnabled = false;
Rock.CMS.BlockInstanceService BlockInstanceService = new Rock.CMS.BlockInstanceService();
Rock.CMS.BlockInstance existingBlockInstance = BlockInstanceService.Get( int.Parse( id ) );
if ( existingBlockInstance.Authorized( "Edit", currentUser ) )
{
// If the block was moved from or to the layout section, then all the pages
// that use that layout need to be flushed from cache
if ( existingBlockInstance.Layout != BlockInstance.Layout )
{
if ( existingBlockInstance.Layout != null )
Rock.Web.Cache.Page.FlushLayout( existingBlockInstance.Layout );
if ( BlockInstance.Layout != null )
Rock.Web.Cache.Page.FlushLayout( BlockInstance.Layout );
}
uow.objectContext.Entry( existingBlockInstance ).CurrentValues.SetValues( BlockInstance );
BlockInstanceService.Move( existingBlockInstance );
BlockInstanceService.Save( existingBlockInstance, currentUser.PersonId );
}
else
throw new WebFaultException<string>( "Not Authorized to Edit this BlockInstance", System.Net.HttpStatusCode.Forbidden );
}
}
示例2: Available
public bool Available( string username )
{
using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
{
uow.objectContext.Configuration.ProxyCreationEnabled = false;
Rock.CMS.UserService UserService = new Rock.CMS.UserService();
User User = UserService.GetByUserName( username );
return ( User == null );
}
}
示例3: ApiFlushGlobal
public void ApiFlushGlobal( string apiKey )
{
using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
{
Rock.CMS.UserService userService = new Rock.CMS.UserService();
Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault();
if ( user != null )
FlushGlobal();
else
throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
}
}
示例4: ApiDeletePage
public void ApiDeletePage( string id, string apiKey )
{
using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
{
Rock.CMS.UserService userService = new Rock.CMS.UserService();
Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault();
if (user != null)
{
uow.objectContext.Configuration.ProxyCreationEnabled = false;
Rock.CMS.PageService PageService = new Rock.CMS.PageService();
Rock.CMS.Page Page = PageService.Get( int.Parse( id ) );
if ( Page.Authorized( "Edit", user ) )
{
PageService.Delete( Page, user.PersonId );
PageService.Save( Page, user.PersonId );
}
else
throw new WebFaultException<string>( "Not Authorized to Edit this Page", System.Net.HttpStatusCode.Forbidden );
}
else
throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
}
}
示例5: ApiCreatePage
public void ApiCreatePage( string apiKey, Rock.CMS.DTO.Page Page )
{
using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
{
Rock.CMS.UserService userService = new Rock.CMS.UserService();
Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault();
if (user != null)
{
uow.objectContext.Configuration.ProxyCreationEnabled = false;
Rock.CMS.PageService PageService = new Rock.CMS.PageService();
Rock.CMS.Page existingPage = new Rock.CMS.Page();
PageService.Add( existingPage, user.PersonId );
uow.objectContext.Entry(existingPage).CurrentValues.SetValues(Page);
if (existingPage.IsValid)
PageService.Save( existingPage, user.PersonId );
else
throw new WebFaultException<string>( existingPage.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
}
else
throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
}
}
示例6: ApiMove
public void ApiMove( string id, string apiKey, Rock.CMS.DTO.BlockInstance BlockInstance )
{
using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
{
Rock.CMS.UserService userService = new Rock.CMS.UserService();
Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault();
if ( user != null )
{
uow.objectContext.Configuration.ProxyCreationEnabled = false;
Rock.CMS.BlockInstanceService BlockInstanceService = new Rock.CMS.BlockInstanceService();
Rock.CMS.BlockInstance existingBlockInstance = BlockInstanceService.Get( int.Parse( id ) );
if ( existingBlockInstance.Authorized( "Edit", user ) )
{
// If the block was moved from or to the layout section, then all the pages
// that use that layout need to be flushed from cache
if ( existingBlockInstance.Layout != BlockInstance.Layout )
{
if ( existingBlockInstance.Layout != null )
Rock.Web.Cache.Page.FlushLayout( existingBlockInstance.Layout );
if ( BlockInstance.Layout != null )
Rock.Web.Cache.Page.FlushLayout( BlockInstance.Layout );
}
uow.objectContext.Entry( existingBlockInstance ).CurrentValues.SetValues( BlockInstance );
BlockInstanceService.Move( existingBlockInstance );
BlockInstanceService.Save( existingBlockInstance, user.PersonId );
}
else
throw new WebFaultException<string>( "Not Authorized to Edit this BlockInstance", System.Net.HttpStatusCode.Forbidden );
}
else
throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
}
}
示例7: ApiGet
public Rock.CMS.DTO.Page ApiGet( string id, string apiKey )
{
using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
{
Rock.CMS.UserService userService = new Rock.CMS.UserService();
Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault();
if (user != null)
{
uow.objectContext.Configuration.ProxyCreationEnabled = false;
Rock.CMS.PageService PageService = new Rock.CMS.PageService();
Rock.CMS.Page Page = PageService.Get( int.Parse( id ) );
if ( Page.Authorized( "View", user ) )
return Page.DataTransferObject;
else
throw new WebFaultException<string>( "Not Authorized to View this Page", System.Net.HttpStatusCode.Forbidden );
}
else
throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
}
}
示例8: UpdatePage
public void UpdatePage( string id, Rock.CMS.DTO.Page Page )
{
var currentUser = Rock.CMS.UserService.GetCurrentUser();
if ( currentUser == null )
throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden );
using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
{
uow.objectContext.Configuration.ProxyCreationEnabled = false;
Rock.CMS.PageService PageService = new Rock.CMS.PageService();
Rock.CMS.Page existingPage = PageService.Get( int.Parse( id ) );
if ( existingPage.Authorized( "Edit", currentUser ) )
{
uow.objectContext.Entry(existingPage).CurrentValues.SetValues(Page);
if (existingPage.IsValid)
PageService.Save( existingPage, currentUser.PersonId );
else
throw new WebFaultException<string>( existingPage.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
}
else
throw new WebFaultException<string>( "Not Authorized to Edit this Page", System.Net.HttpStatusCode.Forbidden );
}
}
示例9: Get
public Rock.CMS.DTO.Page Get( string id )
{
var currentUser = Rock.CMS.UserService.GetCurrentUser();
if ( currentUser == null )
throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden );
using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope())
{
uow.objectContext.Configuration.ProxyCreationEnabled = false;
Rock.CMS.PageService PageService = new Rock.CMS.PageService();
Rock.CMS.Page Page = PageService.Get( int.Parse( id ) );
if ( Page.Authorized( "View", currentUser ) )
return Page.DataTransferObject;
else
throw new WebFaultException<string>( "Not Authorized to View this Page", System.Net.HttpStatusCode.Forbidden );
}
}
示例10: DeletePage
public void DeletePage( string id )
{
var currentUser = Rock.CMS.UserService.GetCurrentUser();
if ( currentUser == null )
throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden );
using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
{
uow.objectContext.Configuration.ProxyCreationEnabled = false;
Rock.CMS.PageService PageService = new Rock.CMS.PageService();
Rock.CMS.Page Page = PageService.Get( int.Parse( id ) );
if ( Page.Authorized( "Edit", currentUser ) )
{
PageService.Delete( Page, currentUser.PersonId );
PageService.Save( Page, currentUser.PersonId );
}
else
throw new WebFaultException<string>( "Not Authorized to Edit this Page", System.Net.HttpStatusCode.Forbidden );
}
}
示例11: CreateEntityChange
public void CreateEntityChange( Rock.Core.DTO.EntityChange EntityChange )
{
var currentUser = Rock.CMS.UserService.GetCurrentUser();
if ( currentUser == null )
throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden );
using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
{
uow.objectContext.Configuration.ProxyCreationEnabled = false;
Rock.Core.EntityChangeService EntityChangeService = new Rock.Core.EntityChangeService();
Rock.Core.EntityChange existingEntityChange = new Rock.Core.EntityChange();
EntityChangeService.Add( existingEntityChange, currentUser.PersonId );
uow.objectContext.Entry(existingEntityChange).CurrentValues.SetValues(EntityChange);
if (existingEntityChange.IsValid)
EntityChangeService.Save( existingEntityChange, currentUser.PersonId );
else
throw new WebFaultException<string>( existingEntityChange.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
}
}
示例12: ApiUpdateEntityChange
public void ApiUpdateEntityChange( string id, string apiKey, Rock.Core.DTO.EntityChange EntityChange )
{
using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() )
{
Rock.CMS.UserService userService = new Rock.CMS.UserService();
Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault();
if (user != null)
{
uow.objectContext.Configuration.ProxyCreationEnabled = false;
Rock.Core.EntityChangeService EntityChangeService = new Rock.Core.EntityChangeService();
Rock.Core.EntityChange existingEntityChange = EntityChangeService.Get( int.Parse( id ) );
if ( existingEntityChange.Authorized( "Edit", user ) )
{
uow.objectContext.Entry(existingEntityChange).CurrentValues.SetValues(EntityChange);
if (existingEntityChange.IsValid)
EntityChangeService.Save( existingEntityChange, user.PersonId );
else
throw new WebFaultException<string>( existingEntityChange.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest );
}
else
throw new WebFaultException<string>( "Not Authorized to Edit this EntityChange", System.Net.HttpStatusCode.Forbidden );
}
else
throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden );
}
}
示例13: Execute
/// <summary>
/// Executes the specified workflow.
/// </summary>
/// <param name="action">The workflow action.</param>
/// <param name="entity">The entity.</param>
/// <param name="errorMessages">The error messages.</param>
/// <returns></returns>
/// <exception cref="System.NotImplementedException"></exception>
public override bool Execute( Model.WorkflowAction action, Object entity, out List<string> errorMessages )
{
var checkInState = GetCheckInState( entity, out errorMessages );
var labels = new List<CheckInLabel>();
if ( checkInState != null )
{
int labelFileTypeId = new BinaryFileTypeService()
.Queryable()
.Where( f => f.Guid == new Guid(SystemGuid.BinaryFiletype.CHECKIN_LABEL))
.Select( f => f.Id)
.FirstOrDefault();
if (labelFileTypeId != 0)
{
using ( var uow = new Rock.Data.UnitOfWorkScope() )
{
foreach ( var family in checkInState.CheckIn.Families.Where( f => f.Selected ) )
{
foreach ( var person in family.People.Where( p => p.Selected ) )
{
foreach ( var groupType in person.GroupTypes.Where( g => g.Selected ) )
{
var mergeObjects = new Dictionary<string, object>();
mergeObjects.Add( "person", person );
mergeObjects.Add( "groupType", groupType );
groupType.Labels = new List<CheckInLabel>();
GetGroupTypeLabels( groupType.GroupType, groupType.Labels, labelFileTypeId, mergeObjects );
var PrinterIPs = new Dictionary<int, string>();
foreach ( var label in groupType.Labels )
{
label.PrintFrom = checkInState.Kiosk.Device.PrintFrom;
label.PrintTo = checkInState.Kiosk.Device.PrintToOverride;
if ( label.PrintTo == PrintTo.Default )
{
label.PrintTo = groupType.GroupType.AttendancePrintTo;
}
if ( label.PrintTo == PrintTo.Kiosk )
{
var device = checkInState.Kiosk.Device;
if ( device != null )
{
label.PrinterDeviceId = device.PrinterDeviceId;
}
}
else if ( label.PrintTo == PrintTo.Location )
{
// Should only be one
var group = groupType.Groups.Where( g => g.Selected ).FirstOrDefault();
if ( group != null )
{
var location = group.Locations.Where( l => l.Selected ).FirstOrDefault();
if ( location != null )
{
var device = location.Location.PrinterDevice;
if ( device != null )
{
label.PrinterDeviceId = device.PrinterDeviceId;
}
}
}
}
if ( label.PrinterDeviceId.HasValue )
{
if ( PrinterIPs.ContainsKey( label.PrinterDeviceId.Value ) )
{
label.PrinterAddress = PrinterIPs[label.PrinterDeviceId.Value];
}
else
{
var printerDevice = new DeviceService().Get( label.PrinterDeviceId.Value );
if ( printerDevice != null )
{
PrinterIPs.Add( printerDevice.Id, printerDevice.IPAddress );
label.PrinterAddress = printerDevice.IPAddress;
}
}
}
}
}
}
}
//.........这里部分代码省略.........
示例14: Execute
/// <summary>
/// Executes the specified workflow.
/// </summary>
/// <param name="action">The workflow action.</param>
/// <param name="entity">The entity.</param>
/// <param name="errorMessages">The error messages.</param>
/// <returns></returns>
/// <exception cref="System.NotImplementedException"></exception>
public override bool Execute( Model.WorkflowAction action, Object entity, out List<string> errorMessages )
{
var checkInState = GetCheckInState( entity, out errorMessages );
if ( checkInState != null )
{
DateTime startDateTime = DateTime.Now;
int securityCodeLength = 3;
if ( !int.TryParse( GetAttributeValue( action, "SecurityCodeLength" ), out securityCodeLength ) )
{
securityCodeLength = 3;
}
using ( var uow = new Rock.Data.UnitOfWorkScope() )
{
var attendanceCodeService = new AttendanceCodeService();
var attendanceService = new AttendanceService();
var groupMemberService = new GroupMemberService();
foreach ( var family in checkInState.CheckIn.Families.Where( f => f.Selected ) )
{
foreach ( var person in family.People.Where( p => p.Selected ) )
{
var attendanceCode = attendanceCodeService.GetNew( securityCodeLength );
person.SecurityCode = attendanceCode.Code;
foreach ( var groupType in person.GroupTypes.Where( g => g.Selected ) )
{
foreach ( var group in groupType.Groups.Where( g => g.Selected ) )
{
foreach ( var location in group.Locations.Where( l => l.Selected ) )
{
if ( groupType.GroupType.AttendanceRule == AttendanceRule.AddOnCheckIn &&
groupType.GroupType.DefaultGroupRoleId.HasValue &&
!groupMemberService.GetByGroupIdAndPersonId( group.Group.Id, person.Person.Id, true ).Any() )
{
var groupMember = new GroupMember();
groupMember.GroupId = group.Group.Id;
groupMember.PersonId = person.Person.Id;
groupMember.GroupRoleId = groupType.GroupType.DefaultGroupRoleId.Value;
groupMemberService.Add( groupMember, null );
groupMemberService.Save( groupMember, null );
}
foreach ( var schedule in location.Schedules.Where( s => s.Selected ) )
{
// Only create one attendance record per day for each person/schedule/group/location
var attendance = attendanceService.Get( startDateTime, location.Location.Id, schedule.Schedule.Id, group.Group.Id, person.Person.Id );
if ( attendance == null )
{
attendance = ((Rock.Data.RockContext)uow.DbContext).Attendances.Create();
attendance.LocationId = location.Location.Id;
attendance.ScheduleId = schedule.Schedule.Id;
attendance.GroupId = group.Group.Id;
attendance.PersonId = person.Person.Id;
attendance.DeviceId = checkInState.Kiosk.Device.Id;
attendance.SearchTypeValueId = checkInState.CheckIn.SearchType.Id;
attendanceService.Add( attendance, null );
}
attendance.AttendanceCodeId = attendanceCode.Id;
attendance.StartDateTime = startDateTime;
attendance.EndDateTime = null;
attendance.DidAttend = true;
attendanceService.Save( attendance, null );
KioskLocationAttendance.AddAttendance( attendance );
}
}
}
}
}
}
}
return true;
}
return false;
}
示例15: BindGrid
private void BindGrid()
{
string type = PageParameter( "SearchType" );
string term = PageParameter( "SearchTerm" );
List<Person> personList = null;
if ( !String.IsNullOrWhiteSpace( type ) && !String.IsNullOrWhiteSpace( term ) )
{
using ( var uow = new Rock.Data.UnitOfWorkScope() )
{
IQueryable<Person> people = null;
var personService = new PersonService();
switch ( type.ToLower() )
{
case ( "name" ):
people = personService.GetByFullName( term, true );
break;
case ( "phone" ):
var phoneService = new PhoneNumberService();
var personIds = phoneService.GetPersonIdsByNumber( term );
people = personService.Queryable().Where( p => personIds.Contains( p.Id ) );
break;
case ( "address" ):
var groupMemberService = new GroupMemberService();
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;
}
SortProperty sortProperty = gPeople.SortProperty;
if ( sortProperty != null )
{
people = people.Sort( sortProperty );
}
else
{
people = people.OrderBy( p => p.LastName ).ThenBy( p => p.FirstName );
}
personList = people.ToList();
}
}
if ( personList != null )
{
if ( personList.Count == 1 )
{
Response.Redirect( string.Format( "~/Person/{0}", personList[0].Id ), false );
Context.ApplicationInstance.CompleteRequest();
}
else
{
gPeople.DataSource = personList;
gPeople.DataBind();
}
}
}