Ejemplo n.º 1
0
        public bool Update(Entity entity, bool ignorePermissions = false)
        {
            var entityMetadata     = GetEntityMetaData(entity.Name);
            var attributeMetadatas = _attributeFinder.FindByEntityId(entityMetadata.EntityId);

            VerifyUpdate(entity, entityMetadata, attributeMetadatas);
            var query = new QueryExpression(entity.Name, _languageId);

            query.ColumnSet.AllColumns = true;
            query.Criteria.AddCondition(entity.IdName, ConditionOperator.Equal, entity.GetIdValue());
            var originalEntity = _organizationDataRetriever.Retrieve(query, ignorePermissions);

            if (!ignorePermissions)
            {
                VerifyEntityPermission(originalEntity, AccessRightValue.Update, entityMetadata);
            }
            var  ownerObj     = entityMetadata.EntityMask == EntityMaskEnum.User && entity.ContainsKey("ownerid") ? (OwnerObject)entity["ownerid"] : null;
            bool ownerChanged = ownerObj != null && !ownerObj.OwnerId.Equals(originalEntity.GetGuidValue("ownerid"));//是否改变了所有者

            if (ownerChanged)
            {
                entity.RemoveKeys("ownerid");
            }
            var result = true;

            //保存前发布事件
            PublishEvents(originalEntity, entity, OperationStage.PreOperation, entityMetadata, attributeMetadatas);
            try
            {
                _organizationDataProvider.BeginTransaction();
                InternalOnUpdate(originalEntity, entity, OperationStage.PreOperation, entityMetadata, attributeMetadatas);
                result = _organizationDataProvider.Update(entity);
                if (result)
                {
                    _mapUpdater.Update(entityMetadata, originalEntity);
                    _formulaUpdater.Update(entityMetadata, originalEntity);
                    if (ownerChanged)//改变了所有者
                    {
                        _dataAssigner.Assign(entityMetadata, entity, ownerObj);
                    }
                    _organizationDataProvider.CommitTransaction();
                    InternalOnUpdate(originalEntity, entity, OperationStage.PostOperation, entityMetadata, attributeMetadatas);
                }
                else
                {
                    _organizationDataProvider.RollBackTransaction();
                }
            }
            catch (Exception e)
            {
                _organizationDataProvider.RollBackTransaction();
                OnException(e);
            }
            if (result)
            {
                //保存成功后发布事件
                PublishEvents(originalEntity, entity, OperationStage.PostOperation, entityMetadata, attributeMetadatas);
            }
            return(result);
        }
Ejemplo n.º 2
0
 public IActionResult Post([FromBody] AssignedModel model)
 {
     if (model == null || !Arguments.HasValue(model.ObjectId))
     {
         return(NotSpecifiedRecord());
     }
     foreach (var item in model.ObjectId)
     {
         OwnerObject owner = null;
         if (model.OwnerIdType == 1) //assign to me
         {
             owner = new OwnerObject(OwnerTypes.SystemUser, CurrentUser.SystemUserId);
         }
         else if (model.OwnerIdType == 2)
         {
             owner = new OwnerObject(OwnerTypes.SystemUser, model.OwnerId);
         }
         else if (model.OwnerIdType == 3)
         {
             owner = new OwnerObject(OwnerTypes.Team, model.OwnerId);
         }
         _dataAssigner.Assign(model.EntityId, item, owner);
     }
     return(JOk(T["assign_success"]));
 }
Ejemplo n.º 3
0
        public void HandleEvent(EntityUpdatedEvent eventMessage)
        {
            var  ownerObj     = eventMessage.EntityMetadata.EntityMask == EntityMaskEnum.User && eventMessage.Updated.ContainsKey("ownerid") ? (OwnerObject)eventMessage.Updated["ownerid"] : null;
            bool ownerChanged = ownerObj != null && !ownerObj.OwnerId.Equals(eventMessage.Origin.GetGuidValue("ownerid")); //是否改变了所有者

            if (ownerChanged)                                                                                              //改变了所有者
            {
                _dataAssigner.Assign(eventMessage.EntityMetadata, eventMessage.Updated, ownerObj);
            }
        }
Ejemplo n.º 4
0
 public IActionResult Assigned(AssignModel model)
 {
     foreach (var item in model.ObjectId)
     {
         OwnerObject owner = null;
         if (model.OwnerIdType == 1) //assign to me
         {
             owner = new OwnerObject(OwnerTypes.SystemUser, CurrentUser.SystemUserId);
         }
         else if (model.OwnerIdType == 2)
         {
             owner = new OwnerObject(OwnerTypes.SystemUser, model.OwnerId);
         }
         else if (model.OwnerIdType == 3)
         {
             owner = new OwnerObject(OwnerTypes.Team, model.OwnerId);
         }
         _dataAssigner.Assign(model.EntityId, item, owner);
     }
     return(JOk(T["assign_success"]));
 }
Ejemplo n.º 5
0
        public Guid Create(Entity entity, bool ignorePermissions = false)
        {
            var entityMetadata     = GetEntityMetaData(entity.Name);
            var attributeMetadatas = _attributeFinder.FindByEntityId(entityMetadata.EntityId);

            VerifyCreate(entity, entityMetadata, attributeMetadatas, ignorePermissions);
            Guid id = Guid.Empty;

            try
            {
                _organizationDataProvider.BeginTransaction();
                InternalOnCreate(entity, OperationStage.PreOperation, entityMetadata, attributeMetadatas);
                id = _organizationDataProvider.Create(entity);
                if (entityMetadata.EntityMask == EntityMaskEnum.User)
                {
                    var owner = entity["ownerid"] as OwnerObject;
                    //assign to other
                    if (!owner.OwnerId.Equals(this._user.SystemUserId))
                    {
                        _dataAssigner.Assign(entityMetadata.EntityId, id, owner);
                    }
                }
                if (!id.Equals(Guid.Empty))
                {
                    var existsData = entity.UnWrapAttributeValue();
                    _mapUpdater.Update(entityMetadata, existsData);
                    //字段表达式计算
                    _formulaUpdater.Update(entityMetadata, existsData);
                }
                _organizationDataProvider.CommitTransaction();
                InternalOnCreate(entity, OperationStage.PostOperation, entityMetadata, attributeMetadatas);
            }
            catch (Exception e)
            {
                _organizationDataProvider.RollBackTransaction();
                id = Guid.Empty;
                OnException(new XmsException(e));
            }
            return(id);
        }