示例#1
0
        /// <summary>
        /// Create a new DebtNegotiator
        /// </summary>
        /// <returns></returns>
        public override Guid Create(DebtNegotiator record)
        {
            DataModel            dataModel            = new DataModel();
            Guid                 entityId             = Guid.Empty;
            TypeRow              typeRow              = null;
            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;

            if (record.TypeId != null && record.TypeId != Guid.Empty)
            {
                typeRow = DataModel.Type.TypeKey.Find(record.TypeId.Value);
            }
            else
            {
                typeRow = DataModel.Type.TypeKeyExternalId0.Find("DEBT NEGOTIATOR");
            }

            if (typeRow != null)
            {
                DebtClassPersistence debtClassPersistence = new DebtClassPersistence();
                typeRow.AcquireReaderLock(dataModelTransaction);
                record.TypeId = typeRow.TypeId;
                typeRow.ReleaseLock(dataModelTransaction.TransactionId);

                entityId = debtClassPersistence.Create(record);

                dataModel.CreateDebtNegotiator(entityId);
            }

            return(entityId);
        }
        /// <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);
        }
示例#3
0
        /// <summary>
        /// Create most of a debt class. This should be kicked off by children of DebtClass.
        /// </summary>
        /// <param name="record">The record, complete with TypeId and ImageId.</param>
        /// <returns>The entityId of the new debt class.</returns>
        public override Guid Create(DebtClass record)
        {
            DataModel dataModel = new DataModel();
            TypeRow   typeRow   = DataModel.Type.TypeKey.Find(record.TypeId.Value);
            EntityRow parentEntity;

            AssetViewerTemplateRow[] templates;
            Guid     entityId       = Guid.Empty;
            Guid     organizationId = Guid.Empty;
            DateTime createdTime    = DateTime.UtcNow;

            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;

            Guid ruleId = Guid.NewGuid();

            entityId = Guid.NewGuid();

            if (record.ParentId == null)
            {
                throw new FaultException <ArgumentFault>(new ArgumentFault("Parent EntityId not specified"), "Parent EntityId not specified");
            }
            if (!DataModelFilters.HasAccess(dataModelTransaction, TradingSupport.UserId, record.ParentId.Value, AccessRight.Write))
            {
                throw new FaultException <SecurityFault>(
                          new SecurityFault("The current user doesn't have write permission to the specified parent"),
                          "The current user doesn't have write permission to the specified parent");
            }

            parentEntity = DataModel.Entity.EntityKey.Find(record.ParentId.Value);

            typeRow.AcquireReaderLock(dataModelTransaction);
            templates = typeRow.GetAssetViewerTemplateRows();
            if (record.ImageId == null && !typeRow.IsImageIdNull())
            {
                record.ImageId = typeRow.ImageId;
            }
            typeRow.ReleaseReaderLock(dataModelTransaction.TransactionId);

            if (record.ImageId == null)
            {
                ImageRow imageRow = DataModel.Image[0];
                imageRow.AcquireReaderLock(dataModelTransaction);
                record.ImageId = imageRow.ImageId;
                imageRow.ReleaseReaderLock(dataModelTransaction.TransactionId);
            }

            parentEntity.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
            try
            {
                record.Name = this.GetUniqueName(dataModelTransaction, parentEntity, record.Name as String);
            }
            finally
            {
                parentEntity.ReleaseReaderLock(dataModelTransaction.TransactionId);
            }


            dataModel.CreateEntity(
                createdTime,
                record.Description,
                entityId,
                Guid.NewGuid().ToString(),
                null,
                null,
                null,
                null,
                null,
                null,
                Guid.NewGuid().ToString(),
                record.ImageId.Value,
                false,
                false,
                createdTime,
                record.Name,
                record.TenantId.GetValueOrDefault(),
                record.TypeId.Value);

            dataModel.CreateEntityTree(entityId, Guid.NewGuid(), null, record.ParentId.Value);

            dataModel.CreateBlotter(entityId, PartyTypeMap.FromCode(PartyType.UseParent));

            foreach (AssetViewerTemplateRow template in templates)
            {
                template.AcquireReaderLock(dataModelTransaction);

                dataModel.CreateBlotterConfiguration(Guid.NewGuid(), entityId, null, template.ReportId, template.ReportTypeId);

                template.ReleaseReaderLock(dataModelTransaction.TransactionId);
            }

            dataModel.CreateDebtClass(
                record.Address1,
                record.Address2,
                record.BankAccountNumber,
                record.BankRoutingNumber,
                record.City,
                null,
                record.CompanyName,
                record.ContactName,
                entityId,
                record.DebtRuleId,
                record.Department,
                record.Email,
                record.Fax,
                record.ForBenefitOf,
                record.Phone,
                record.PostalCode,
                record.Province,
                null);

            organizationId = this.FindOrganization(dataModelTransaction);
            Guid tenantId = record.TenantId.HasValue ? record.TenantId.GetValueOrDefault() : organizationId;

            PersistenceHelper.AddGroupPermissions(dataModel, dataModelTransaction, organizationId, entityId, tenantId);
            dataModel.CreateAccessControl(
                Guid.NewGuid(),
                AccessRightMap.FromCode(AccessRight.FullControl),
                entityId,
                TradingSupport.UserId,
                tenantId);

            return(entityId);
        }