Esempio n. 1
0
        /// <summary>
        /// Determines whether this instance can execute the specified item.
        /// </summary>
        /// <param name="item">The target item.</param>
        /// <param name="oldItem">The old item.</param>
        /// <returns><c>true</c> if this instance can execute the specified item; otherwise, <c>false</c>.</returns>
        public override bool CanExecute(IDynamicObject item, IDynamicObject oldItem)
        {
            if (item == null)
                return false;

            if (string.IsNullOrWhiteSpace(ApprovalFieldName))
                return false;

            var prop = item.GetPropertyByName(ApprovalFieldName);

            if (prop == null)
                return false;

            var approval = item.ReadValueByPropertyName<IApprovalEdit>(ApprovalFieldName);

            if (approval == null)
                return false;

            var oldApproval = oldItem != null
                                  ? oldItem.ReadValueByPropertyName<IApprovalEdit>(ApprovalFieldName)
                                  : null;

            return approval.GetApprovalState() == ApprovalStates.ReadyForApproval
                   && (oldApproval == null
                       || (approval.CurrentLevel != oldApproval.CurrentLevel || approval.GetApprovalState() != oldApproval.GetApprovalState()));
        }
        /// <summary>
        /// Removes the old action items.
        /// </summary>
        /// <param name="item">The target item.</param>
        /// <param name="oldItem">The old item.</param>
        public override void RemoveOldActionItems(IDynamicObject item, IDynamicObject 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 oldApproval = oldItem != null
                                  ? oldItem.ReadValueByPropertyName<IApprovalEdit>(ApprovalFieldName)
                                  : null;

            var readyForApproval = approval.GetApprovalState() == ApprovalStates.ReadyForApproval;
            var approvalLevelChanged = oldApproval == null || approval.CurrentLevel != oldApproval.CurrentLevel;

            Collection<int> actionIds;

            if (!readyForApproval || approvalLevelChanged)
            {
                actionIds = DataContext.GetAllActionItems(item);
            }
            else
            {
                actionIds = DataContext.GetInvalidActionItems(item);
            }

            if (actionIds.Count == 0)
                return;

            var affectedPersonIds = new HashSet<int>();

            foreach (var id in actionIds)
            {
                var action = DynamicTypeManager.GetActionItem(id);
                if (action == null || action.Id != id)
                    continue;

                var personId = action.PersonId;
                action.Delete();
                action.Save();

                if (personId.HasValue)
                {
                    affectedPersonIds.Add(personId.Value);
                }
            }

            foreach (var personId in affectedPersonIds)
            {
                CommunicationService.NotifyActionsChanged(personId);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Determines whether [is person field match] [the specified item].
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="sc">The sc.</param>
        /// <param name="personIds">The person ids.</param>
        /// <returns><c>true</c> if [is person field match] [the specified item]; otherwise, <c>false</c>.</returns>
        private static bool IsPersonFieldMatch(IDynamicObject item, IStateConnectorSecurityConfiguration sc, IDictionary<string, int> personIds)
        {
            if (string.IsNullOrEmpty(sc.PersonFieldName) || sc.PersonFieldName == Constants.AllPersonFieldsSystemName)
                return false;

            var prop = item.GetPropertyByName(sc.PersonFieldName);

            if (prop == null)
                return false;

            var crAttr =
                (CrossRefFieldAttribute)
                prop.GetCustomAttributes(typeof(CrossRefFieldAttribute), false).FirstOrDefault();

            if (crAttr == null)
                return false;

            int personId;

            if (!personIds.TryGetValue(crAttr.ReferenceTableName, out personId))
                return false;

            if (crAttr.AllowMultiple)
            {
                var list = item.ReadValueByPropertyName<IList>(prop.Name);

                if (list == null)
                    return false;

                return list.Cast<ICrossRefItemInfo>().Any(x => x.Id == personId);
            }

            var value = item.ReadValueByPropertyName<int?>(prop.Name);

            return value == personId;
        }