public bool PendingQuestionFormAcceptNew(PendingQuestionForm entity)
        {
            //Check permission: Admin
              PrincipalPermission permissionAdm =
            new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
              permissionAdm.Demand();

              TraceCallEnterEvent.Raise();
              try
              {
            //Check required fields
            if (entity.ID.IsNull)
              throw new ArgumentNullException("PendingQuestionForm.ID", "Az elbírálandó kérdõív azonosítója nincs megadva.");
            if (entity.ProgramCategoryId.Length == 0)
              throw new ArgumentNullException("PendingQuestionForm.ProgramCategoryId",
                                          "Az elbírálandó kérdõív kategóriája nincs megadva.");
            if (entity.TemplateRef.IsNull)
              throw new ArgumentNullException("PendingQuestionForm.TemplateRef", "A sablon azonosítója nincs megadva.");
            if (entity.Details.AllCount == 0)
              throw new ArgumentNullException("PendingQuestionForm.Details", "A válaszok nincsenek megadva.");
            if (entity.ProgramCategoryId.Equals("ORG"))
            {
              if (entity.OrganisationID.IsNull)
            throw new ArgumentNullException("PendingQuestionForm.OrganisationID",
                                            "A szervezet azonosítója nincs megadva.");
            }
            else
            {
              if (entity.ProgramID.IsNull)
            throw new ArgumentNullException("PendingQuestionForm.ProgramID", "A program azonosítója nincs megadva.");
            }

            // Logical checks:
            PendingQuestionForm selected = base.PendingQuestionFormSelect(entity.ID);
            if (selected == null)
              throw new ApplicationException("A megadott azonosítóval nem létezik elbírálandó kérdõív.");
            if (!selected.Status.Equals(QuestionFormStatus.New_WaitingForDecision))
              throw new ApplicationException("Csak jóváhagyásra váró státuszú kérdõív bírálható el.");

            // Set properties
            DBGuid questionFormID = Guid.NewGuid();
            QuestionForm questionForm = new QuestionForm(questionFormID);
            questionForm.TemplateRef = entity.TemplateRef;

            selected.DecidedBy = Thread.CurrentPrincipal.Identity.Name;
            selected.DecidedDate = DBDateTime.Now;
            selected.Status = QuestionFormStatus.New_Accepted;
            selected.QuestionFormRef = questionFormID;
            selected.IsActual = true;
            //utolsó módosítás, és elfogadás dátuma
            questionForm.LastModifiedDate = selected.SentDate;
            questionForm.DecidedDate = selected.DecidedDate;
            questionForm.LastModifiedByUser = selected.LastModifiedByUser;
            questionForm.IsActual = true;
            //Set mail:
            string modifiedAnswers = "";
            PendingQuestionFormDetailContainer origAnswers = base.SelectChildrenByDetailOfPendingQuestionForm(entity.ID);
            TemplateDetailService templateDetailService = new TemplateDetailService(m_DataContext);
            foreach (PendingQuestionFormDetail origDetail in origAnswers.All)
            {
              string hash = origDetail.HashString();
              PendingQuestionFormDetail currentDetail = (PendingQuestionFormDetail) entity.Details[hash];
              if (currentDetail != null)
              {
            if (!origDetail.Answer.Equals(currentDetail.Answer))
            {
              TemplateDetail question =
                templateDetailService.TemplateDetailSelect(origDetail.TemplateDetailRef, origDetail.TemplateRef);
              modifiedAnswers += "Kérdés:  " + question.Question + "\n";
              modifiedAnswers += "  Eredeti válasz:    " + origDetail.Answer + "\n";
              modifiedAnswers += "  Módosított válasz: " + currentDetail.Answer + "\n\n";
            }
              }
            }
            if (modifiedAnswers.Length == 0)
            {
              modifiedAnswers = "  A jóváhagyó módosítás nélkül fogadta el a kitöltött kérdõívet.\n";
            }

            UserService userSrv = new UserService(m_DataContext);
            User sentBy = userSrv.UserSelect(selected.SentBy);
            Email mail = new Email(Guid.NewGuid());
            mail.Category = EmailCategory.QuestionFormInsertAccept;
            mail.To = sentBy.Email;

            //Subject és body lekérdezése
            string body = "";
            string subject = "";
            EmailTemplateService srvTemplate = new EmailTemplateService();
            srvTemplate.GetEmailTemplateByCode(ref subject, ref body, EmailCategory.QuestionFormInsertAccept);

            mail.Subject = subject;

            body = body.Replace("<FULL_USER_NAME>", sentBy.Name);
            body = body.Replace("<SENT_DATE>", entity.SentDate.ToString());
            body = body.Replace("<TEMPLATE_NAME>", entity.TemplateName);
            body = body.Replace("<MODIFIED_ANSWERS>", modifiedAnswers);
            mail.MailBody = body;

            // Save data to database
            EmailService emailSrv = new EmailService(m_DataContext);
            QuestionFormService questionFormService = new QuestionFormService(m_DataContext);
            ProgramQuestionFormService programQuestionFormService = new ProgramQuestionFormService(m_DataContext);
            OrganisationQuestionFormService organisationQuestionFormService =
              new OrganisationQuestionFormService(m_DataContext);
            QuestionFormDetailService questionFormDetailService = new QuestionFormDetailService(m_DataContext);
            m_DataContext.BeginNestedTran();
            try
            {
              questionFormService.QuestionFormInsert(questionForm);
              base.PendingQuestionFormUpdate(selected);

              if (entity.ProgramCategoryId.Equals("ORG"))
              {
            OrganisationQuestionForm organisationQuestionForm =
              new OrganisationQuestionForm("ORG", entity.OrganisationID, questionFormID);

            //organisationQuestionForm.QuestionFormRef = questionFormID;
            organisationQuestionFormService.OrganisationQuestionFormInsert(organisationQuestionForm);
              }
              else
              {
            ProgramQuestionForm programQuestionForm =
              new ProgramQuestionForm(entity.ProgramCategoryId, entity.ProgramID, questionFormID);
            //programQuestionForm.QuestionFormRef = questionFormID;
            programQuestionFormService.ProgramQuestionFormInsert(programQuestionForm);
              }

              foreach (PendingQuestionFormDetail pendingDetail in entity.Details.All)
              {
            QuestionFormDetail detail =
              new QuestionFormDetail(questionFormID, pendingDetail.TemplateDetailRef, entity.TemplateRef);
            detail.Answer = pendingDetail.Answer;
            detail.FreetextId = Guid.NewGuid();
            questionFormDetailService.QuestionFormDetailInsert(detail);
              }

              emailSrv.EmailInsert(mail);
              m_DataContext.CommitNested();
            }
            catch
            {
              m_DataContext.RollbackNested();
              throw;
            }

            // Sending mail:
            try
            {
              emailSrv.EmailSend(mail.ID);
            }
            catch (Exception ex)
            {
              ExceptionManager.Publish(ex);
              return false;
            }

            // Log success
            BusinessAuditEvent.Success(
              new EventParameter("PendingQuestionFormID", entity.ID.ToString()),
              new EventParameter("ProgramID", entity.ProgramID.ToString()),
              new EventParameter("OrganisationID", entity.OrganisationID.ToString())
              );
            TraceCallReturnEvent.Raise();
            return true;
              }
              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()),
              new EventParameter("OrganisationID", entity.OrganisationID.ToString())
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="programID"></param>
        /// <param name="templateID"></param>
        /// <returns></returns>
        public string GetQuestionFormAsXML(DBGuid programID, DBGuid templateID)
        {
            TraceCallEnterEvent.Raise();
              try
              {
            string result = "";

            ProgramService programService = new ProgramService(m_DataContext);
            Program program = programService.ProgramSelect(programID);
            if (program == null)
              throw new ApplicationException("Ezzel az azonosítóval nem létezik program.");

            TemplateContainer availableTemplates = TemplateSelectOfProgramPendingQuestionForm(programID);

            Template currentTemplate = (Template) availableTemplates[templateID.ToString()];
            if (currentTemplate == null)
              throw new ApplicationException("Ezzel az azonosítóval nem létezik kérdõív a megadott programhoz.");

            if (currentTemplate.Status.Equals("NWD") || currentTemplate.Status.Equals("UWD"))
            {
              throw new ApplicationException("A megadott kérdõív jóváhagyásra vár, nem módosítható.");
            }

            Template extendedTemplate = TemplateSelect(currentTemplate.ID);

            // feltöltjük a válaszokat
            PendingQuestionFormService pendingQuestionFormService = new PendingQuestionFormService(m_DataContext);
            QuestionFormService questionFormService = new QuestionFormService(m_DataContext);
            if (!currentTemplate.PendingQuestionFormID.IsNull)
            {
              PendingQuestionFormDetailContainer pendingAnswers =
            pendingQuestionFormService.SelectChildrenByDetailOfPendingQuestionForm(currentTemplate.PendingQuestionFormID);
              foreach (TemplateDetail d in extendedTemplate.Details.All)
              {
            string hash = currentTemplate.PendingQuestionFormID.ToString() + "<#>" +
                          d.ID.ToString() + "<#>" +
                          d.TemplateRef.ToString();
            PendingQuestionFormDetail answer = (PendingQuestionFormDetail) pendingAnswers[hash];
            if (answer != null)
            {
              d.Answer = answer.Answer;
            }
              }
            }
            else
            {
              if (!currentTemplate.QuestionFormID.IsNull)
              {
            QuestionFormDetailContainer acceptedAnswers =
              questionFormService.SelectChildrenByDetailOfQuestionForm(currentTemplate.QuestionFormID);
            foreach (TemplateDetail d in extendedTemplate.Details.All)
            {
              string hash = currentTemplate.QuestionFormID.ToString() + "<#>" +
                            d.ID.ToString() + "<#>" +
                            d.TemplateRef.ToString();
              QuestionFormDetail answer = (QuestionFormDetail) acceptedAnswers[hash];
              if (answer != null)
              {
                d.Answer = answer.Answer;
              }
            }
              }
            }

            // Build XML
            StringWriter sw = new StringWriter();
            XmlTextWriter xtw = new XmlTextWriter(sw);
            xtw.WriteStartElement("QuestionForm");
            xtw.WriteElementString("QuestionFormID", currentTemplate.QuestionFormID.AsXmlString);
            xtw.WriteElementString("PendingQuestionFormID", currentTemplate.PendingQuestionFormID.AsXmlString);
            xtw.WriteElementString("Status", currentTemplate.Status.AsXmlString);

            //	---	program paramétereinek beállítása
            ProgramCategoryService pcs = new ProgramCategoryService(m_DataContext);
            if (!program.ProgramCategoryRef.IsNull)
            {
              ProgramCategory pc = pcs.ProgramCategorySelect(program.ProgramCategoryRef);
              if (pc != null) program.ProgramCategoryName = pc.Name;
            }

            OrganisationService os = new OrganisationService(m_DataContext);
            if (!program.OrganisationRef.IsNull)
            {
              Organisation org = os.OrganisationSelect(program.OrganisationRef);
              if (org != null) program.OrganisationName = org.Name;
            }

            xtw.WriteRaw(program.AsXmlString);
            string templateXML = ConvertTemplateToXML(extendedTemplate);
            xtw.WriteRaw(templateXML);

            xtw.WriteEndElement();

            result = sw.ToString();

            TraceCallReturnEvent.Raise();
            return result;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }