public new void TemplateUpdate(Template entity) { PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator"); permAdmin.Demand(); TraceCallEnterEvent.Raise(); try { //check required fields: if (entity.ID.IsNull) throw new ArgumentNullException("Template.ID", "A sablon azonosítója nincs megadva."); if (entity.Name.Length == 0) throw new ArgumentNullException("Template.Name", "A sablon neve nincs megadva."); if (entity.PublicityLevel.IsNull) throw new ArgumentNullException("Template.PublicityLevel", "A publikussági szint nincs megadva."); if (entity.Details == null) throw new ArgumentNullException("Template.Details", "A sablonhoz nincs egyetlen kérdés sem megadva."); if (entity.Details.CurrentCount == 0) throw new ArgumentNullException("Template.Details", "A sablonhoz nincs egyetlen kérdés sem megadva."); string p = PublicityLevel.GetNameById(entity.PublicityLevel.ToString()); if (p == null) throw new ApplicationException("Érvénytelen publikussági szint érték."); Template selected = base.TemplateSelect(entity.ID); if (selected == null) throw new ApplicationException("A megadott azonosítóval nem létezik sablon."); // TODO: check pages //save data m_DataContext.BeginNestedTran(); try { TemplateDetailService detailService = new TemplateDetailService(m_DataContext); TemplatePageService pageService = new TemplatePageService(m_DataContext); TemplateDetailContainer originalDetails = SelectChildrenByDetailOfTemplate(entity.ID); base.TemplateUpdate(entity); foreach (TemplateDetail detail in entity.Details.Current) { if (originalDetails[detail.HashString()] != null) { detailService.TemplateDetailUpdate(detail); } else { detailService.TemplateDetailInsert(detail); } } // replace pages: base.DeleteChildrenByPageOfTemplate(entity.ID); foreach (TemplatePage page in entity.Pages.Current) { pageService.TemplatePageInsert(page); } # region feltöltjük a szabadszöveges kereséshez a GlobalSearch táblát GlobalSearchService srvGlobalSearch = new GlobalSearchService(m_DataContext); DataSet ds = TemplateSelectPendingPrograms(entity.ID); DataTable dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { srvGlobalSearch.SaveProgram(new Guid(dr["uID"].ToString())); } #endregion m_DataContext.CommitNested(); } catch { m_DataContext.RollbackNested(); throw; } BusinessAuditEvent.Success( new EventParameter("TemplateID", entity.ID.ToString()), new EventParameter("TemplateName", entity.Name.ToString()) ); TraceCallReturnEvent.Raise(); return; } catch (Exception ex) { ExceptionManager.Publish(ex); BusinessAuditEvent.Fail( new EventParameter("Exception", ex.ToString()), new EventParameter("TemplateID", entity.ID.ToString()), new EventParameter("TemplateName", entity.Name.ToString()) ); TraceCallReturnEvent.Raise(false); throw; } }
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; } }
public Template TemplateSelectIsActive(DBGuid IDVal, bool IsActive) { TraceCallEnterEvent.Raise(); try { TemplateDetailService srvTmpDetail = new TemplateDetailService(); Template result = base.TemplateSelect(IDVal); result.Pages = PageOfTemplateSelectByIsactive(IDVal, IsActive); result.Categories = base.SelectChildrenByTemplateCategoryOfTemplate(IDVal); result.Details = srvTmpDetail.DetailOfTemplateSelectByIsActive(IDVal); TraceCallReturnEvent.Raise(); return result; } catch (Exception ex) { ExceptionManager.Publish(ex); TraceCallReturnEvent.Raise(false); throw; } }