Example #1
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
        }
Example #2
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());
        }