public virtual void ProgramPendingQuestionFormDelete(ProgramPendingQuestionForm entity)
 {
     TraceCallEnterEvent.Raise();
       try
       {
     m_DataContext.BeginNestedTran();
     try
     {
       m_DataContext.ndihdProgramPendingQuestionFormDelete(entity.ProgramRef,
     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 ProgramPendingQuestionForm(ProgramPendingQuestionForm origInstance)
     : base(origInstance)
 {
 }
        public void PendingQuestionFormInsertForProgram(PendingQuestionForm entity)
        {
            TraceCallEnterEvent.Raise();
              try
              {
            if (entity.ProgramID.IsNull)
              throw new ArgumentNullException("PendingQuestionForm.ProgramID", "A program azonosítója nincs megadva.");
            ProgramService programSrv = new ProgramService(m_DataContext);
            Program program = programSrv.ProgramSelect(entity.ProgramID);
            if (program == null)
              throw new ApplicationException("A megadott azonosítóval nem létezik program.");

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

            // 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.");

            /* TODO módosításnál ez is kötelezõ:
            if(entity.QuestionFormRef.IsNull)
              throw new ArgumentNullException("PendingQuestionForm.QuestionFormRef", "Az eredeti kérdõív azonosítója nincs megadva.");
              */

            // logical check:
            TemplateCategoryService templCatSrv = new TemplateCategoryService(m_DataContext);
            TemplateCategory templCat = templCatSrv.TemplateCategorySelect(entity.TemplateRef, program.ProgramCategoryRef);
            if (templCat == null)
              throw new ApplicationException("A megadott programhoz 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.TemplateSelectOfProgramPendingQuestionFormByTemplateID(program.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;
            }

            ProgramPendingQuestionForm programPending = new ProgramPendingQuestionForm(program.ID, entity.ID);

            PendingQuestionFormDetailService detailService = new PendingQuestionFormDetailService(m_DataContext);
            ProgramPendingQuestionFormService programPendingSrv = new ProgramPendingQuestionFormService(m_DataContext);
            m_DataContext.BeginNestedTran();
            try
            {
              base.PendingQuestionFormInsert(entity);
              foreach (PendingQuestionFormDetail detail in entity.Details.All)
              {
            detailService.PendingQuestionFormDetailInsert(detail);
              }
              programPendingSrv.ProgramPendingQuestionFormInsert(programPending);
              m_DataContext.CommitNested();
            }
            catch
            {
              m_DataContext.RollbackNested();
              throw;
            }

            // Log success
            BusinessAuditEvent.Success(
              new EventParameter("PendingQuestionFormID", entity.ID.ToString()),
              new EventParameter("ProgramID", entity.ProgramID.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("ProgramID", entity.ProgramID.ToString())
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
   public virtual ProgramPendingQuestionForm ProgramPendingQuestionFormSelect(DBGuid ProgramRefVal,
 DBGuid PendingQuestionFormRefVal)
   {
       TraceCallEnterEvent.Raise();
         try
         {
       ProgramPendingQuestionForm result = null;
       DataSet entitySet = m_DataContext.ndihdProgramPendingQuestionFormSelect(ProgramRefVal,
         PendingQuestionFormRefVal);
       if (entitySet.Tables[0].Rows.Count != 0)
       {
         result = new ProgramPendingQuestionForm(entitySet);
       }
       TraceCallReturnEvent.Raise();
       return result;
         }
         catch (Exception ex)
         {
       ExceptionManager.Publish(ex);
       TraceCallReturnEvent.Raise(false);
       throw;
         }
   }