本文整理汇总了C#中WorkflowTypeService.Get方法的典型用法代码示例。如果您正苦于以下问题:C# WorkflowTypeService.Get方法的具体用法?C# WorkflowTypeService.Get怎么用?C# WorkflowTypeService.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorkflowTypeService
的用法示例。
在下文中一共展示了WorkflowTypeService.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LaunchTheWorkflow
/// <summary>
/// Launch the workflow
/// </summary>
protected void LaunchTheWorkflow(string workflowName)
{
Guid workflowTypeGuid = Guid.NewGuid();
if ( Guid.TryParse( workflowName, out workflowTypeGuid ) )
{
var rockContext = new RockContext();
var workflowTypeService = new WorkflowTypeService(rockContext);
var workflowType = workflowTypeService.Get( workflowTypeGuid );
if ( workflowType != null )
{
var workflow = Rock.Model.Workflow.Activate( workflowType, workflowName );
List<string> workflowErrors;
if ( workflow.Process( rockContext, out workflowErrors ) )
{
if ( workflow.IsPersisted || workflowType.IsPersisted )
{
var workflowService = new Rock.Model.WorkflowService(rockContext);
workflowService.Add( workflow );
rockContext.WrapTransaction( () =>
{
rockContext.SaveChanges();
workflow.SaveAttributeValues( rockContext );
foreach ( var activity in workflow.Activities )
{
activity.SaveAttributeValues( rockContext );
}
} );
}
}
}
}
}
示例2: Execute
/// <summary>
/// Execute method to write transaction to the database.
/// </summary>
public void Execute()
{
if ( Trigger != null )
{
var rockContext = new RockContext();
var workflowTypeService = new WorkflowTypeService( rockContext );
var workflowType = workflowTypeService.Get( Trigger.WorkflowTypeId );
if ( workflowType != null )
{
var workflow = Rock.Model.Workflow.Activate( workflowType, Trigger.WorkflowName );
List<string> workflowErrors;
if ( workflow.Process( rockContext, Entity, out workflowErrors ) )
{
if ( workflow.IsPersisted || workflowType.IsPersisted )
{
var workflowService = new Rock.Model.WorkflowService( rockContext );
workflowService.Add( workflow );
rockContext.WrapTransaction( () =>
{
rockContext.SaveChanges();
workflow.SaveAttributeValues( rockContext );
foreach ( var activity in workflow.Activities )
{
activity.SaveAttributeValues( rockContext );
}
} );
}
}
}
}
}
示例3: 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 workflowTypeGuid = GetAttributeValue(action, "WorkflowType").AsGuidOrNull();
var workflowName = GetAttributeValue(action, "WorkflowName");
if (workflowTypeGuid.HasValue && !string.IsNullOrEmpty(workflowName))
{
var sourceKeyMap = new Dictionary<string, string>();
var workflowAttributeKeys = GetAttributeValue(action, "WorkflowAttributeKey");
if (!string.IsNullOrWhiteSpace(workflowAttributeKeys))
{
//TODO Find a way upstream to stop an additional being appended to the value
sourceKeyMap = workflowAttributeKeys.AsDictionaryOrNull();
var workflowTypeService = new WorkflowTypeService(rockContext);
var workflow = Rock.Model.Workflow.Activate(workflowTypeService.Get(workflowTypeGuid.Value), workflowName);
workflow.LoadAttributes(rockContext);
foreach (var keyPair in sourceKeyMap)
{
//Does the source key exist as an attribute in the source workflow?
if (action.Activity.Workflow.Attributes.ContainsKey(keyPair.Key))
{
if (workflow.Attributes.ContainsKey(keyPair.Value))
{
var value = action.Activity.Workflow.AttributeValues[keyPair.Key].Value;
workflow.SetAttributeValue(keyPair.Value, value);
}
else
{
errorMessages.Add(string.Format("{0} not a key in {1}", keyPair.Value, action.Activity.Workflow.Name));
}
}
else
{
errorMessages.Add(string.Format("{0} not a key in {1}", keyPair.Key, workflowName));
}
}
new Rock.Model.WorkflowService(rockContext).Process(workflow, out errorMessages);
}
}
else
{
errorMessages.Add("Workflow type or name not provided");
}
return true;
}
示例4: LaunchTheWorkflow
/// <summary>
/// Launch the workflow
/// </summary>
protected void LaunchTheWorkflow(string workflowName)
{
Guid workflowTypeGuid = Guid.NewGuid();
if ( Guid.TryParse( workflowName, out workflowTypeGuid ) )
{
var rockContext = new RockContext();
var workflowTypeService = new WorkflowTypeService(rockContext);
var workflowType = workflowTypeService.Get( workflowTypeGuid );
if ( workflowType != null )
{
var workflow = Rock.Model.Workflow.Activate( workflowType, workflowName );
List<string> workflowErrors;
new Rock.Model.WorkflowService( rockContext ).Process( workflow, out workflowErrors );
}
}
}
示例5: LaunchTheWorkflow
/// <summary>
/// Launch the workflow
/// </summary>
protected void LaunchTheWorkflow( string workflowName, IJobExecutionContext context )
{
Guid workflowTypeGuid = Guid.NewGuid();
if ( Guid.TryParse( workflowName, out workflowTypeGuid ) )
{
var rockContext = new RockContext();
var workflowTypeService = new WorkflowTypeService( rockContext );
var workflowType = workflowTypeService.Get( workflowTypeGuid );
if ( workflowType != null )
{
var workflow = Rock.Model.Workflow.Activate( workflowType, workflowName );
List<string> workflowErrors;
var processed = new Rock.Model.WorkflowService( rockContext ).Process( workflow, out workflowErrors );
context.Result = ( processed ? "Processed " : "Did not process " ) + workflow.ToString();
}
}
}
示例6: Execute
/// <summary>
/// Execute method to write transaction to the database.
/// </summary>
public void Execute()
{
if ( Trigger != null )
{
var workflowTypeService = new WorkflowTypeService();
var workflowType = workflowTypeService.Get( Trigger.WorkflowTypeId );
if ( workflowType != null )
{
var workflow = Rock.Model.Workflow.Activate( workflowType, Trigger.WorkflowName );
List<string> workflowErrors;
if ( workflow.Process( Entity, out workflowErrors ) )
{
if ( workflowType.IsPersisted )
{
var workflowService = new Rock.Model.WorkflowService();
workflowService.Add( workflow, PersonId );
workflowService.Save( workflow, PersonId );
}
}
}
}
}
示例7: LaunchTheWorkflow
/// <summary>
/// Launch the workflow
/// </summary>
protected void LaunchTheWorkflow(string workflowName)
{
Guid workflowTypeGuid = Guid.NewGuid();
if ( Guid.TryParse( workflowName, out workflowTypeGuid ) )
{
var workflowTypeService = new WorkflowTypeService();
var workflowType = workflowTypeService.Get( workflowTypeGuid );
if ( workflowType != null )
{
var workflow = Rock.Model.Workflow.Activate( workflowType, workflowName );
List<string> workflowErrors;
if ( workflow.Process( out workflowErrors ) )
{
if ( workflowType.IsPersisted )
{
var workflowService = new Rock.Model.WorkflowService();
workflowService.Add( workflow, CurrentPersonId );
workflowService.Save( workflow, CurrentPersonId );
}
}
}
}
}
示例8: LaunchWorkflow
/// <summary>
/// Launches the workflow.
/// </summary>
/// <param name="workflowTypeGuid">The workflow type unique identifier.</param>
/// <param name="family">The family.</param>
private void LaunchWorkflow( Guid workflowTypeGuid, Group family )
{
int adultRoleId = GroupTypeCache.Read( SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid() ).Roles.Where(r => r.Guid == SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid()).FirstOrDefault().Id;
var headOfHouse = family.Members.Where( m => m.GroupRoleId == adultRoleId ).OrderBy( m => m.Person.Gender ).FirstOrDefault();
// don't launch a workflow if no adult is present in the family
if ( headOfHouse != null && headOfHouse.Person != null && headOfHouse.Person.PrimaryAlias != null ) {
var spouse = family.Members.Where( m => m.GroupRoleId == adultRoleId && m.PersonId != headOfHouse.Person.Id ).FirstOrDefault();
using ( var rockContext = new RockContext() )
{
var workflowTypeService = new WorkflowTypeService( rockContext );
var workflowType = workflowTypeService.Get( workflowTypeGuid );
if ( workflowType != null )
{
var workflowService = new WorkflowService( rockContext );
var workflow = Rock.Model.Workflow.Activate( workflowType, headOfHouse.Person.FullName, rockContext );
workflowService.Add( workflow );
rockContext.SaveChanges();
workflow.SetAttributeValue( "Family", family.Guid );
workflow.SetAttributeValue( "HeadOfHouse", headOfHouse.Person.PrimaryAlias.Guid );
if ( family.Campus != null )
{
workflow.SetAttributeValue( "Campus", family.Campus.Guid );
}
if ( spouse != null && spouse.Person != null && spouse.Person.PrimaryAlias != null )
{
workflow.SetAttributeValue( "Spouse", spouse.Person.PrimaryAlias.Guid );
}
workflow.SaveAttributeValues();
}
}
}
}
示例9: LaunchFileUploadWorkflow
/// <summary>
/// Launches the file upload workflow.
/// </summary>
/// <param name="binaryFile">The binary file.</param>
/// <param name="binaryFileService">The binary file service.</param>
private void LaunchFileUploadWorkflow( BinaryFile binaryFile, BinaryFileService binaryFileService )
{
// Process uploaded file using an optional workflow (which will probably populate attribute values)
Guid workflowTypeGuid = Guid.NewGuid();
if ( Guid.TryParse( GetAttributeValue( "Workflow" ), out workflowTypeGuid ) )
{
try
{
// temporarily set the binaryFile.Id to the uploaded binaryFile.Id so that workflow can do stuff with it
binaryFile.Id = fsFile.BinaryFileId ?? 0;
// create a rockContext for the workflow so that it can save it's changes, without
var workflowRockContext = new RockContext();
var workflowTypeService = new WorkflowTypeService( workflowRockContext );
var workflowType = workflowTypeService.Get( workflowTypeGuid );
if ( workflowType != null )
{
var workflow = Workflow.Activate( workflowType, binaryFile.FileName );
List<string> workflowErrors;
if ( new Rock.Model.WorkflowService( workflowRockContext ).Process( workflow, binaryFile, out workflowErrors ) )
{
binaryFile = binaryFileService.Get( binaryFile.Id );
}
nbWorkflowSuccess.Text = string.Format( "Succesfully processed a <strong>{0}</strong> workflow!", workflowType.Name );
nbWorkflowSuccess.Visible = true;
}
}
finally
{
// set binaryFile.Id to original id again since the UploadedFile is a temporary binaryFile with a different id
binaryFile.Id = hfBinaryFileId.ValueAsInt();
}
}
}
示例10: btnSave_Click
/// <summary>
/// Handles the Click event of the btnSave control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void btnSave_Click( object sender, EventArgs e )
{
ParseControls( true );
var rockContext = new RockContext();
var service = new WorkflowTypeService( rockContext );
WorkflowType workflowType = null;
int? workflowTypeId = hfWorkflowTypeId.Value.AsIntegerOrNull();
if ( workflowTypeId.HasValue )
{
workflowType = service.Get( workflowTypeId.Value );
}
if ( workflowType == null )
{
workflowType = new WorkflowType();
}
var validationErrors = new List<string>();
// check for unique prefix
string prefix = tbNumberPrefix.UntrimmedText;
if ( !string.IsNullOrWhiteSpace( prefix ) &&
prefix.ToUpper() != ( workflowType.WorkflowIdPrefix ?? string.Empty ).ToUpper() )
{
if ( service.Queryable().AsNoTracking()
.Any( w =>
w.Id != workflowType.Id &&
w.WorkflowIdPrefix == prefix ) )
{
validationErrors.Add( "Workflow Number Prefix is already being used by another workflow type. Please use a unique prefix." );
}
else
{
workflowType.WorkflowIdPrefix = prefix;
}
}
else
{
workflowType.WorkflowIdPrefix = prefix;
}
workflowType.IsActive = cbIsActive.Checked;
workflowType.Name = tbName.Text;
workflowType.Description = tbDescription.Text;
workflowType.CategoryId = cpCategory.SelectedValueAsInt();
workflowType.WorkTerm = tbWorkTerm.Text;
workflowType.ModifiedByPersonAliasId = CurrentPersonAliasId;
workflowType.ModifiedDateTime = RockDateTime.Now;
int? mins = tbProcessingInterval.Text.AsIntegerOrNull();
if ( mins.HasValue )
{
workflowType.ProcessingIntervalSeconds = mins.Value * 60;
}
else
{
workflowType.ProcessingIntervalSeconds = null;
}
workflowType.IsPersisted = cbIsPersisted.Checked;
workflowType.LoggingLevel = ddlLoggingLevel.SelectedValueAsEnum<WorkflowLoggingLevel>();
workflowType.IconCssClass = tbIconCssClass.Text;
workflowType.SummaryViewText = ceSummaryViewText.Text;
workflowType.NoActionMessage = ceNoActionMessage.Text;
if ( validationErrors.Any() )
{
nbValidationError.Text = string.Format( "Please Correct the Following<ul><li>{0}</li></ul>",
validationErrors.AsDelimited( "</li><li>" ) );
nbValidationError.Visible = true;
return;
}
if ( !Page.IsValid || !workflowType.IsValid )
{
return;
}
foreach(var activityType in ActivityTypesState)
{
if (!activityType.IsValid)
{
return;
}
foreach(var actionType in activityType.ActionTypes)
{
if ( !actionType.IsValid )
{
return;
}
}
//.........这里部分代码省略.........
示例11: fsFile_FileUploaded
/// <summary>
/// Handles the FileUploaded event of the fsFile control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void fsFile_FileUploaded( object sender, EventArgs e )
{
var rockContext = new RockContext();
var binaryFileService = new BinaryFileService( rockContext );
BinaryFile binaryFile = null;
if ( fsFile.BinaryFileId.HasValue )
{
binaryFile = binaryFileService.Get( fsFile.BinaryFileId.Value );
}
if ( binaryFile != null )
{
if ( !string.IsNullOrWhiteSpace( tbName.Text ) )
{
binaryFile.FileName = tbName.Text;
}
// set binaryFile.Id to original id since the UploadedFile is a temporary binaryFile with a different id
binaryFile.Id = hfBinaryFileId.ValueAsInt();
binaryFile.Description = tbDescription.Text;
binaryFile.BinaryFileTypeId = ddlBinaryFileType.SelectedValueAsInt();
if ( binaryFile.BinaryFileTypeId.HasValue )
{
binaryFile.BinaryFileType = new BinaryFileTypeService( rockContext ).Get( binaryFile.BinaryFileTypeId.Value );
}
var tempList = OrphanedBinaryFileIdList;
tempList.Add( fsFile.BinaryFileId.Value );
OrphanedBinaryFileIdList = tempList;
// load attributes, then get the attribute values from the UI
binaryFile.LoadAttributes();
Rock.Attribute.Helper.GetEditValues( phAttributes, binaryFile );
// Process uploaded file using an optional workflow (which will probably populate attribute values)
Guid workflowTypeGuid = Guid.NewGuid();
if ( Guid.TryParse( GetAttributeValue( "Workflow" ), out workflowTypeGuid ) )
{
try
{
// temporarily set the binaryFile.Id to the uploaded binaryFile.Id so that workflow can do stuff with it
binaryFile.Id = fsFile.BinaryFileId ?? 0;
// create a rockContext for the workflow so that it can save it's changes, without
var workflowRockContext = new RockContext();
var workflowTypeService = new WorkflowTypeService( workflowRockContext );
var workflowType = workflowTypeService.Get( workflowTypeGuid );
if ( workflowType != null )
{
var workflow = Workflow.Activate( workflowType, binaryFile.FileName );
List<string> workflowErrors;
if ( new Rock.Model.WorkflowService( workflowRockContext ).Process( workflow, binaryFile, out workflowErrors ) )
{
binaryFile = binaryFileService.Get( binaryFile.Id );
}
}
}
finally
{
// set binaryFile.Id to original id again since the UploadedFile is a temporary binaryFile with a different id
binaryFile.Id = hfBinaryFileId.ValueAsInt();
}
}
ShowBinaryFileDetail( binaryFile );
}
}
示例12: StartWorkflow
/// <summary>
/// Starts the workflow if one was defined in the block setting.
/// </summary>
/// <param name="prayerRequest">The prayer request.</param>
/// <param name="rockContext">The rock context.</param>
private void StartWorkflow( PrayerRequest prayerRequest, RockContext rockContext )
{
WorkflowType workflowType = null;
Guid? workflowTypeGuid = GetAttributeValue( "Workflow" ).AsGuidOrNull();
if ( workflowTypeGuid.HasValue )
{
var workflowTypeService = new WorkflowTypeService( rockContext );
workflowType = workflowTypeService.Get( workflowTypeGuid.Value );
if ( workflowType != null )
{
try
{
var workflow = Workflow.Activate( workflowType, prayerRequest.Name );
List<string> workflowErrors;
new WorkflowService( rockContext ).Process( workflow, prayerRequest, out workflowErrors );
}
catch ( Exception ex )
{
ExceptionLogService.LogException( ex, this.Context );
}
}
}
}
示例13: EditControl
/// <summary>
/// Creates the control(s) necessary for prompting user for a new value
/// </summary>
/// <param name="configurationValues">The configuration values.</param>
/// <param name="id"></param>
/// <returns>
/// The control
/// </returns>
public override Control EditControl( Dictionary<string, ConfigurationValue> configurationValues, string id )
{
ListControl editControl;
editControl = new Rock.Web.UI.Controls.RockDropDownList { ID = id };
editControl.Items.Add( new ListItem() );
IEnumerable<WorkflowActivityType> activityTypes = null;
Guid? workflowTypeGuid = configurationValues != null && configurationValues.ContainsKey( WORKFLOW_TYPE_KEY ) ? configurationValues[WORKFLOW_TYPE_KEY].Value.AsGuidOrNull() : null;
WorkflowType workflowType = null;
if ( workflowTypeGuid.HasValue )
{
var workflowTypeService = new WorkflowTypeService( new RockContext() );
workflowType = workflowTypeService.Get( workflowTypeGuid.Value );
}
if ( workflowType == null )
{
workflowType = GetContextWorkflowType();
}
if ( workflowType != null )
{
activityTypes = workflowType.ActivityTypes;
if ( activityTypes != null && activityTypes.Any() )
{
foreach ( var activityType in activityTypes.OrderBy( a => a.Order ) )
{
editControl.Items.Add( new ListItem( activityType.Name ?? "[New Activity]", activityType.Guid.ToString().ToUpper() ) );
}
}
return editControl;
}
return null;
}
示例14: OnLoad
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if ( !Page.IsPostBack )
{
if ( Person != null && Person.Id != 0 )
{
if ( Person.NickName == Person.FirstName )
{
lName.Text = Person.FullName.FormatAsHtmlTitle();
}
else
{
lName.Text = String.Format( "{0} {2} <span class='full-name'>({1})</span>", Person.NickName.FormatAsHtmlTitle(), Person.FirstName, Person.LastName );
}
// Setup Image
string imgTag = Rock.Model.Person.GetPhotoImageTag( Person.PhotoId, Person.Age, Person.Gender, 200, 200 );
if ( Person.PhotoId.HasValue )
{
lImage.Text = string.Format("<a href='{0}'>{1}</a>", Person.PhotoUrl, imgTag);
}
else
{
lImage.Text = imgTag;
}
SetFollowing();
var socialCategoryGuid = Rock.SystemGuid.Category.PERSON_ATTRIBUTES_SOCIAL.AsGuid();
if ( !socialCategoryGuid.IsEmpty() )
{
var attributes = Person.Attributes.Where( p => p.Value.Categories.Select( c => c.Guid ).Contains( socialCategoryGuid ) );
var result = attributes.Join( Person.AttributeValues, a => a.Key, v => v.Key, ( a, v ) => new { Attribute = a.Value, Value = v.Value } );
rptSocial.DataSource = result
.Where( r =>
r.Value != null &&
r.Value.Value != string.Empty )
.OrderBy( r => r.Attribute.Order )
.Select( r => new
{
url = r.Value.Value,
name = r.Attribute.Name,
icon = r.Attribute.IconCssClass
} )
.ToList();
rptSocial.DataBind();
}
if ( Person.BirthDate.HasValue )
{
string ageText = ( Person.BirthYear.HasValue && Person.BirthYear != DateTime.MinValue.Year ) ?
string.Format( "{0} yrs old ", Person.BirthDate.Value.Age() ) : string.Empty;
lAge.Text = string.Format( "{0}<small>({1})</small><br/>", ageText, Person.BirthDate.Value.ToMonthDayString() );
}
lGender.Text = Person.Gender.ToString();
if ( Person.GraduationYear.HasValue && Person.HasGraduated.HasValue )
{
lGraduation.Text = string.Format( "<small>({0} {1})</small>",
Person.HasGraduated.Value ? "Graduated " : "Graduates ",
Person.GraduationYear.Value );
string grade = Person.GradeFormatted;
if ( grade != string.Empty )
{
lGrade.Text = string.Format( "{0}", grade );
}
}
lMaritalStatus.Text = Person.MaritalStatusValueId.DefinedValue();
if ( Person.AnniversaryDate.HasValue )
lAnniversary.Text = string.Format( "{0} yrs <small>({1})</small>", Person.AnniversaryDate.Value.Age(), Person.AnniversaryDate.Value.ToMonthDayString() );
if ( Person.PhoneNumbers != null )
{
rptPhones.DataSource = Person.PhoneNumbers.ToList();
rptPhones.DataBind();
}
lEmail.Text = Person.GetEmailTag( ResolveRockUrl( "/" ) );
taglPersonTags.EntityTypeId = Person.TypeId;
taglPersonTags.EntityGuid = Person.Guid;
taglPersonTags.GetTagValues( CurrentPersonId );
StringBuilder sbActions = new StringBuilder();
var workflowActions = GetAttributeValue( "WorkflowActions" );
if ( !string.IsNullOrWhiteSpace( workflowActions ) )
{
using ( var rockContext = new RockContext() )
{
var workflowTypeService = new WorkflowTypeService( rockContext );
foreach ( string guidValue in workflowActions.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) )
{
Guid? guid = guidValue.AsGuidOrNull();
if ( guid.HasValue )
//.........这里部分代码省略.........
示例15: Execute
/// <summary>
/// Executes the specified context.
/// </summary>
/// <param name="context">The context.</param>
public void Execute( IJobExecutionContext context )
{
var rockContext = new RockContext();
JobDataMap dataMap = context.JobDetail.JobDataMap;
// Get the details for the email that we'll be sending out.
Guid? systemEmailGuid = dataMap.GetString( "ExpiringCreditCardEmail" ).AsGuidOrNull();
SystemEmailService emailService = new SystemEmailService( rockContext );
SystemEmail systemEmail = null;
if ( systemEmailGuid.HasValue )
{
systemEmail = emailService.Get( systemEmailGuid.Value );
}
// Fetch the configured Workflow once if one was set, we'll use it later.
Guid? workflowGuid = dataMap.GetString( "Workflow" ).AsGuidOrNull();
WorkflowType workflowType = null;
var workflowTypeService = new WorkflowTypeService( rockContext );
var workflowService = new WorkflowService( rockContext );
if ( workflowGuid != null )
{
workflowType = workflowTypeService.Get( workflowGuid.Value );
}
var qry = new FinancialScheduledTransactionService( rockContext )
.Queryable( "ScheduledTransactionDetails,FinancialPaymentDetail.CurrencyTypeValue,FinancialPaymentDetail.CreditCardTypeValue" )
.Where( t => t.IsActive && t.FinancialPaymentDetail.ExpirationMonthEncrypted != null
&& ( t.EndDate == null || t.EndDate > DateTime.Now ) )
.AsNoTracking();
var appRoot = Rock.Web.Cache.GlobalAttributesCache.Read( rockContext ).GetValue( "PublicApplicationRoot" );
// Get the current month and year
DateTime now = DateTime.Now;
int month = now.Month;
int year = now.Year;
int counter = 0;
foreach ( var transaction in qry )
{
int expirationMonthDecrypted = Int32.Parse( Encryption.DecryptString( transaction.FinancialPaymentDetail.ExpirationMonthEncrypted ) );
int expirationYearDecrypted = Int32.Parse( Encryption.DecryptString( transaction.FinancialPaymentDetail.ExpirationYearEncrypted ) );
string acctNum = transaction.FinancialPaymentDetail.AccountNumberMasked.Substring( transaction.FinancialPaymentDetail.AccountNumberMasked.Length - 4 );
int warningYear = expirationYearDecrypted;
int warningMonth = expirationMonthDecrypted - 1;
if ( warningMonth == 0 )
{
warningYear -= 1;
warningMonth = 12;
}
string warningDate = warningMonth.ToString() + warningYear.ToString();
string currentMonthString = month.ToString() + year.ToString();
if ( warningDate == currentMonthString )
{
// as per ISO7813 https://en.wikipedia.org/wiki/ISO/IEC_7813
var expirationDate = string.Format( "{0:D2}/{1:D2}", expirationMonthDecrypted, expirationYearDecrypted );
var recipients = new List<RecipientData>();
var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields( null );
var person = transaction.AuthorizedPersonAlias.Person;
mergeFields.Add( "Person", person );
mergeFields.Add( "Card", acctNum );
mergeFields.Add( "Expiring", expirationDate );
recipients.Add( new RecipientData( person.Email, mergeFields ) );
Email.Send( systemEmail.Guid, recipients, appRoot );
// Start workflow for this person
if ( workflowType != null )
{
Dictionary<string, string> attributes = new Dictionary<string, string>();
attributes.Add( "Person", transaction.AuthorizedPersonAlias.Guid.ToString() );
attributes.Add( "Card", acctNum );
attributes.Add( "Expiring", expirationDate );
StartWorkflow( workflowService, workflowType, attributes, string.Format( "{0} (scheduled transaction Id: {1})", person.FullName, transaction.Id ) );
}
counter++;
}
}
context.Result = string.Format( "{0} scheduled credit card transactions were examined with {1} notice(s) sent.", qry.Count(), counter );
}