Exemplo n.º 1
0
        /// <summary>
        /// Creates the entity object.
        /// </summary>
        /// <param name="metaClassName">Name of the meta class.</param>
        /// <param name="primaryKeyId">The primary key id.</param>
        /// <returns></returns>
        protected override EntityObject CreateEntityObject(string metaClassName, PrimaryKeyId?primaryKeyId)
        {
            if (metaClassName == DocumentEntity.GetAssignedMetaClassName())
            {
                DocumentEntity retVal = new DocumentEntity();
                retVal.PrimaryKeyId = primaryKeyId;
                return(retVal);
            }

            return(base.CreateEntityObject(metaClassName, primaryKeyId));
        }
Exemplo n.º 2
0
        protected override void PreDeleteInsideTransaction(BusinessContext context)
        {
            base.PreDeleteInsideTransaction(context);

            #region Delete DocumentVersion
            EntityObject[] versions = BusinessManager.List(DocumentContentVersionEntity.GetAssignedMetaClassName(),
                                                           new FilterElement[] { FilterElement.EqualElement("OwnerDocumentId", context.GetTargetPrimaryKeyId().Value) });

            foreach (EntityObject version in versions)
            {
                BusinessManager.Delete(version);
            }
            #endregion

            #region Process RelatedDocumentAction
            RelatedDocumentAction relDocumentAction = context.Request.Parameters.GetValue <RelatedDocumentAction>(DocumentRequestParameters.Delete_RelatedDocumentAction, RelatedDocumentAction.None);

            switch (relDocumentAction)
            {
            // Detach all assigned contacts
            case RelatedDocumentAction.Detach:
                EntityObject[] detachedItems = BusinessManager.List(DocumentEntity.GetAssignedMetaClassName(),
                                                                    new FilterElement[] { FilterElement.EqualElement("MasterDocumentId", context.GetTargetPrimaryKeyId()) });

                foreach (DocumentEntity document in detachedItems)
                {
                    document.MasterDocumentId = null;

                    BusinessManager.Update(document);
                }
                break;

            // Delete all assigned actions
            case RelatedDocumentAction.Delete:
                EntityObject[] deletedItems = BusinessManager.List(DocumentEntity.GetAssignedMetaClassName(),
                                                                   new FilterElement[] { FilterElement.EqualElement("MasterDocumentId", context.GetTargetPrimaryKeyId()) });

                foreach (DocumentEntity document in deletedItems)
                {
                    DeleteRequest request = new DeleteRequest(document);
                    request.Parameters.Add(DocumentRequestParameters.Delete_RelatedDocumentAction, RelatedDocumentAction.Delete);

                    BusinessManager.Execute(request);
                }
                break;
            }

            #endregion

            // TODO: Process Link To Current Document
        }
Exemplo n.º 3
0
        protected override void PostCreateInsideTransaction(BusinessContext context)
        {
            // Call Base method
            base.PostCreateInsideTransaction(context);

            #region Create a new Document Card
            PrimaryKeyId pkDocumentType = ((CreateResponse)context.Response).PrimaryKeyId;

            // Create a new Document Card
            using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit())
            {
                // TODO: Check Card Name
                string cardName         = context.Request.Target["Name"].ToString();
                string cardFriendlyName = context.Request.Target["FriendlyName"].ToString();
                string cardPluralName   = cardFriendlyName;
                string tableName        = "cls_Document_" + context.Request.Target["Name"].ToString();

                MetaClass newCard = DataContext.Current.MetaModel.CreateCardMetaClass(DataContext.Current.GetMetaClass(DocumentEntity.GetAssignedMetaClassName()),
                                                                                      cardName, cardFriendlyName,
                                                                                      cardPluralName, tableName);

                scope.SaveChanges();
            }
            #endregion
        }
Exemplo n.º 4
0
        /// <summary>
        /// Customs the method.
        /// </summary>
        /// <param name="context">The context.</param>
        protected virtual void UpdateState(BusinessContext context)
        {
            // Load Meta Object
            MetaObject metaObject = MetaObjectActivator.CreateInstance(DocumentContentVersionEntity.GetAssignedMetaClassName(),
                                                                       context.GetTargetPrimaryKeyId().Value);

            // Extract old and new states
            DocumentContentVersionState newState = (DocumentContentVersionState)(int)context.Request.Target["State"];
            DocumentContentVersionState oldState = (DocumentContentVersionState)(int)metaObject["State"];

            if (oldState == newState)
            {
                return;
            }

            BusinessContext.Current.Items["MC_Document_SourceMetaObject"] = metaObject;
            BusinessContext.Current.Items["MC_Document_NewState"]         = newState;
            BusinessContext.Current.Items["MC_Document_OldState"]         = oldState;



            // Pre-Process
            switch (oldState)
            {
            case DocumentContentVersionState.Active:
            {
                // Reset Content Reference to Active Document here
                DocumentEntity document = (DocumentEntity)BusinessManager.Load(DocumentEntity.GetAssignedMetaClassName(), (PrimaryKeyId)metaObject["OwnerDocumentId"]);
                document.ActiveVersionId = null;
                BusinessManager.Update(document);
            }
            break;

            case DocumentContentVersionState.Draft:
                // Nothing
                break;

            case DocumentContentVersionState.Obsolete:
                // Nothing
                break;
            }

            // Process
            switch (newState)
            {
            case DocumentContentVersionState.Active:
            {
                DocumentEntity document = (DocumentEntity)BusinessManager.Load(DocumentEntity.GetAssignedMetaClassName(), (PrimaryKeyId)metaObject["OwnerDocumentId"]);

                // Reset Current Reference to Active Document here
                if (document.ActiveVersionId.HasValue)
                {
                    DocumentContentVersionEntity oldVersion = new DocumentContentVersionEntity(document.ActiveVersionId.Value);
                    oldVersion.State = (int)DocumentContentVersionState.Draft;

                    UpdateStateRequest request = new UpdateStateRequest(oldVersion);
                    BusinessManager.Execute(request);
                }

                // Update Current Reference to Active Document here
                document.ActiveVersionId = context.GetTargetPrimaryKeyId();
                BusinessManager.Update(document);
            }
            break;

            case DocumentContentVersionState.Draft:
                break;

            case DocumentContentVersionState.Obsolete:
                break;
            }

            // Update Data Storage And Save
            metaObject["State"] = (int)newState;
            metaObject.Save();

            context.SetResponse(new Response());
        }