Ejemplo n.º 1
0
        public bool Evaluate(UserConnection userConnection, AdElement element, Entity relatedEntity, Entity handler)
        {
            _logger.Info("Добавляем средство связи " + handler.GetTypedColumnValue <string>("NavAdAttributeName"));

            string adValue = AdAttributesHelper.GetAdValue(element, (NavAdAttributesHandlers)handler);

            var  contact             = (Contact)relatedEntity;
            Guid communicationTypeId = GetCommunicationType(userConnection, handler.GetTypedColumnValue <string>("NavAdAttributeName"));

            ContactCommunication[] contactCommunications = GetContactCommunications(userConnection, contact, communicationTypeId);

            if (adValue != null)
            {
                char[] separator           = Core.Configuration.SysSettings.GetValue(userConnection.AppConnection.SystemUserConnection, "ContactCommunicationSeparator").ToString().ToArray();
                var    communicationValues = adValue.Split(separator).Select(s => s.Trim()).ToList();

                // обрабатываем уже существующие в bpm средства связи
                foreach (var cm in contactCommunications)
                {
                    if (!communicationValues.Contains(cm.Number))
                    {
                        cm.Delete();
                    }
                    else
                    {
                        communicationValues.Remove(cm.Number);
                    }
                }

                // создаем отсутствующие записи
                foreach (var cv in communicationValues)
                {
                    var contactCommunication = new ContactCommunication(userConnection);
                    contactCommunication.UseAdminRights = false;

                    contactCommunication.SetDefColumnValues();
                    contactCommunication.ContactId               = contact.Id;
                    contactCommunication.CommunicationTypeId     = communicationTypeId;
                    contactCommunication.NavSynchronizedWithLDAP = true;

                    contactCommunication.Number = cv;
                    contactCommunication.Save(false);
                }
            }
            else
            {
                foreach (var cm in contactCommunications)
                {
                    cm.Delete();
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public bool Evaluate(UserConnection userConnection, AdElement element, Entity relatedEntity, Entity handler)
        {
            string adValue = AdAttributesHelper.GetAdValue(element, (NavAdAttributesHandlers)handler);

            if (adValue != null)
            {
                // получаем данные о справочнике, на который смотрит колонка в основном объекте
                var NavEntityFieldName = handler.GetTypedColumnValue <string>("NavEntityFieldName");
                if (NavEntityFieldName.IsEmpty())
                {
                    throw new Exception("Не заполнено поле NavEntityFieldName");
                }

                var    lookupColumn = relatedEntity.Schema.Columns.GetByName(NavEntityFieldName);
                var    entitySchema = lookupColumn.ReferenceSchema;
                string schemaName   = entitySchema.Name;

                var searchColumn = AdAttributesHelper.GetXmlElement("searchcolumn", handler.GetTypedColumnValue <string>("NavHandlerParameterXML"));
                if (searchColumn.IsEmpty())
                {
                    searchColumn = entitySchema.GetPrimaryDisplayColumnName();
                }

                Entity lookupValue = AdAttributesHelper.GetLookupValue(userConnection, adValue, schemaName, searchColumn);
                if (lookupValue == null)
                {
                    lookupValue = AdAttributesHelper.CreateLookupValue(userConnection, adValue, schemaName, searchColumn);
                }

                // Если атрибут существует в AD и у него есть значение
                _logger.Info("Записываем в поле " + relatedEntity.Schema.Caption + "." + handler.GetTypedColumnValue <string>("NavEntityFieldName") + " = \"" + lookupValue.PrimaryDisplayColumnValue + "\"(" + lookupValue.PrimaryColumnValue + ")");
                relatedEntity.SetColumnValue(handler.GetTypedColumnValue <string>("NavEntityFieldName") + "Id", lookupValue.PrimaryColumnValue);
            }
            else
            {
                // Если атрибут отсутствует в AD, удаляем соотвутствующие данные из системы
                _logger.Info("Очищаем поле (отсутствует в AD) " + relatedEntity.Schema.Caption + "." + handler.GetTypedColumnValue <string>("NavEntityFieldName"));
                relatedEntity.SetColumnValue(handler.GetTypedColumnValue <string>("NavEntityFieldName") + "Id", null);
            }
            _logger.Info("Сохраняем запись");
            relatedEntity.Save(false);
            return(true);
        }