/// <summary> /// Create a new group. /// </summary> /// <param name="record">The group object.</param> /// <returns>The GroupId of the new group.</returns> public override Guid Create(Group record) { DataModel dataModel = new DataModel(); DataModelTransaction transaction = DataModelTransaction.Current; EntityPersistence entityPersistence = new EntityPersistence(); Guid entityId; TypeRow typeRow = DataModel.Type.TypeKeyExternalId0.Find("GROUP"); typeRow.AcquireReaderLock(transaction.TransactionId, DataModel.LockTimeout); try { record.TypeId = typeRow.TypeId; record.ImageId = typeRow.ImageId; } finally { typeRow.ReleaseReaderLock(transaction.TransactionId); } entityId = entityPersistence.Create(record); dataModel.CreateRightsHolder( entityId, record.TenantId.Value); dataModel.CreateGroup( entityId, GroupTypeMap.FromCode(record.GroupType), record.TenantId.Value); return(entityId); }
/// <summary> /// /// </summary> /// <returns></returns> public override void Update(DebtNegotiator record) { DataModel dataModel = new DataModel(); DataModelTransaction transaction = DataModelTransaction.Current; EntityPersistence entityPersistence = new EntityPersistence(); DebtClassPersistence debtClassPersistence = new DebtClassPersistence(); entityPersistence.Update(record); debtClassPersistence.Update(record); }
/// <summary> /// Placeholder /// </summary> /// <param name="record"></param> public override void Update(EntityTree record) { DataModel dataModel = new DataModel(); DataModelTransaction transaction = DataModelTransaction.Current; EntityTreeRow entityTreeRow = DataModel.EntityTree.EntityTreeKey.Find(record.RowId); EntityRow child = DataModel.Entity.EntityKey.Find(record.ChildId); EntityRow parent = DataModel.Entity.EntityKey.Find(record.ParentId); String childName; entityTreeRow.AcquireWriterLock(transaction); if (!DataModelFilters.HasAccess(transaction, TradingSupport.UserId, entityTreeRow.ParentId, AccessRight.Write)) { throw new SecurityException("Current user does not have write access to the old parent entity"); } if (!DataModelFilters.HasAccess(transaction, TradingSupport.UserId, record.ParentId, AccessRight.Write)) { throw new SecurityException("Current user does not have write access to the new parent entity"); } parent.AcquireWriterLock(transaction); child.AcquireReaderLock(transaction); childName = child.Name; child.ReleaseLock(transaction.TransactionId); if (record.ChildId == record.ParentId) { throw new FaultException <ArgumentFault>(new ArgumentFault("Create EntityTree"), new FaultReason(String.Format("Cannot add {0} as a child of this element because it wil create a circular relationship", childName))); } if (IsParentEntity(transaction, parent, record.ChildId) == true) { throw new FaultException <ArgumentFault>(new ArgumentFault("Create EntityTree"), new FaultReason(String.Format("Cannot add {0} as a child of this element because it wil create a circular relationship", childName))); } if (!EntityPersistence.IsNameUnique(transaction, parent, childName)) { throw new FaultException <RecordExistsFault>( new RecordExistsFault("Entity", new object[] { childName }), "An entity with this name already exists"); } dataModel.UpdateEntityTree( record.ChildId, entityTreeRow.EntityTreeId, new object[] { entityTreeRow.EntityTreeId }, null, record.ParentId, entityTreeRow.RowVersion); }
/// <summary> /// /// </summary> /// <returns></returns> public override void Update(Entity record) { DataModel dataModel = new DataModel(); DataModelTransaction transaction = DataModelTransaction.Current; DateTime modifiedTime = DateTime.UtcNow; EntityRow entityRow = DataModel.Entity.EntityKey.Find(record.RowId); Dictionary <String, EntityRow> parents = new Dictionary <String, EntityRow>(); List <String> parentNames = new List <String>(); EntityTreeRow[] entityTreeRows; String oldName = null; Int64 rowVersion; if (!TradingSupport.HasAccess(transaction, record.RowId, AccessRight.Write)) { throw new SecurityException("Current user does not have write access to the selected Entity"); } if (record.Name != null && !EntityPersistence.IsNameValid(record.Name as String)) { throw new FaultException <ArgumentFault>(new ArgumentFault("Names cannot contain a backslash"), "Names cannot contain a backslash"); } entityRow.AcquireReaderLock(transaction); entityTreeRows = entityRow.GetEntityTreeRowsByFK_Entity_EntityTree_ChildId(); oldName = entityRow.Name; rowVersion = entityRow.RowVersion; entityRow.ReleaseLock(transaction.TransactionId); if (!oldName.Equals(record.Name)) { foreach (EntityTreeRow entityTreeRow in entityTreeRows) { EntityRow parentEntityRow; entityTreeRow.AcquireReaderLock(transaction); parentEntityRow = entityTreeRow.EntityRowByFK_Entity_EntityTree_ParentId; entityTreeRow.ReleaseLock(transaction.TransactionId); parentEntityRow.AcquireReaderLock(transaction); parents.Add(parentEntityRow.Name, parentEntityRow); parentEntityRow.ReleaseLock(transaction.TransactionId); } parentNames = parents.Keys.ToList(); parentNames.Sort(); foreach (String parentName in parentNames) { parents[parentName].AcquireWriterLock(transaction); } foreach (EntityRow parentEntityRow in parents.Values) { if (!EntityPersistence.IsNameUnique(transaction, parentEntityRow, record.Name as String)) { throw new FaultException <RecordExistsFault>( new RecordExistsFault("Entity", new object[] { record.Name }), "An entity with this name already exists"); } } } dataModel.UpdateEntity( null, record.Description, null, new object[] { record.RowId }, record.ExternalId0, record.ExternalId1, record.ExternalId2, record.ExternalId3, record.ExternalId4, record.ExternalId5, record.ExternalId6, record.ExternalId7, record.ImageId, record.IsHidden, record.IsReadOnly, modifiedTime, record.Name, rowVersion, record.TenantId, null); }