public virtual void OrganisationPendingQuestionFormDelete(OrganisationPendingQuestionForm entity)
 {
     TraceCallEnterEvent.Raise();
       try
       {
     m_DataContext.BeginNestedTran();
     try
     {
       m_DataContext.ndihdOrganisationPendingQuestionFormDelete(entity.OrganisationRef,
     entity.PendingQuestionFormRef);
       m_DataContext.CommitNested();
     }
     catch
     {
       m_DataContext.RollbackNested();
       throw;
     }
     TraceCallReturnEvent.Raise();
     return;
       }
       catch (Exception ex)
       {
     ExceptionManager.Publish(ex);
     TraceCallReturnEvent.Raise(false);
     throw;
       }
 }
 // -------------------------------------------------------------------------------------
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="origInstance">Original document data to copy.</param>
 // -------------------------------------------------------------------------------------
 public OrganisationPendingQuestionForm(OrganisationPendingQuestionForm origInstance)
     : base(origInstance)
 {
 }
   public virtual OrganisationPendingQuestionForm OrganisationPendingQuestionFormSelect(DBGuid OrganisationRefVal,
 DBGuid PendingQuestionFormRefVal)
   {
       TraceCallEnterEvent.Raise();
         try
         {
       OrganisationPendingQuestionForm result = null;
       DataSet entitySet = m_DataContext.ndihdOrganisationPendingQuestionFormSelect(OrganisationRefVal,
         PendingQuestionFormRefVal);
       if (entitySet.Tables[0].Rows.Count != 0)
       {
         result = new OrganisationPendingQuestionForm(entitySet);
       }
       TraceCallReturnEvent.Raise();
       return result;
         }
         catch (Exception ex)
         {
       ExceptionManager.Publish(ex);
       TraceCallReturnEvent.Raise(false);
       throw;
         }
   }
        public void PendingQuestionFormInsertForOrganisation(PendingQuestionForm entity)
        {
            TraceCallEnterEvent.Raise();
              try
              {
            if (entity.OrganisationID.IsNull)
              throw new ArgumentNullException("PendingQuestionForm.OrganisationID", "A szervezet azonosítója nincs megadva.");

            string writerRole = entity.OrganisationID.Value.ToString() + ".Writer";
            PrincipalPermission permWriter = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, writerRole);
            permWriter.Demand();

            OrganisationService orgSrv = new OrganisationService(m_DataContext);
            Organisation organisation = orgSrv.OrganisationSelect(entity.OrganisationID);
            if (organisation == null)
              throw new ApplicationException("A megadott azonosítóval nem létezik szervezet.");

            // required:
            if (entity.TemplateRef.IsNull)
              throw new ArgumentNullException("PendingQuestionForm.TemplateRef", "A sablon azonosítója nincs megadva.");
            if (entity.Status.Length == 0)
              throw new ArgumentNullException("PendingQuestionForm.Status", "A státusz nincs megadva.");

            // logical check:
            TemplateCategoryService templCatSrv = new TemplateCategoryService(m_DataContext);
            TemplateCategory templCat = templCatSrv.TemplateCategorySelect(entity.TemplateRef, "ORG");
            if (templCat == null)
              throw new ApplicationException("Szervezethez nem tölthetõ ki ez a sablon.");

            // ellenõrizzük, hogy nincs folyamatban ilyen kérdõív kitöltése:
            TemplateService srv = new TemplateService(m_DataContext);
            Template tmplCurrentPending =
              srv.TemplateSelectOfOrganisationPendingQuestionFormByTemplateID(organisation.ID, entity.TemplateRef);

            if (!tmplCurrentPending.Status.IsNull)
            {
              throw new ApplicationException("A kérdõív nem módosítható, mert a módosítás már folyamatban van.");
            }

            // set data:
            entity.SentBy = Thread.CurrentPrincipal.Identity.Name;
            entity.SentDate = DBDateTime.Now;
            entity.LastModifiedByUser = DBDateTime.Now;
            if (entity.Status == "UWD" || entity.Status == "NWD")
            entity.IsActual = true;
            else
            {
              entity.IsActual = false;
            }
            OrganisationPendingQuestionForm organisationPending =
              new OrganisationPendingQuestionForm(entity.OrganisationID, entity.ID);

            PendingQuestionFormDetailService detailService = new PendingQuestionFormDetailService(m_DataContext);
            OrganisationPendingQuestionFormService organisationPendingSrv =
              new OrganisationPendingQuestionFormService(m_DataContext);
            m_DataContext.BeginNestedTran();
            try
            {
              base.PendingQuestionFormInsert(entity);
              foreach (PendingQuestionFormDetail detail in entity.Details.All)
              {
            detailService.PendingQuestionFormDetailInsert(detail);
              }
              organisationPendingSrv.OrganisationPendingQuestionFormInsert(organisationPending);
              m_DataContext.CommitNested();
            }
            catch
            {
              m_DataContext.RollbackNested();
              throw;
            }

            // Log success
            BusinessAuditEvent.Success(
              new EventParameter("PendingQuestionFormID", entity.ID.ToString()),
              new EventParameter("OrganisationID", entity.OrganisationID.ToString())
              );
            TraceCallReturnEvent.Raise();
            return;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("PendingQuestionFormID", entity.ID.ToString()),
              new EventParameter("OrganisationID", entity.OrganisationID.ToString())
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }