Exemplo n.º 1
0
        public override void KefEventInsert(KefEvent entity)
        {
            //
              // Esemény beszúrás elõtt frissíteni kell az utolsó módosítás dátumát
              //
              OrganisationService srvOrg = new OrganisationService();
              Organisation org = srvOrg.OrganisationSelect(entity.OrganisationRef);

              org.KefEventsLastModified = DateTime.Now;
              srvOrg.OrganisationUpdateBase(org);

              //
              // Beszúrjuk az eseményt
              //
              base.KefEventInsert(entity);
        }
        public bool OrganisationPendingUserAccept(Guid OrgPendingUseID, Guid OrganisationID, string LoginName,
                                              string RejectText)
        {
            //Check permission: Admin
              PrincipalPermission permissionAdm =
            new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
              permissionAdm.Demand();

              TraceCallEnterEvent.Raise();
              try
              {
            // Check required fields
            if (OrgPendingUseID == Guid.Empty)
              throw new ArgumentNullException("OrganisationPendingUser.OrgPendingUseID",
                                          "A jóváhagyás azonosítója nincs megadva.");
            if (OrganisationID == Guid.Empty)
              throw new ArgumentNullException("OrganisationPendingUser.OrganisationRef",
                                          "A regisztrálandó szervezet azonosítója nincs megadva.");
            if (LoginName.Length == 0)
              throw new ArgumentNullException("OrganisationPendingUser.LoginNameRef",
                                          "A regisztrálandó felhasználó nincs megadva.");

            // Logical checks
            OrganisationPendingUser selected = base.OrganisationPendingUserSelect(OrgPendingUseID);
            if (selected == null)
              throw new ApplicationException("A megadott azonosítóval nem létezik regisztráció.");
            if (! selected.Status.Equals(RegistrationStatus.New))
              throw new ApplicationException("Csak új státuszú regisztráció bírálható el.");

            // Frissitjük a regisztráció adatait
            selected.SentDate = selected.SentDate;
            selected.DecidedBy = Thread.CurrentPrincipal.Identity.Name;
            selected.DecidedDate = DBDateTime.Now;
            selected.Status = RegistrationStatus.Accepted;
            selected.RejectComment = RejectText;

            //Emailben szereplõ adatok lekkérdezése
            string userEmail = "";
            string userFullName = "";
            string organisationName = "";
            OrganisationService srvOrg = new OrganisationService();
            UserService srvUser = new UserService();
            Organisation org = srvOrg.OrganisationSelect(OrganisationID);
            User u = srvUser.UserSelect(LoginName);

            userEmail = u.Email;
            userFullName = u.Name;
            organisationName = org.Name;

            //set mail:
            Email mail = new Email(Guid.NewGuid());
            mail.Category = EmailCategory.OrganisationPendingUserAccept;
            mail.To = userEmail;

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

            mail.Subject = subject;

            body = body.Replace("<FULL_USER_NAME>", userFullName);
            body = body.Replace("<LOGIN_NAME>", LoginName);
            body = body.Replace("<ORGANISATION>", organisationName);
            mail.MailBody = body;

            // Save data to database
            EmailService emailSrv = new EmailService(m_DataContext);
            m_DataContext.BeginNestedTran();
            try
            {
              //eltároljuk a szervezet-felhasználó kapcsolatot
              OrganisationUserService orgUserSrv = new OrganisationUserService(m_DataContext);
              OrganisationUser orgUser = new OrganisationUser(OrganisationID, LoginName);
              orgUser.Right = selected.Right;
              orgUserSrv.OrganisationUserInsert(orgUser);

              base.OrganisationPendingUserUpdate(selected);
              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("OrganisationPendingUser", OrgPendingUseID.ToString()),
              new EventParameter("OrganisationID", OrganisationID.ToString()),
              new EventParameter("LoginName", LoginName)
              );
            TraceCallReturnEvent.Raise();
            return true;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("OrganisationPendingUser", OrgPendingUseID.ToString()),
              new EventParameter("OrganisationID", OrganisationID.ToString()),
              new EventParameter("LoginName", LoginName)
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
        public bool OrganisationPendingUserReject(OrganisationPendingUser entity)
        {
            //Check permission: Admin
              PrincipalPermission permissionAdm =
            new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
              permissionAdm.Demand();

              TraceCallEnterEvent.Raise();
              try
              {
            // Check required fields
            if (entity.RejectComment.Length == 0)
              throw new ArgumentNullException("OrganisationPendingUser.RejectComment",
                                          "Az elutasítás indoklása nincs megadva.");

            // Logical checks
            OrganisationPendingUser selected = base.OrganisationPendingUserSelect(entity.ID);
            if (selected == null)
              throw new ApplicationException("A megadott azonosítóhoznemtartozik igénylés.");
            if (! selected.Status.Equals(RegistrationStatus.New))
              throw new ApplicationException("Csak új státuszú regisztráció bírálható el.");

            // Set properties
            selected.DecidedBy = Thread.CurrentPrincipal.Identity.Name;
            selected.DecidedDate = DBDateTime.Now;
            selected.Status = RegistrationStatus.Rejected;
            selected.RejectComment = entity.RejectComment;

            //Emailben szereplõ adatok lekkérdezése
            string userEmail = "";
            string userFullName = "";
            string organisationName = "";
            IOrganisationPendingUserService srvOpu = new OrganisationPendingUserService();
            OrganisationPendingUser opu = srvOpu.OrganisationPendingUserSelect(entity.ID);
            IOrganisationService srvOrg = new OrganisationService();
            IUserService srvUser = new UserService();
            Organisation org = srvOrg.OrganisationSelect(opu.OrganisationRef);
            User u = srvUser.UserSelect(opu.LoginNameRef);

            userEmail = u.Email;
            userFullName = u.Name;
            organisationName = org.Name;

            //set mail:
            Email mail = new Email(Guid.NewGuid());
            mail.Category = EmailCategory.OrganisationRegistrationReject;
            mail.To = userEmail;

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

            mail.Subject = subject;

            body = body.Replace("<FULL_USER_NAME>", userFullName);
            body = body.Replace("<LOGIN_NAME>", u.LoginName);
            body = body.Replace("<ORGANISATION>", organisationName);
            body = body.Replace("<REJECT_COMMENT>", entity.RejectComment);
            mail.MailBody = body;

            // Save data to database
            EmailService emailSrv = new EmailService(m_DataContext);
            m_DataContext.BeginNestedTran();
            try
            {
              base.OrganisationPendingUserUpdate(selected);
              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("RegisterOrganisationID", entity.ID.ToString()),
              new EventParameter("OrganisationName", organisationName),
              new EventParameter("LoginName", u.LoginName)
              );
            TraceCallReturnEvent.Raise();
            return true;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("RegisterOrganisationID", entity.ID.ToString())
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
        public new void ProgramPartnerInsert(ProgramPartner entity)
        {
            ProgramPartner part = base.ProgramPartnerSelect(entity.OrganisationRef, entity.ProgramRef);
              if (part != null)
              {
            return;
              }

              TraceCallEnterEvent.Raise();
              try
              {
            // logical checks:
            ProgramService progSrv = new ProgramService();
            Program selected = progSrv.ProgramSelect(entity.ProgramRef);
            if (selected == null)
              throw new ApplicationException("Ezzel az azonosítóval nem létezik program.");
            if (!selected.IsActive)
              throw new ApplicationException("A program nem aktív.");

            // check permission: Writer or Admin
            string writerRole = selected.OrganisationRef.Value.ToString() + ".Writer";
            PrincipalPermission permWriter = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, writerRole);
            PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
            permWriter.Union(permAdmin).Demand();

            if (entity.OrganisationRef.Value.Equals(selected.OrganisationRef.Value))
              throw new ApplicationException("A szervezet nem lehet saját maga partnere.");

            OrganisationService orgSrv = new OrganisationService();
            Organisation partner = orgSrv.OrganisationSelect(entity.OrganisationRef);
            if (partner == null)
              throw new ApplicationException("Ezzel az azonosítóval nem létezik szervezet.");
            if (!partner.IsActive)
              throw new ApplicationException("A szervezet nem aktív.");

            // save data:
            base.ProgramPartnerInsert(entity);

            BusinessAuditEvent.Success(
              new EventParameter("ProgramID", entity.ProgramRef.ToString()),
              new EventParameter("OrganisationID", entity.OrganisationRef.ToString())
              );
            TraceCallReturnEvent.Raise();
            return;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("ProgramID", entity.ProgramRef.ToString()),
              new EventParameter("OrganisationID", entity.OrganisationRef.ToString())
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
        public override void OrgMemberOfOrgUpdate(OrgMemberOfOrg entity)
        {
            TraceCallEnterEvent.Raise();
              try
              {
            m_DataContext.BeginNestedTran();

            try
            {
              #region : Frissítjük a dKefMembersLastModified idõpontot :

              OrganisationService srvOrg = new OrganisationService(m_DataContext);
              Organisation org = srvOrg.OrganisationSelect(entity.OrganisationKefRef);

              org.KefMembersLastModified = DateTime.Now;

              srvOrg.OrganisationUpdateBase(org);

              #endregion

              //elmentjük az entitás adatait
              base.OrgMemberOfOrgUpdate(entity);

              m_DataContext.CommitNested();
            }
            catch
            {
              m_DataContext.RollbackNested();
              throw;
            }

            TraceCallReturnEvent.Raise();

            return;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
Exemplo n.º 6
0
        public UserContainer UserSelectOfEmailRecipient(
      bool activityOther,
      bool activityPrevention,
      bool activityRehabilitation,
      bool activityResearch,
      bool activityNDI,
      bool activityAll)
        {
            // Check permission: Administrator
              PrincipalPermission permissionAdm =
            new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
              permissionAdm.Demand();

              TraceCallEnterEvent.Raise();
              try
              {
            string ndiIdSting = ConfigurationManager.AppSettings["NDI.Id"];
            Guid ndiID= Guid.Empty;
            if (ndiIdSting != null && ndiIdSting.Length == 36)
            {
              ndiID= new Guid(ndiIdSting);
            }

            OrganisationService orgSrv = new OrganisationService(m_DataContext);

            UserContainer all;
            UserContainer result;
            DataSet entitySet = m_DataContext.ndihdUserSelectDispsetOfEmailRecipient();
            all = new UserContainer(entitySet.Tables[0]);
            result = new UserContainer();
            //mindenki
            if (activityAll)
            {
              result = new UserContainer(entitySet.Tables[0]);
            }
            else
            {
              foreach (User user in all.All)
              {
            Organisation org = orgSrv.OrganisationSelect(user.OrganisationRef);
            if (org != null)
            {
              if(org.ID.Equals(ndiID) && activityNDI)
              {
                if (!result.All.Items.Contains(user))
                {
                  result.All.Items.Add(user);
                }
              }

              if (org.ActivityOther && activityOther)
              {
                if (!result.All.Items.Contains(user))
                {
                  result.All.Items.Add(user);
                }
              }

              if (org.ActivityPrevention && activityPrevention)
              {
                if (!result.All.Items.Contains(user))
                {
                  result.All.Items.Add(user);
                }
              }

              if (org.ActivityRehabilitation && activityRehabilitation)
              {
                if (!result.All.Items.Contains(user))
                {
                  result.All.Items.Add(user);
                }
              }

              if (org.ActivityResearch && activityResearch)
              {
                if (!result.All.Items.Contains(user))
                {
                  result.Add(user);
                }
              }
            }
              }
            }
            TraceCallReturnEvent.Raise();
            return result;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
        public void PendingQuestionFormUpdateForOrganisation(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.");

            PendingQuestionForm selectedPending = base.PendingQuestionFormSelect(entity.ID); //Ez van az adatbázisban
            if (selectedPending == null)
              throw new ApplicationException("A módosítani kívánt kérdõív nem létezik.");
            PendingQuestionFormDetailService detailService = new PendingQuestionFormDetailService(m_DataContext);
            PendingQuestionFormDetailContainer selectedPendingDetails = base.SelectChildrenByDetailOfPendingQuestionForm(selectedPending.ID);
            // set data:
            entity.SentBy = Thread.CurrentPrincipal.Identity.Name;
            entity.SentDate = DBDateTime.Now;
            entity.LastModifiedByUser = DBDateTime.Now;
            bool onlyIsActualChanged = true;
            if (entity.Status == "UWD" || entity.Status == "NWD")
            {
              entity.IsActual = true; //Új- jóváhagyásra vár, módosítiott jóváhagyásra vár
              //Kell egy ellenõrzés, hogy csak a bIsActual változott-e
              //onlyIsActualChanged =
              //  entity.QuestionFormRef == selectedPending.QuestionFormRef && entity.TemplateRef == selectedPending.TemplateRef;

              //foreach (PendingQuestionFormDetail detail in entity.Details.All)
              //{
              //   foreach (PendingQuestionFormDetail selectedDetail in selectedPendingDetails.All)
              //   {
              //     if(detail.TemplateDetailRef == selectedDetail.TemplateDetailRef && detail.TemplateRef == selectedDetail.TemplateRef)
              //     {
              //       onlyIsActualChanged &= detail.Answer == selectedDetail.Answer;
              //     }
              //   }
              //}
              //Ha az alapadatok és minden váasz egyforma, akkor csak a bIsActualt akarta menteni, tehát jóv kell hagyni a végén
            }
            else
            {
              entity.IsActual = false;
            }

            m_DataContext.BeginNestedTran();
            try
            {
              base.PendingQuestionFormUpdate(entity);
              base.DeleteChildrenByDetailOfPendingQuestionForm(entity.ID);
              foreach (PendingQuestionFormDetail detail in entity.Details.All)
              {
            detailService.PendingQuestionFormDetailInsert(detail);
              }
              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;
              }
        }
        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;
              }
        }
        public new void OrganisationAttachmentUpdate(OrganisationAttachment entity)
        {
            // check permission: admin, writer
              PrincipalPermission permReg = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Registered");
              PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
              permReg.Union(permAdmin).Demand();

              TraceCallEnterEvent.Raise();
              try
              {
            OrganisationService srvOrg = new OrganisationService();
            Organisation selectedOrg = srvOrg.OrganisationSelect(entity.OrganisationRef);
            if (selectedOrg == null)
              throw new ApplicationException("A megadott azonosítóval nem létezik szervezet.");

            string writerRole = selectedOrg.ID.Value.ToString() + ".Writer";
            PrincipalPermission permWriter = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, writerRole);
            permWriter.Union(permAdmin).Demand();

            // check required fields:
            if (entity.Name.Length == 0)
              throw new ArgumentNullException("OrganisationAttachment.Name", "A csatolt fájl neve nincs megadva.");
            if (entity.Description.Length == 0)
              throw new ArgumentNullException("OrganisationAttachment.Description", "A csatolt fájl leírása nincs megadva.");

            OrganisationAttachment selected = base.OrganisationAttachmentSelect(entity.ID);
            if (selected == null)
              throw new ApplicationException("A csatolt dokumentum nem létezik.");
            if (!selected.IsActive)
              throw new ApplicationException("A csatolt dokumentum nem aktív.");

            // save data
            if (entity.DownloadData != null && entity.DownloadData.Length > 0)
            {
              if (entity.Path.Length == 0 || entity.Path == DBString.Null )
            throw new ArgumentNullException("OrganisationAttachment.Path", "A fájlnév nincs megadva.");

              OrganisationAttachment newAttachment = new OrganisationAttachment(Guid.NewGuid(), entity);
              string fileName = newAttachment.ID.Value.ToString() + Path.GetExtension(newAttachment.Path);
              FileDataContext fileDataContext = new FileDataContext();
              fileDataContext.OrganisationAttachmentInsert(newAttachment.OrganisationRef, fileName, entity.DownloadData);
              newAttachment.CreatedDate = DBDateTime.Now;
              newAttachment.IsActive = true;
              newAttachment.FileSize = entity.DownloadData.Length;
              newAttachment.KefFileTypeRef = entity.KefFileTypeRef;
              selected.IsActive = false;
              m_DataContext.BeginNestedTran();
              try
              {
            base.OrganisationAttachmentInsert(newAttachment);
            OrganisationAttachmentDelete(selected);
            m_DataContext.CommitNested();
              }
              catch
              {
            m_DataContext.RollbackNested();
            throw;
              }
            }
            else
            {
              selected.Name = entity.Name;
              selected.Description = entity.Description;
              selected.Author = entity.Author;
              selected.Publisher = entity.Publisher;
              selected.PublishedYear = entity.PublishedYear;
              selected.Keywords = entity.Keywords;
              selected.KefFileTypeRef = entity.KefFileTypeRef;
              base.OrganisationAttachmentUpdate(selected);
            }

            BusinessAuditEvent.Success(
              new EventParameter("OrganisationAttachmentID", entity.ID.ToString()),
              new EventParameter("OrganisationAttachmentName", entity.Name),
              new EventParameter("OrganisationID", entity.OrganisationRef.ToString())
              );
            TraceCallReturnEvent.Raise();
            return;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("OrganisationAttachmentID", entity.ID.ToString()),
              new EventParameter("OrganisationAttachmentName", entity.Name),
              new EventParameter("OrganisationID", entity.OrganisationRef.ToString())
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
Exemplo n.º 10
0
        /// <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;
              }
        }
Exemplo n.º 11
0
        public TemplateContainer TemplateSelectOfOrganisationQuestionForm(DBGuid OrganisationIdVal, DBInt PublicityLevel)
        {
            TraceCallEnterEvent.Raise();
              try
              {
            OrganisationService orgSrv = new OrganisationService(m_DataContext);
            Organisation selectedOrg = orgSrv.OrganisationSelect(OrganisationIdVal);
            if (selectedOrg == null)
              throw new ApplicationException("A megadott azonosítóval nem létezik szervezet.");

            if (!selectedOrg.IsActive)
              throw new ApplicationException("A szervezet nem aktív.");

            TemplateContainer result;
            DataSet entitySet = m_DataContext.ndihdTemplateSelectOfOrganisationQuestionForm(
              OrganisationIdVal, PublicityLevel);
            result = new TemplateContainer(entitySet.Tables[0]);

            TraceCallReturnEvent.Raise();
            return result;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
Exemplo n.º 12
0
        public Template TemplateSelectOfOrganisationPendingQuestionFormByTemplateID(DBGuid OrganisationIdVal,
                                                                                DBGuid TemplateIdVal)
        {
            TraceCallEnterEvent.Raise();
              try
              {
            string writerRole = OrganisationIdVal.Value.ToString() + ".Writer";
            string readerRole = OrganisationIdVal.Value.ToString() + ".Reader";
            PrincipalPermission permWriter = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, writerRole);
            PrincipalPermission permReader = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, readerRole);
            permWriter.Union(permReader).Demand();

            OrganisationService orgSrv = new OrganisationService(m_DataContext);
            Organisation selectedOrg = orgSrv.OrganisationSelect(OrganisationIdVal);
            if (selectedOrg == null)
              throw new ApplicationException("A megadott azonosítóval nem létezik szervezet.");
            if (!selectedOrg.IsActive)
              throw new ApplicationException("A szervezet nem aktív.");

            DataSet entitySet = m_DataContext.ndihdTemplateSelectOfOrganisationPendingQuestionFormByTemplateID(
              OrganisationIdVal, TemplateIdVal);
            Template retTempl = new Template(entitySet);

            TraceCallReturnEvent.Raise();
            return retTempl;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
Exemplo n.º 13
0
        public new void ProgramInsert(Program entity)
        {
            // check permission: Writer or Admin
              string writerRole = entity.OrganisationRef.Value.ToString() + ".Writer";
              PrincipalPermission permWriter = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, writerRole);
              PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
              permWriter.Union(permAdmin).Demand();

              TraceCallEnterEvent.Raise();
              try
              {
            // check required fields:
            if (entity.ID.IsNull) throw new ArgumentNullException("Program.ID", "A program azonosítója nincs megadva.");
            if (entity.OrganisationRef.IsNull)
              throw new ArgumentNullException("Program.OrganisationRef", "A szervezet azonosítója nincs megadva.");
            if (entity.Name.Length == 0) throw new ArgumentNullException("Program.Name", "A program neve nincs megadva.");
            if (entity.Description.Length == 0)
              throw new ArgumentNullException("Program.Description", "A program leírása nincs megadva.");
            if (entity.ProgramStatus.Length == 0)
              throw new ArgumentNullException("Program.ProgramStatus", "A program státusza nincs megadva.");
            if (entity.ProgramCategoryRef.Length == 0)
              throw new ArgumentNullException("Program.ProgramCategoryRef", "A program típusa nincs megadva.");

            if (CheckProgramExistByName(entity.Name, entity.OrganisationRef, entity.ID))
            {
              throw new ApplicationException("Ezzel a névvel már létezik program!");
            }

            OrganisationService orgSrv = new OrganisationService(m_DataContext);
            Organisation orgSelected = orgSrv.OrganisationSelect(entity.OrganisationRef);
            if (orgSelected == null)
              throw new ApplicationException("Ezzel az azonosítóval nem létezik szervezet.");

            bool orgNeedToUpdate = false;

            switch (entity.ProgramCategoryRef)
            {
              case "PRE":
            if (!orgSelected.ActivityPrevention)
            {
              orgSelected.ActivityPrevention = true;
              orgNeedToUpdate = true;
            }
            break;
              case "TRE":
            if (!orgSelected.ActivityRehabilitation)
            {
              orgSelected.ActivityRehabilitation = true;
              orgNeedToUpdate = true;
            }
            break;
              case "RES":
            if (!orgSelected.ActivityResearch)
            {
              orgSelected.ActivityResearch = true;
              orgNeedToUpdate = true;
            }
            break;
              case "OTH":
            if (!orgSelected.ActivityOther)
            {
              orgSelected.ActivityOther = true;
              orgNeedToUpdate = true;
            }
            break;
            }

            // save data:
            entity.IsActive = true;

            m_DataContext.BeginNestedTran();
            try
            {
              entity.LastModifiedDate = DateTime.Now;
              base.ProgramInsert(entity);
              if (orgNeedToUpdate)
              {
            orgSrv.OrganisationUpdateBase(orgSelected);
              }

              #region Megyék

              // Program partner - delete and insert
              //if (entity.Regions.AllCount > 0)
              {
            //egyesével felvesszük
            for (int i = 0; i < entity.Regions.All.Count; i++)
            {
              DBString regionRef = ((ProgramRegion) entity.Regions.All.Items[i]).RegionRef;
              m_DataContext.ndihdProgramRegionInsert(entity.ID, regionRef);
            }
              }

              #endregion

              //feltöltjük a szabadszöveges kereséshez a GlobalSearch táblát
              GlobalSearchService srvGlobalSearch = new GlobalSearchService(m_DataContext);
              srvGlobalSearch.SaveProgram(entity);

              m_DataContext.CommitNested();
            }
            catch
            {
              m_DataContext.RollbackNested();
              throw;
            }

            BusinessAuditEvent.Success(
              new EventParameter("ProgramID", entity.ID.ToString()),
              new EventParameter("ProgramName", entity.Name)
              );
            TraceCallReturnEvent.Raise();
            return;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("ProgramID", entity.ID.ToString()),
              new EventParameter("ProgramName", entity.Name)
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }