private static XmlPropertyChangeAction ToXmlModel(IePropertyChangeAction ieAction, WorkflowDataMaps dataMaps) { if (ieAction == null) { return(null); } var xmlAction = new XmlPropertyChangeAction { Name = ieAction.Name, PropertyValue = ieAction.PropertyValue, UsersGroups = ToXmlModel(ieAction.UsersGroups, dataMaps) }; int propertyTypeId; if (!dataMaps.PropertyTypeMap.TryGetValue(ieAction.PropertyName, out propertyTypeId) && !WorkflowHelper.TryGetNameOrDescriptionPropertyTypeId(ieAction.PropertyName, out propertyTypeId)) { throw new ExceptionWithErrorCode(I18NHelper.FormatInvariant("Id of Standard Property Type '{0}' is not found.", ieAction.PropertyName), ErrorCodes.UnexpectedError); } xmlAction.PropertyTypeId = propertyTypeId; ToXmlModel(ieAction.ValidValues, propertyTypeId, ieAction.PropertyName, dataMaps, xmlAction); return(xmlAction); }
private PropertyChangeAction ToPropertyChangeAction(XmlPropertyChangeAction propertyChangeAction, int currentUserId) { if (propertyChangeAction.UsersGroups != null) { return(ToPropertyChangeUserGroupAction(propertyChangeAction, currentUserId)); } else { var action = new PropertyChangeAction { InstancePropertyTypeId = propertyChangeAction.PropertyTypeId, PropertyValue = propertyChangeAction.PropertyValue, }; if (propertyChangeAction.ValidValues.Any()) { action.ValidValues.AddRange(propertyChangeAction.ValidValues); } return(action); } }
private PropertyChangeAction ToPropertyChangeUserGroupAction( XmlPropertyChangeAction propertyChangeAction, int currentUserId) { var action = new PropertyChangeUserGroupsAction { InstancePropertyTypeId = propertyChangeAction.PropertyTypeId, PropertyValue = propertyChangeAction.PropertyValue }; if (propertyChangeAction.UsersGroups.UsersGroups?.Any() ?? false) { action.UserGroups.AddRange(propertyChangeAction.UsersGroups.UsersGroups.Select( u => new UserGroup { Id = u.Id, IsGroup = u.IsGroup }).ToList()); } var includeCurrentUser = propertyChangeAction.UsersGroups.IncludeCurrentUser.GetValueOrDefault(false); if (!includeCurrentUser) { return(action); } var isUserAlreadyIncluded = action.UserGroups.Exists( u => !u.IsGroup.GetValueOrDefault(false) && u.Id.GetValueOrDefault(0) == currentUserId); if (!isUserAlreadyIncluded) { action.UserGroups.Add(new UserGroup() { Id = currentUserId, IsGroup = false }); } return(action); }
private static void ToXmlModel(List <IeValidValue> validValues, int propertyTypeId, string propertyName, WorkflowDataMaps dataMaps, XmlPropertyChangeAction xmlAction) { if (validValues == null || !validValues.Any()) { return; } IDictionary <int, string> validValuesById = null; IDictionary <string, int> validValuesByValue = null; validValues.ForEach(validValue => { int validValueId; if (validValue.Id.HasValue) { if (validValuesById == null) { if (!dataMaps.ValidValuesById.TryGetValue(propertyTypeId, out validValuesById)) { throw new ExceptionWithErrorCode( I18NHelper.FormatInvariant( "Valid Values of Choice Standard Property Type '{0}' are not found.", propertyName), ErrorCodes.UnexpectedError); } } if (!validValuesById.ContainsKey(validValue.Id.Value)) { throw new ExceptionWithErrorCode( I18NHelper.FormatInvariant( "Valid Value with id '{0}' of Choice Standard Property Type '{1}' is not found.", validValue.Id.Value, propertyName), ErrorCodes.UnexpectedError); } validValueId = validValue.Id.Value; } else { if (validValuesByValue == null) { if (!dataMaps.ValidValuesByValue.TryGetValue(propertyTypeId, out validValuesByValue)) { throw new ExceptionWithErrorCode( I18NHelper.FormatInvariant( "Valid Values of Choice Standard Property Type '{0}' are not found.", propertyName), ErrorCodes.UnexpectedError); } } if (!validValuesByValue.TryGetValue(validValue.Value, out validValueId)) { throw new ExceptionWithErrorCode( I18NHelper.FormatInvariant( "Valid Value '{0}' of Choice Standard Property Type '{1}' is not found.", validValue.Value, propertyName), ErrorCodes.UnexpectedError); } } (xmlAction.ValidValues ?? (xmlAction.ValidValues = new List <int>())).Add(validValueId); }); }