/// <summary> /// Executes the specified item. /// </summary> /// <param name="item">The target item.</param> /// <param name="oldItem">The old item.</param> public override void Execute(IEditableRoot item, IEditableRoot oldItem) { if (item == null) throw new ArgumentNullException("item"); var approval = item.ReadValueByPropertyName<IApprovalEdit>(ApprovalFieldName); if (approval == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Approval field \"{0}\" not found in item \"{1}\" or you don't have access. Action will not run.", ApprovalFieldName, item.GetType()), "item"); var membersFound = new HashSet<int>(); foreach (var member in approval.MemberResults.Where(am => am.ApprovalLevel == approval.CurrentLevel)) { if (member.GetApprovalMemberResult() != ApprovalMemberResults.Undecided) continue; if (!member.Person.HasValue || !member.OriginalApprover.HasValue || membersFound.Contains(member.OriginalApprover.Value)) continue; membersFound.Add(member.OriginalApprover.Value); var person = PersonManager.GetPerson(member.Person.Value); if (person == null) continue; var basePersonId = member.OriginalApprover.Value; var actionItem = DynamicTypeManager.NewActionItem(); actionItem.ActionGuid = Guid.ToString(); actionItem.Process = item.ProcessName; actionItem.PersonId = person.Id; actionItem.BasePersonId = basePersonId; actionItem.ItemId = item.Id; actionItem.IsActionNew = true; var supportStates = item as ISupportStates; if (supportStates != null) actionItem.ItemStateId = supportStates.CurrentState; actionItem.Save(); CommunicationService.NotifyActionsChanged(person.Id); if (SendEmail && !string.IsNullOrWhiteSpace(person.Email)) { SendMessage(item, person); } } if (SendEmail && !string.IsNullOrWhiteSpace(EmailFieldName)) { var email = item.ReadValueByPropertyName<string>(EmailFieldName); if (!string.IsNullOrWhiteSpace(email)) { SendMessage(item, email); } } base.Execute(item, oldItem); }
/// <summary> /// Executes the specified item. /// </summary> /// <param name="item">The source item.</param> /// <param name="oldItem">The old item.</param> public override void Execute(IEditableRoot item, IEditableRoot oldItem) { if (item == null) throw new ArgumentNullException("item"); foreach (var originalAssignee in DataContext.GetNewAssignees(item).DistinctBy(p => p.Id)) { var assignee = originalAssignee; if (originalAssignee.OutOfOffice == true && originalAssignee.DelegateApproverId != null) { assignee = PersonManager.GetFirstActivePerson(originalAssignee.Id) ?? originalAssignee; } var actionItem = DynamicTypeManager.NewActionItem(); actionItem.ActionGuid = Guid.ToString(); actionItem.Process = item.ProcessName; actionItem.PersonId = assignee.Id; actionItem.BasePersonId = originalAssignee.Id; actionItem.ItemId = item.Id; actionItem.IsActionNew = true; var states = item as ISupportStates; if (states != null) { actionItem.ItemStateId = states.CurrentState; } actionItem.Save(); CommunicationService.NotifyActionsChanged(assignee.Id); if (SendEmail && !string.IsNullOrWhiteSpace(assignee.Email)) { SendMessage(item, assignee); } } if (SendEmail && !string.IsNullOrWhiteSpace(EmailFieldName)) { var email = item.ReadValueByPropertyName<string>(EmailFieldName); if (!string.IsNullOrWhiteSpace(email)) { SendMessage(item, email); } } base.Execute(item, oldItem); }