Esempio 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);
        }
Esempio n. 2
0
 public bool Share(Guid entityId, Guid recordId, List <PrincipalObjectAccess> principals, bool ignorePermissions = false)
 {
     try
     {
         var entityMetadata = _entityFinder.FindById(entityId);
         var query          = new QueryExpression(entityMetadata.Name, _languageId);
         query.ColumnSet.AllColumns = true;
         query.Criteria.AddCondition(entityMetadata.Name + "id", ConditionOperator.Equal, recordId);
         var entity = _dataFinder.Retrieve(query);
         if (!ignorePermissions)
         {
             VerifyEntityPermission(entity, AccessRightValue.Share, entityMetadata);
         }
         var attributeMetadatas = _attributeFinder.FindByEntityId(entityMetadata.EntityId);
         _organizationDataProvider.BeginTransaction();
         InternalOnShare(entity, OperationStage.PreOperation, entityMetadata, attributeMetadatas);
         _principalObjectAccessService.DeleteByObjectId(entityId, recordId);
         if (principals.NotEmpty())
         {
             foreach (var item in principals)
             {
                 item.PrincipalObjectAccessId = Guid.NewGuid();
             }
             _principalObjectAccessService.CreateMany(principals);
         }
         _organizationDataProvider.CommitTransaction();
         InternalOnShare(entity, OperationStage.PostOperation, entityMetadata, attributeMetadatas);
         return(true);
     }
     catch (Exception e)
     {
         _organizationDataProvider.RollBackTransaction();
         return(OnException(e));
     }
 }
Esempio n. 3
0
        public Guid Create(AggregateRoot aggregateRoot, Guid?systemFormId = null, bool ignorePermissions = false)
        {
            AggregateRootMetaData aggRootMetaData = GetAggregateRootMetaData(aggregateRoot, systemFormId);
            var thisId = Guid.Empty;

            try
            {
                _organizationDataProvider.BeginTransaction();
                InternalOnCreate(aggregateRoot, OperationStage.PreOperation, aggRootMetaData);

                //关联Id
                thisId = Guid.NewGuid();

                foreach (var c in aggregateRoot.ChildEntities)
                {
                    string name = c.Name, relationshipname = c.Relationshipname, refname = string.Empty;
                    if (relationshipname.IsNotEmpty())
                    {
                        var relationShipMetas = _relationShipFinder.FindByName(c.Relationshipname);
                        if (null != relationShipMetas && relationShipMetas.ReferencedEntityId == c.Entityid)
                        {
                            refname = relationShipMetas.ReferencingAttributeName;
                        }
                        if (refname.IsNotEmpty())
                        {
                            c.Entity.SetAttributeValue(refname, new EntityReference(aggregateRoot.MainEntity.Name, thisId));
                        }
                    }
                }

                var childEntities = aggregateRoot.ChildEntities.Select(x => x.Entity).ToList();
                var entityNames   = childEntities.Select(n => n.Name).Distinct().ToList();
                foreach (var item in entityNames)
                {
                    var items           = childEntities.Where(n => n.Name.IsCaseInsensitiveEqual(item)).ToList();
                    var creatingRecords = items.Where(n => n.Name.IsCaseInsensitiveEqual(item) && n.GetIdValue().Equals(Guid.Empty)).ToList();
                    if (creatingRecords.NotEmpty())
                    {
                        _dataCreater.CreateMany(creatingRecords);
                    }
                }
                aggregateRoot.MainEntity.SetIdValue(thisId);
                _dataCreater.Create(aggregateRoot.MainEntity);

                InternalOnCreate(aggregateRoot, OperationStage.PostOperation, aggRootMetaData);

                _organizationDataProvider.CommitTransaction();
            }
            catch (Exception e)
            {
                _organizationDataProvider.RollBackTransaction();
                OnException(e);
            }
            return(thisId);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        private Guid CreateFromMap_Copy(EntityMap entityMap, Guid sourceRecordId)
        {
            var headTargetEntityMeta = _entityFinder.FindById(entityMap.TargetEntityId);
            var headTargetAttributes = _attributeFinder.FindByEntityId(entityMap.TargetEntityId);
            //引用源实体的字段
            var headRelationShipMeta = _relationShipFinder.FindByName(entityMap.RelationShipName);
            var refAttr = headTargetAttributes.Find(n => n.AttributeId == headRelationShipMeta.ReferencingAttributeId);

            if (entityMap.MapType == MapType.CopyOne)
            {
                //查询是否已生成记录
                QueryExpression query_target = new QueryExpression(headTargetEntityMeta.Name, _languageId);
                query_target.ColumnSet.AddColumn(headTargetAttributes.Find(n => n.TypeIsPrimaryKey()).Name);
                query_target.Criteria.AddCondition(refAttr.Name, ConditionOperator.Equal, sourceRecordId);
                var existsRecord = _dataFinder.Retrieve(query_target);
                if (existsRecord.NotEmpty())
                {
                    OnException(_loc["entitymap_copyone_error"]);
                    return(Guid.Empty);
                }
            }
            Guid newId = Guid.Empty;
            //源记录
            var sourceRecord = _dataFinder.RetrieveById(entityMap.SourceEnttiyName, sourceRecordId);

            if (sourceRecord.IsEmpty())
            {
                OnException(_loc["notfound_record"]);
                return(Guid.Empty);
            }
            //单据头
            var attributeMaps = _attributeMapFinder.Query(n => n.Where(f => f.EntityMapId == entityMap.EntityMapId));

            if (attributeMaps.IsEmpty())
            {
                OnException(_loc["entitymap_emptyheadattributemap"]);
                return(Guid.Empty);
            }
            //单据体
            var childEntityMap = _entityMapFinder.FindByParentId(entityMap.EntityMapId);
            //单据头字段元数据
            var headSourceAttributes = _attributeFinder.FindByEntityId(entityMap.SourceEntityId);
            //新增单据头信息
            Entity headEntity = new Entity(entityMap.TargetEnttiyName);

            foreach (var attrMap in attributeMaps)
            {
                if (!headSourceAttributes.Exists(n => n.AttributeId == attrMap.SourceAttributeId) || !headTargetAttributes.Exists(n => n.AttributeId == attrMap.TargetAttributeId))
                {
                    continue;
                }
                var attr = headTargetAttributes.Find(n => n.AttributeId == attrMap.TargetAttributeId);
                if (attr == null)
                {
                    continue;
                }
                var value = sourceRecord[attrMap.SourceAttributeName];
                if (value == null && attrMap.DefaultValue.IsNotEmpty())
                {
                    value = attrMap.DefaultValue;
                }
                headEntity.SetAttributeValue(attr.Name, sourceRecord.WrapAttributeValue(_entityFinder, attr, value));
            }
            //关联来源单据ID
            headEntity.SetAttributeValue(refAttr.Name, sourceRecord.WrapAttributeValue(_entityFinder, refAttr, sourceRecord.GetIdValue()));
            try
            {
                _organizationDataProvider.BeginTransaction();
                InternalOnMap(sourceRecord, headEntity, OperationStage.PreOperation, headTargetEntityMeta, headTargetAttributes);
                newId = _dataCreater.Create(headEntity);
                //新增单据体信息
                if (childEntityMap != null)
                {
                    var childAttributeMaps = _attributeMapFinder.Query(n => n.Where(f => f.EntityMapId == childEntityMap.EntityMapId));
                    if (childAttributeMaps.NotEmpty())
                    {
                        var childTargetEntityMeta     = _entityFinder.FindById(childEntityMap.TargetEntityId);
                        var childTargetAttributesMeta = _attributeFinder.FindByEntityId(childEntityMap.TargetEntityId);
                        var childSourceAttributesMeta = _attributeFinder.FindByEntityId(childEntityMap.SourceEntityId);
                        var childRelationShips        = childEntityMap.RelationShipName.SplitSafe(",");
                        //源单据体与源单据头的关系
                        var childSourceRelationShipMeta = _relationShipFinder.FindByName(childRelationShips[0]);
                        //目标单据体与目标单据头的关系
                        var childTargetRelationShipMeta = _relationShipFinder.FindByName(childRelationShips[1]);
                        //源单据体数据
                        QueryExpression query_source = new QueryExpression(childEntityMap.SourceEnttiyName, _languageId);
                        query_source.ColumnSet.AllColumns = true;
                        var refKey = headSourceAttributes.Find(n => n.AttributeId == childSourceRelationShipMeta.ReferencedAttributeId).Name;
                        query_source.Criteria.AddCondition(refKey, ConditionOperator.Equal, sourceRecordId);
                        var childSourceRecords = _dataFinder.RetrieveAll(query_source);
                        if (childSourceRecords.NotEmpty())
                        {
                            //引用单据头的字段
                            var headRefAttr = childTargetAttributesMeta.Find(n => n.AttributeId == childTargetRelationShipMeta.ReferencingAttributeId);
                            //引用源单据体的字段
                            var refSourceAttr = childTargetAttributesMeta.Find(n => n.ReferencedEntityId.HasValue && n.ReferencedEntityId.Value == childEntityMap.SourceEntityId);
                            foreach (var item in childSourceRecords)
                            {
                                //目标单据体
                                Entity childTargetRecord = new Entity(childEntityMap.TargetEnttiyName);
                                foreach (var attrMap in childAttributeMaps)
                                {
                                    if (!childSourceAttributesMeta.Exists(n => n.AttributeId == attrMap.SourceAttributeId) || !childTargetAttributesMeta.Exists(n => n.AttributeId == attrMap.TargetAttributeId))
                                    {
                                        continue;
                                    }
                                    var attr = childTargetAttributesMeta.Find(n => n.AttributeId == attrMap.TargetAttributeId);
                                    if (attr == null)
                                    {
                                        continue;
                                    }
                                    var value = item[attrMap.SourceAttributeName];
                                    if (value == null && attrMap.DefaultValue.IsNotEmpty())
                                    {
                                        value = attrMap.DefaultValue;
                                    }
                                    childTargetRecord.SetAttributeValue(attrMap.TargetAttributeName, sourceRecord.WrapAttributeValue(_entityFinder, attr, value));
                                }
                                //关联来源单据体记录ID
                                if (refSourceAttr != null)
                                {
                                    childTargetRecord.SetAttributeValue(refSourceAttr.Name, sourceRecord.WrapAttributeValue(_entityFinder, refSourceAttr, item.GetIdValue()));
                                }
                                //单据头ID
                                childTargetRecord.SetAttributeValue(headRefAttr.Name, sourceRecord.WrapAttributeValue(_entityFinder, headRefAttr, newId));
                                _dataCreater.Create(childTargetRecord);
                            }
                        }
                    }
                }
                _organizationDataProvider.CommitTransaction();
                InternalOnMap(sourceRecord, headEntity, OperationStage.PostOperation, headTargetEntityMeta, headTargetAttributes);
            }
            catch (Exception e)
            {
                _organizationDataProvider.RollBackTransaction();
                newId = Guid.Empty;
                OnException(e);
            }
            return(newId);
        }
Esempio n. 6
0
        public bool Assign(Schema.Domain.Entity entityMetadata, Entity entity, OwnerObject owner, bool ignorePermissions = false)
        {
            if (!ignorePermissions)
            {
                VerifyEntityPermission(entity, AccessRightValue.Assign, entityMetadata);
            }
            var    recordId     = entity.GetIdValue();
            Entity ownerEntity  = null;
            Entity updateEntity = new Entity(entityMetadata.Name);

            updateEntity.SetIdValue(recordId);
            updateEntity.SetAttributeValue("ownerid", owner);
            if (owner.OwnerType == OwnerTypes.SystemUser)
            {
                if (owner.OwnerId.Equals(_user.SystemUserId))
                {
                    updateEntity.SetAttributeValue("owningbusinessunit", _user.BusinessUnitId);
                }
                else
                {
                    //business unit
                    var queryBusinessUnit = new QueryExpression("systemuser", _languageId);
                    queryBusinessUnit.ColumnSet.AddColumn("businessunitid");
                    queryBusinessUnit.Criteria.AddCondition("systemuserid", ConditionOperator.Equal, owner.OwnerId);
                    ownerEntity = _organizationDataRetriever.Retrieve(queryBusinessUnit, true);

                    updateEntity.SetAttributeValue("owningbusinessunit", ownerEntity.GetGuidValue("businessunitid"));
                }
                updateEntity.SetAttributeValue("modifiedon", DateTime.Now);
                updateEntity.SetAttributeValue("modifiedby", _user.SystemUserId);
            }
            else
            {
                updateEntity.SetAttributeValue("owningbusinessunit", null);
            }
            var attributeMetadatas = _attributeFinder.FindByEntityId(entityMetadata.EntityId);
            var result             = true;

            try
            {
                _organizationDataProvider.BeginTransaction();
                InternalOnAssign(entity, updateEntity, OperationStage.PreOperation, entityMetadata, attributeMetadatas);
                result = _organizationDataProvider.Update(updateEntity);
                if (result)
                {
                    //assign cascade relationship, 1: N
                    var relationships = _relationShipFinder.Query(n => n
                                                                  .Where(f => f.ReferencedEntityId == entityMetadata.EntityId && f.CascadeAssign != (int)CascadeUpdateType.None)
                                                                  );
                    if (relationships.NotEmpty())
                    {
                        foreach (var rs in relationships)
                        {
                            var relatedEntityMeta = _entityFinder.FindById(rs.ReferencingEntityId);
                            if (relatedEntityMeta.EntityMask == EntityMaskEnum.Organization)
                            {
                                continue;
                            }

                            var queryRelated = new QueryExpression(rs.ReferencingEntityName, _languageId);
                            queryRelated.ColumnSet.AddColumns(rs.ReferencingEntityName + "id");
                            queryRelated.Criteria.AddCondition(rs.ReferencingAttributeName, ConditionOperator.Equal, recordId);
                            //update related records
                            Entity updEntity = new Entity(rs.ReferencingEntityName);
                            updEntity.SetAttributeValue("ownerid", owner);
                            if (owner.OwnerType == OwnerTypes.SystemUser)
                            {
                                updEntity.SetAttributeValue("owningbusinessunit", ownerEntity.GetGuidValue("businessunitid"));
                            }
                            else
                            {
                                updEntity.SetAttributeValue("owningbusinessunit", null);
                            }
                            updEntity.SetAttributeValue("modifiedon", DateTime.Now);
                            updEntity.SetAttributeValue("modifiedby", _user.SystemUserId);
                            _organizationDataProvider.Update(updEntity, _queryResolverFactory.Get(queryRelated), true);
                        }
                    }
                    _organizationDataProvider.CommitTransaction();
                    InternalOnAssign(entity, updateEntity, OperationStage.PostOperation, entityMetadata, attributeMetadatas);
                }
                else
                {
                    _organizationDataProvider.RollBackTransaction();
                }
            }
            catch (Exception e)
            {
                _organizationDataProvider.RollBackTransaction();
                return(OnException(e));
            }
            return(true);
        }
Esempio n. 7
0
        public bool Merge(Guid entityId, Guid mainRecordId, Guid mergedRecordId, Dictionary <string, Guid> attributeMaps, bool ignorePermissions = false)
        {
            var entityMetadata = _entityFinder.FindById(entityId);
            //retrive main record
            var queryMain = new QueryExpression(entityMetadata.Name, _languageId);

            queryMain.ColumnSet.AllColumns = true;
            queryMain.Criteria.AddCondition(entityMetadata.Name + "id", ConditionOperator.Equal, mainRecordId);
            var mainRecord = _dataFinder.Retrieve(queryMain, ignorePermissions);

            if (mainRecord.IsEmpty())
            {
                return(OnException(_loc["notfound_record"]));
            }
            //retrive merged record
            var queryMerged = new QueryExpression(entityMetadata.Name, _languageId);

            queryMerged.ColumnSet.AllColumns = true;
            queryMerged.Criteria.AddCondition(entityMetadata.Name + "id", ConditionOperator.Equal, mergedRecordId);
            var mergedRecord = _dataFinder.Retrieve(queryMerged, ignorePermissions);

            if (mergedRecord.IsEmpty())
            {
                return(OnException(_loc["notfound_record"]));
            }
            var attributeMetadatas = _attributeFinder.FindByEntityId(entityId);
            var updatedRecord      = new Entity(entityMetadata.Name);

            //set target record values
            foreach (var attr in attributeMetadatas)
            {
                if (attr.IsSystemControl())
                {
                    continue;
                }

                if (attributeMaps.ContainsKey(attr.Name))
                {
                    var eid = attributeMaps[attr.Name];
                    updatedRecord.SetAttributeValue(attr.Name, eid.Equals(mainRecordId) ? updatedRecord.WrapAttributeValue(_entityFinder, attr, mainRecord[attr.Name]) : updatedRecord.WrapAttributeValue(_entityFinder, attr, mergedRecord[attr.Name]));
                }
                else
                {
                    updatedRecord.SetAttributeValue(attr.Name, updatedRecord.WrapAttributeValue(_entityFinder, attr, mainRecord[attr.Name]));
                }
            }
            //this.VerifyUpdate(updatedRecord);
            updatedRecord.AddIfNotContain("modifiedon", DateTime.Now);
            updatedRecord.AddIfNotContain("modifiedby", _user.SystemUserId);
            var result = false;

            try
            {
                _organizationDataProvider.BeginTransaction();
                InternalOnMerge(mergedRecord, updatedRecord, OperationStage.PreOperation, entityMetadata, attributeMetadatas);
                //result = _dataUpdater.Update(updatedRecord, ignorePermissions);
                result = _organizationDataProvider.Update(updatedRecord);
                //update referencing records
                var relationships = _relationShipFinder.QueryByEntityId(null, entityId);
                foreach (var rs in relationships)
                {
                    var relatedEntity = new Entity(rs.ReferencingEntityName);
                    relatedEntity.SetAttributeValue(rs.ReferencingAttributeName, mainRecordId);
                    var queryRelated = new QueryExpression(rs.ReferencingEntityName, _languageId);
                    queryRelated.ColumnSet.AddColumns(rs.ReferencingEntityName + "id");
                    queryRelated.Criteria.AddCondition(rs.ReferencingAttributeName, ConditionOperator.Equal, mergedRecordId);
                    _organizationDataProvider.Update(relatedEntity, _queryResolverFactory.Get(queryRelated), ignorePermissions: true);
                }
                //disabled original record
                var disabledEntity = new Entity(entityMetadata.Name);
                disabledEntity.SetIdValue(mergedRecordId);
                disabledEntity.SetAttributeValue("statecode", false);
                //result = _dataUpdater.Update(disabledEntity, ignorePermissions);
                result = _organizationDataProvider.Update(disabledEntity);
                if (result)
                {
                    _organizationDataProvider.CommitTransaction();
                    InternalOnMerge(mergedRecord, updatedRecord, OperationStage.PostOperation, entityMetadata, attributeMetadatas);
                }
                else
                {
                    _organizationDataProvider.RollBackTransaction();
                }
            }
            catch (Exception e)
            {
                _organizationDataProvider.RollBackTransaction();
                OnException(e);
            }
            return(result);
        }
Esempio n. 8
0
        private bool DeleteCore(Schema.Domain.Entity entityMetadata, List <Schema.Domain.Attribute> attributeMetadatas, Entity record, bool ignorePermissions = false)
        {
            if (!ignorePermissions)
            {
                VerifyEntityPermission(record, AccessRightValue.Delete, entityMetadata);
            }
            //cascade relationship, 1: N
            var relationships = _relationShipFinder.Query(n => n
                                                          .Where(f => f.ReferencedEntityId == entityMetadata.EntityId)
                                                          );
            //check referenced
            var cascadeDeleteRestrict = relationships.Where(n => n.ReferencedEntityId == entityMetadata.EntityId && n.CascadeDelete == (int)CascadeDeleteType.Restrict && n.RelationshipType == RelationShipType.ManyToOne);

            var primaryAttr = attributeMetadatas.Find(n => n.TypeIsPrimaryKey());
            var primarykey  = primaryAttr.Name;

            record.IdName = primarykey;
            var recordId = record.GetIdValue();

            foreach (var cdr in cascadeDeleteRestrict)
            {
                var referencingRecord = _aggregateService.Count(cdr.ReferencingEntityName, new FilterExpression(LogicalOperator.And).AddCondition(cdr.ReferencingAttributeName, ConditionOperator.Equal, recordId));
                if (referencingRecord > 0)
                {
                    _relationShipFinder.WrapLocalizedLabel(cdr);
                    return(OnException(_loc["referenced"] + ": " + cdr.ReferencingEntityLocalizedName));
                }
            }
            var result = false;

            try
            {
                _organizationDataProvider.BeginTransaction();
                InternalOnDelete(record, OperationStage.PreOperation, entityMetadata, attributeMetadatas);
                //delete related records
                var cascadeDelete = relationships.Where(n => n.ReferencedEntityId == entityMetadata.EntityId && n.CascadeDelete == (int)CascadeDeleteType.All && n.RelationshipType == RelationShipType.ManyToOne).ToList();
                if (cascadeDelete.NotEmpty())
                {
                    DeleteRelatedRecords(entityMetadata, attributeMetadatas, cascadeDelete, recordId);
                }
                //delete main record
                result = _organizationDataProvider.Delete(record.Name, recordId, primarykey);
                if (result)
                {
                    //update maps
                    _mapUpdater.Update(entityMetadata, record, true);
                    _formulaUpdater.Update(entityMetadata, record);
                    _organizationDataProvider.CommitTransaction();
                    InternalOnDelete(record, OperationStage.PostOperation, entityMetadata, attributeMetadatas);
                }
                else
                {
                    _organizationDataProvider.RollBackTransaction();
                }
            }
            catch (Exception e)
            {
                _organizationDataProvider.RollBackTransaction();
                OnException(e);
            }

            return(result);
        }