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;
              }
        }
예제 #2
0
        /// <summary>
        /// Sends the mail to sender.
        /// </summary>
        /// <param name="category">The category.</param>
        /// <param name="body">The body.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="offer">The offer.</param>
        /// <param name="mustUpdate">if set to <c>true</c> [must update].</param>
        private void SendMailToSender(string category, string body, string subject, JobOffer offer, bool mustUpdate)
        {
            //set mail:
              Email mail = new Email(Guid.NewGuid());

              mail.Category = category;
              mail.Subject = subject;

              mail.To = offer.ContactEmail;
              mail.MailBody = body;

              if (mail.MailBody != null && mail.To != null && mail.Subject != null)
              {
            // Save data to database
            EmailService emailSrv = new EmailService(m_DataContext);
            m_DataContext.BeginNestedTran();
            try
            {
              emailSrv.EmailInsert(mail);
              if (mustUpdate)
              {

            JobOfferService srv = new JobOfferService(m_DataContext);
            JobOffer job = srv.JobOfferSelect(offer.ID);
            if (job != null)
            {
              job.NotificationSend = true;
              job.LastModified = DateTime.Now;
              srv.JobOfferUpdate(job);
            }

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

            // Sending mail:
            try
            {
              emailSrv.EmailSend(mail.ID);
            }
            catch (Exception ex)
            {
              ExceptionManager.Publish(ex);
              return;
            }
              }
        }
        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;
              }
        }
예제 #4
0
        /// <summary>
        /// Sends the mail to subscriber.
        /// </summary>
        /// <param name="category">The category.</param>
        /// <param name="body">The body.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="emailTo">The email to.</param>
        /// <param name="mustUpdate">if set to <c>true</c> [must update].</param>
        /// <param name="answer">The id.</param>
        private void SendMailToSender(string category, string body, string subject, string emailTo, bool mustUpdate, JobAnswer answer)
        {
            //set mail:
              Email mail = new Email(Guid.NewGuid());

              mail.Category = category;
              mail.Subject = subject;
              mail.To = emailTo;
              mail.MailBody = body;

              if (mail.MailBody != null && mail.To != null && mail.Subject != null)
              {
            // Save data to database
            EmailService emailSrv = new EmailService(m_DataContext);
            m_DataContext.BeginNestedTran();
            try
            {
              emailSrv.EmailInsert(mail);
              JobAnswerService srv = new JobAnswerService(m_DataContext);
              JobAnswer job = srv.JobAnswerSelect(answer.JobRef, answer.Type, answer.SubscriberNameRef, answer.SenderNameRef);
              if (job != null)
              {
            if (mustUpdate)
            {
              job.IsActive = false;

            }
            else
            {
              job.SenderNotificationSend = true;
            }
            srv.JobAnswerUpdate(job);
              }
              m_DataContext.CommitNested();
            }
            catch
            {
              m_DataContext.RollbackNested();
              throw;
            }

            // Sending mail:
            try
            {
              emailSrv.EmailSend(mail.ID);
            }
            catch (Exception ex)
            {
              ExceptionManager.Publish(ex);
              return;
            }
              }
        }
예제 #5
0
        public new void JobOfferInsert(JobOffer entity)
        {
            // check permission: Writer or Admin
              PrincipalPermission permReg = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Registered");
              PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
              permReg.Union(permAdmin).Demand();

              TraceCallEnterEvent.Raise();
              m_DataContext.BeginNestedTran();
              try
              {
            // check required fields:
            if (entity.Description.Length == 0)
              throw new ArgumentNullException("JobOffer.Description", "A hirdetés leírása nincs megadva.");

            entity.Sender = Thread.CurrentPrincipal.Identity.Name;
            entity.Status = JobStatusEnum.ACT;
            entity.NotificationSend = false;
            entity.LastModified = DateTime.Now;
            entity.Created = DateTime.Now;
            base.JobOfferInsert(entity);

            JobOfferAttachmentService attSrv = new JobOfferAttachmentService(m_DataContext);

            // EDocumentAttachments - insert:
            foreach (JobOfferAttachment file in entity.JobOfferAttachments.Current)
            {
              file.JobOfferRef = entity.ID;
              file.IsActive = true;
              file.CreatedDate = DateTime.Now;
              attSrv.JobOfferAttachmentInsert(file);
            }
            m_DataContext.CommitNested();

            #region Találati mail
            entity = JobOfferSelect(entity.ID); // a refid miatt kell

            //Ellenõrizni kell, hogy van-epárja megye, végzettség szerint. Ha van levelet kell küldeni
            //a pár feladójának
            JobFindService srvJobFind = new JobFindService();
            JobFind filter = new JobFind(Guid.Empty);
            filter.RegionRef = entity.RegionRef;
            filter.Qualification = entity.QualificationMinRef;
            filter.Status = JobStatusEnum.ACT;
            //filter.Expiredate = DateTime.Now;
            QualificationService srvQualification = new QualificationService();
            UserService srvUser = new UserService();

            JobFindContainer finds = srvJobFind.JobFindSelectFiltered(filter);
            //Van pár
            foreach (JobFind find in finds.All)
            {
              //Itt meg kell nézni azt is, hogy nem õ-e a másik hirdetés feladója
              if (find.Sender != entity.Sender)
              {

            //értesítjük a feladót, hogy valaki válaszolt a hirdetésére
            //set mail:
            Email mail = new Email(Guid.NewGuid());
            //Subject és body lekérdezése
            string body = "";
            string subject = "";
            EmailTemplateService srvTemplate = new EmailTemplateService();
            srvTemplate.GetEmailTemplateByCode(ref subject, ref body, EmailCategory.JobFindMatchCreated);
            mail.Category = EmailCategory.JobFindMatchCreated;
            mail.Subject = subject;

            User findSender = srvUser.UserSelect(find.Sender);
            if (findSender != null)
            {
              mail.To = findSender.Email;
              body = body.Replace("<FULL_USER_NAME>", findSender.Name);
              body = body.Replace("<JOB_REFID>", entity.RefId.ToString());
              body = body.Replace("<JOB_DESCRIPTION>", entity.Description);
              body = body.Replace("<SENDER_NAME>", entity.ContactName);
              body = body.Replace("<SENDER_MAIL>", entity.ContactEmail);
            }
            mail.MailBody = body;

            if (mail.MailBody != null && mail.To != null && mail.Subject != null)
            {
              // Save data to database
              EmailService emailSrv = new EmailService(m_DataContext);
              m_DataContext.BeginNestedTran();
              try
              {
                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;
              }
            }
              }
            }

            #endregion
            BusinessAuditEvent.Success(
              new EventParameter("JobOfferID", entity.ID.ToString()),
              new EventParameter("JobOfferLogin", entity.Sender)
              );
            TraceCallReturnEvent.Raise();
            return;
              }
              catch (Exception ex)
              {
            m_DataContext.RollbackNested();
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("JobOfferID", entity.ID.ToString()),
              new EventParameter("JobOfferLogin", entity.Sender)
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
예제 #6
0
        private void SendMail(Email mail)
        {
            // Save data to database
              EmailService emailSrv = new EmailService(m_DataContext);
              m_DataContext.BeginNestedTran();
              try
              {
            emailSrv.EmailInsert(mail);
            m_DataContext.CommitNested();
              }
              catch
              {
            m_DataContext.RollbackNested();
            throw;
              }

              // Sending mail:
              try
              {
            emailSrv.EmailSend(mail.ID);
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
              }
        }
예제 #7
0
        public new void JobAnswerInsert(JobAnswer entity)
        {
            try
              {
            PrincipalPermission permReg = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Registered");
            PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
            permReg.Union(permAdmin).Demand();

            JobAnswer ja = base.JobAnswerSelect(entity.JobRef, entity.Type, entity.SubscriberNameRef, entity.SenderNameRef);
            if(ja != null)
            {
              if(ja.IsActive)
              throw new ApplicationException("Erre a hirdetésre már válaszolt.");
            }

            //entity.SubscriberNameRef = Thread.CurrentPrincipal.Identity.Name;
            entity.Created = DateTime.Now;
            entity.IsActive = true;
            if (ja == null)
            {
              base.JobAnswerInsert(entity);
            }
            else
            {
              ja = entity;
              base.JobAnswerUpdate(ja);
            }
            //értesítjük a feladót, hogy valaki válaszolt a hirdetésére
            //set mail:
            Email mail = new Email(Guid.NewGuid());
            //Subject és body lekérdezése
            string body = "";
            string subject = "";
            EmailTemplateService srvTemplate = new EmailTemplateService();
            srvTemplate.GetEmailTemplateByCode(ref subject, ref body, EmailCategory.JobAnswerCreated);
            mail.Category = EmailCategory.JobAnswerCreated;
            mail.Subject = subject;
            UserService srvUser = new UserService();
            User subscriber = srvUser.UserSelect(entity.SubscriberNameRef);
            //Ha keresés hirdetésre jelentkezett valaki
            if (entity.Type == JobAnswerTypeEnum.FIN)
            {
              User sender = srvUser.UserSelect(entity.SenderNameRef);

              if (sender != null && sender.Email.Length > 0)
              {
            JobFindService srvJob = new JobFindService();
            JobFind find = srvJob.JobFindSelect(entity.JobRef);
            mail.To = sender.Email;
            body = body.Replace("<FULL_USER_NAME>", sender.Name);
            if (find != null)
            {
              body = body.Replace("<JOB_REFID>", find.RefId.ToString());
              body = body.Replace("<JOB_DESCRIPTION>", find.Description);
            }
              }
            }
            else
            {
              //ajánlat
              JobOfferService srvJob = new JobOfferService();
              JobOffer offer = srvJob.JobOfferSelect(entity.JobRef);
              if (offer != null && offer.ContactEmail.Length > 0)
              {
            mail.To = offer.ContactEmail;
            body = body.Replace("<FULL_USER_NAME>", offer.ContactName);
            body = body.Replace("<JOB_REFID>", offer.RefId.ToString());
            body = body.Replace("<JOB_DESCRIPTION>", offer.Description);
              }
            }
            if (subscriber != null)
            {
              body = body.Replace("<SUBSCRIBER_NAME>", subscriber.Name);
              body = body.Replace("<SUBSCRIBER_MAIL>", subscriber.Email);
              body = body.Replace("<MOTIVATION>", entity.Motivation);
            }

            mail.MailBody = body;

            if (mail.MailBody != null && mail.To != null && mail.Subject != null)
            {
              // Save data to database
              EmailService emailSrv = new EmailService(m_DataContext);
              m_DataContext.BeginNestedTran();
              try
              {
            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;
              }
            }
            // Log success
            BusinessAuditEvent.Success(
              new EventParameter("JobRef", entity.JobRef.ToString()),
              new EventParameter("OrganisationID", Thread.CurrentPrincipal.Identity.Name)
              );
            TraceCallReturnEvent.Raise();
            return;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("JobRef", entity.JobRef.ToString()),
              new EventParameter("OrganisationID", Thread.CurrentPrincipal.Identity.Name)
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
예제 #8
0
        public bool RegisterUserAccept(RegisterUser entity)
        {
            //Check permission: Admin
              PrincipalPermission permissionAdm =
            new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
              permissionAdm.Demand();

              TraceCallEnterEvent.Raise();
              try
              {
            // Check required fields
            if (entity.LoginName.Length == 0)
              throw new ArgumentNullException("RegisterUser.LoginName",
                                          "A regisztrálandó felhasználó bejelentkezési neve nincs megadva.");
            if (entity.Name.Length == 0)
              throw new ArgumentNullException("RegisterUser.Name", "A regisztrálandó felhasználó neve nincs megadva.");
            if (entity.Sex.Length == 0)
              throw new ArgumentNullException("RegisterUser.Sex", "A regisztrálandó felhasználó neme nincs megadva.");
            if (entity.BirthYear.Length == 0)
              throw new ArgumentNullException("RegisterUser.BirthYear",
                                          "A regisztrálandó felhasználó születési éve nincs megadva.");
            if (entity.Email.Length == 0)
              throw new ArgumentNullException("RegisterUser.Email",
                                          "A regisztrálandó felhasználó e-mail címe nincs megadva.");
            if (entity.QualificationRef.Length == 0)
              throw new ArgumentNullException("RegisterUser.QualificationRef",
                                          "A regisztrálandó felhasználó legmagasabb iskolai végzettsége nincs megadva.");
            if (entity.ReasonOfRegistration.Length == 0)
              throw new ArgumentNullException("RegisterUser.ReasonOfRegistration",
                                          "Az adatbázis használatának célja nincs megadva.");
            if (entity.Right.Length == 0)
              throw new ArgumentNullException("RegisterUser.Right", "A jogosultság nincs megadva.");

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

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

            User newUser = new User(entity.LoginName);
            string generatedPassword = Password.Generate();
            newUser.Password = Password.ComputeHash(generatedPassword);

            newUser.OrganisationRef = entity.OrganisationRef;
            newUser.Name = entity.Name;
            newUser.Sex = entity.Sex;
            newUser.BirthYear = entity.BirthYear;
            newUser.Phone = entity.Phone;
            newUser.Email = entity.Email;
            newUser.PostCode = entity.PostCode;
            newUser.City = entity.City;
            newUser.Address = entity.Address;
            newUser.Country = entity.Country;
            newUser.QualificationRef = entity.QualificationRef;
            newUser.ReasonOfRegistration = entity.ReasonOfRegistration;
            newUser.Right = entity.Right;
            newUser.IsActive = true;
            newUser.NewsMail = entity.NewsMail;
            newUser.MustChangePassword = true;
            newUser.LockedOut = false;
            newUser.FailedAttemptCount = 0;

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

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

            mail.Subject = subject;

            body = body.Replace("<FULL_USER_NAME>", entity.Name);
            body = body.Replace("<LOGIN_NAME>", entity.LoginName);
            body = body.Replace("<PASSWORD>", generatedPassword);
            mail.MailBody = body;

            // Save data to database
            EmailService emailSrv = new EmailService(m_DataContext);
            m_DataContext.BeginNestedTran();
            try
            {
              UserServiceBase userSrv = new UserServiceBase(m_DataContext);
              userSrv.UserInsert(newUser);
              base.RegisterUserUpdate(entity);
              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("RegisterUserID", entity.ID.ToString()),
              new EventParameter("LoginName", entity.LoginName)
              );
            TraceCallReturnEvent.Raise();
            return true;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("RegisterUserID", entity.ID.ToString()),
              new EventParameter("LoginName", entity.LoginName)
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
        public bool PendingQuestionFormSendBackNew(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.RejectComment.Length == 0)
              throw new ArgumentNullException("PendingQuestionForm.RejectComment", "A visszaküldés indoklása 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
            selected.DecidedBy = Thread.CurrentPrincipal.Identity.Name;
            selected.DecidedDate = DBDateTime.Now;
            selected.Status = QuestionFormStatus.New_SendBack;
            selected.RejectComment = entity.RejectComment;
            selected.QuestionFormRef = entity.QuestionFormRef;
            selected.IsActual = false;
            //Set mail:
            UserService userSrv = new UserService(m_DataContext);
            User sentBy = userSrv.UserSelect(selected.SentBy);
            Email mail = new Email(Guid.NewGuid());
            mail.Category = EmailCategory.QuestionFormInsertSendBack;
            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.QuestionFormInsertSendBack);

            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("<REJECT_COMMENT>", entity.RejectComment);
            mail.MailBody = body;

            // Save data to database
            EmailService emailSrv = new EmailService(m_DataContext);
            m_DataContext.BeginNestedTran();
            try
            {
              base.PendingQuestionFormUpdate(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("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 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 bool RegisterOrganisationToUserAccept(RegisterOrganisation entity)
        {
            //Check permission: Admin
              PrincipalPermission permissionAdm =
            new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
              permissionAdm.Demand();

              TraceCallEnterEvent.Raise();
              try
              {
            // Check required fields
            // Organisation
            if (entity.Name.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.Name", "A regisztrálandó szervezet neve nincs megadva.");
            if (entity.RegionRef.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.RegionRef",
                                          "A regisztrálandó szervezet megyéje nincs megadva.");
            if (entity.WorkingAreaRef.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.WorkingAreaRef",
                                          "A regisztrálandó szervezet mûködési területe nincs megadva.");
            if (entity.OrganisationFormRef.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.OrganisationFormRef",
                                          "A regisztrálandó szervezet szervezeti formája nincs megadva.");
            if (entity.ReasonOfRegistration.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.ReasonOfRegistration",
                                          "Az adatbázis használatának célja nincs megadva.");
            if (entity.PostCode.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.PostCode",
                                          "A szervezet címének irányítószáma nincs megadva.");
            if (entity.City.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.City",
                                          "A szervezet címének település része nincs megadva.");
            if (entity.Address.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.Address",
                                          "A szervezet címének utca, házszám része nincs megadva.");

            // User
            if (entity.LoginName.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.LoginName",
                                          "A regisztrálandó felhasználó bejelentkezési neve nincs megadva.");
            if (entity.UserName.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.UserName",
                                          "A regisztrálandó felhasználó neve nincs megadva.");
            if (entity.UserSex.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.UserSex",
                                          "A regisztrálandó felhasználó neme nincs megadva.");
            if (entity.UserBirthYear.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.UserBirthYear",
                                          "A regisztrálandó felhasználó születési éve nincs megadva.");
            if (entity.UserEmail.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.UserEmail",
                                          "A regisztrálandó felhasználó e-mail címe nincs megadva.");
            if (entity.QualificationRef.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.QualificationRef",
                                          "A regisztrálandó felhasználó legmagasabb iskolai végzettsége nincs megadva.");

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

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

            Organisation newOrg = new Organisation(entity.ID);
            newOrg.Name = entity.Name;
            newOrg.Department = entity.Department;
            newOrg.PostCode = entity.PostCode;
            newOrg.City = entity.City;
            newOrg.Address = entity.Address;
            newOrg.Country = entity.Country;
            newOrg.Phone1 = entity.Phone1;
            newOrg.Fax = entity.Fax;
            newOrg.Email1 = entity.Email1;
            newOrg.HomePage = entity.HomePage;
            newOrg.RegionRef = entity.RegionRef;
            newOrg.WorkingAreaRef = entity.WorkingAreaRef;
            newOrg.WorkingAreaOther = entity.WorkingAreaOther;
            newOrg.OrganisationFormRef = entity.OrganisationFormRef;
            newOrg.ActivityPrevention = entity.ActivityPrevention;
            newOrg.ActivityRehabilitation = entity.ActivityRehabilitation;
            newOrg.ActivityResearch = entity.ActivityResearch;
            newOrg.ActivityOther = entity.ActivityOther;
            newOrg.SourceGovernment = 0;
            newOrg.SourceCompetition = 0;
            newOrg.SourceSponsor = 0;
            newOrg.SourceDonation = 0;
            newOrg.SourceTax = 0;
            newOrg.SourceOther = 0;
            newOrg.IsActive = true;
            // defaults
            newOrg.WorkersFix = 0;
            newOrg.WorkersExternal = 0;
            newOrg.WorkersVolunteer = 0;
            newOrg.JobPsychologist = 0;
            newOrg.JobPsychiater = 0;
            newOrg.JobDoctor = 0;
            newOrg.JobMedicalExpert = 0;
            newOrg.JobHealthExpert = 0;
            newOrg.JobSociologist = 0;
            newOrg.JobSocialPolitician = 0;
            newOrg.JobSocialWorker = 0;
            newOrg.JobSocialPedagogist = 0;
            newOrg.JobPedagogist = 0;
            newOrg.JobManualist = 0;
            newOrg.JobLawyer = 0;
            newOrg.JobPoliceman = 0;
            newOrg.JobMentalhygiene = 0;
            newOrg.JobCultureOrganizer = 0;
            newOrg.JobOther1 = 0;
            newOrg.JobOther2 = 0;
            newOrg.JobOther3 = 0;
            newOrg.IsActual = true;
            newOrg.LastModified = DateTime.Now;
            //set mail:
            Email mail = new Email(Guid.NewGuid());
            mail.Category = EmailCategory.OrganisationRegistrationAccept;
            mail.To = entity.UserEmail;

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

            mail.Subject = subject;

            body = body.Replace("<FULL_USER_NAME>", entity.Name);
            body = body.Replace("<LOGIN_NAME>", entity.LoginName);
            body = body.Replace("<ORGANIZATION>", newOrg.Name);

            mail.MailBody = body;

            // Save data to database
            EmailService emailSrv = new EmailService(m_DataContext);
            m_DataContext.BeginNestedTran();
            try
            {
              //elmentjük a szervezet adatait
              OrganisationService orgSrv = new OrganisationService(m_DataContext);
              orgSrv.OrganisationInsert(newOrg);

              //eltároljuk a szervezet-felhasználó kapcsolatot
              OrganisationUserService orgUserSrv = new OrganisationUserService(m_DataContext);
              OrganisationUser orgUser = new OrganisationUser(newOrg.ID, entity.LoginName);
              orgUser.Right = UserRights.Write;
              orgUserSrv.OrganisationUserInsert(orgUser);

              base.RegisterOrganisationUpdate(entity);
              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("OrganisationID", newOrg.ID.ToString()),
              new EventParameter("OrganisationName", entity.Name),
              new EventParameter("LoginName", entity.LoginName)
              );
            TraceCallReturnEvent.Raise();
            return true;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("RegisterOrganisationID", entity.ID.ToString()),
              new EventParameter("OrganisationName", entity.Name),
              new EventParameter("LoginName", entity.LoginName)
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }
        public bool RegisterKefOrganisation(RegisterOrganisation entity, string regSearchCode, DBInt disSearchCode,
                                        string estYear, string estMonth, string areaHomePage)
        {
            //Check permission: Admin
              PrincipalPermission permissionAdm =
            new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator");
              permissionAdm.Demand();

              TraceCallEnterEvent.Raise();
              try
              {
            // Check required fields
            // Organisation
            if (entity.Name.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.Name", "A regisztrálandó szervezet neve nincs megadva.");
            if (entity.RegionRef.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.RegionRef",
                                          "A regisztrálandó szervezet megyéje nincs megadva.");
            if (entity.WorkingAreaRef.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.WorkingAreaRef",
                                          "A regisztrálandó szervezet mûködési területe nincs megadva.");
            if (entity.OrganisationFormRef.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.OrganisationFormRef",
                                          "A regisztrálandó szervezet szervezeti formája nincs megadva.");
            if (entity.ReasonOfRegistration.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.ReasonOfRegistration",
                                          "Az adatbázis használatának célja nincs megadva.");
            if (entity.PostCode.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.PostCode",
                                          "A szervezet címének irányítószáma nincs megadva.");
            if (entity.City.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.City",
                                          "A szervezet címének település része nincs megadva.");
            if (entity.Address.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.Address",
                                          "A szervezet címének utca, házszám része nincs megadva.");

            // User
            if (entity.LoginName.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.LoginName",
                                          "A regisztrálandó felhasználó bejelentkezési neve nincs megadva.");
            if (entity.UserName.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.UserName",
                                          "A regisztrálandó felhasználó neve nincs megadva.");
            if (entity.UserSex.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.UserSex",
                                          "A regisztrálandó felhasználó neme nincs megadva.");
            if (entity.UserBirthYear.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.UserBirthYear",
                                          "A regisztrálandó felhasználó születési éve nincs megadva.");
            if (entity.UserEmail.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.UserEmail",
                                          "A regisztrálandó felhasználó e-mail címe nincs megadva.");
            if (entity.QualificationRef.Length == 0)
              throw new ArgumentNullException("RegisterOrganisation.QualificationRef",
                                          "A regisztrálandó felhasználó legmagasabb iskolai végzettsége nincs megadva.");

            Organisation newOrg = new Organisation(entity.ID);
            newOrg.Name = entity.Name;
            newOrg.Department = entity.Department;
            newOrg.PostCode = entity.PostCode;
            newOrg.City = entity.City;
            newOrg.Address = entity.Address;
            newOrg.Country = entity.Country;
            newOrg.Phone1 = entity.Phone1;
            newOrg.Fax = entity.Fax;
            newOrg.Email1 = entity.Email1;
            newOrg.HomePage = entity.HomePage;
            newOrg.RegionRef = entity.RegionRef;
            newOrg.WorkingAreaRef = entity.WorkingAreaRef;
            newOrg.WorkingAreaOther = entity.WorkingAreaOther;
            newOrg.OrganisationFormRef = entity.OrganisationFormRef;
            newOrg.ActivityPrevention = entity.ActivityPrevention;
            newOrg.ActivityRehabilitation = entity.ActivityRehabilitation;
            newOrg.ActivityResearch = entity.ActivityResearch;
            newOrg.ActivityOther = entity.ActivityOther;
            newOrg.SourceGovernment = 0;
            newOrg.SourceCompetition = 0;
            newOrg.SourceSponsor = 0;
            newOrg.SourceDonation = 0;
            newOrg.SourceTax = 0;
            newOrg.SourceOther = 0;
            newOrg.IsActive = true;
            // defaults
            newOrg.WorkersFix = 0;
            newOrg.WorkersExternal = 0;
            newOrg.WorkersVolunteer = 0;
            newOrg.JobPsychologist = 0;
            newOrg.JobPsychiater = 0;
            newOrg.JobDoctor = 0;
            newOrg.JobMedicalExpert = 0;
            newOrg.JobHealthExpert = 0;
            newOrg.JobSociologist = 0;
            newOrg.JobSocialPolitician = 0;
            newOrg.JobSocialWorker = 0;
            newOrg.JobSocialPedagogist = 0;
            newOrg.JobPedagogist = 0;
            newOrg.JobManualist = 0;
            newOrg.JobLawyer = 0;
            newOrg.JobPoliceman = 0;
            newOrg.JobMentalhygiene = 0;
            newOrg.JobCultureOrganizer = 0;
            newOrg.JobOther1 = 0;
            newOrg.JobOther2 = 0;
            newOrg.JobOther3 = 0;

            //It's a KEF -> set KEF specific data
            newOrg.IsKef = true;
            newOrg.RegionSearchCodeRef = regSearchCode;
            newOrg.DistrictSearchCodeRef = disSearchCode;
            newOrg.EstablishmentYear = estYear;
            newOrg.EstablishmentMonth = estMonth;
            newOrg.AreaHomePage = areaHomePage;
            newOrg.IsActual = true;
            newOrg.LastModified = DateTime.Now;

            //save the user
            User newUser = new User(entity.LoginName);
            newUser.OrganisationRef = entity.ID;

            string generatedPassword = Password.Generate();
            newUser.Password = Password.ComputeHash(generatedPassword);

            newUser.Address = entity.UserAddress;
            newUser.Name = entity.UserName;
            newUser.Sex = entity.UserSex;
            newUser.BirthYear = entity.UserBirthYear;
            newUser.Phone = entity.UserPhone;
            newUser.Email = entity.UserEmail;
            newUser.PostCode = entity.UserPostCode;
            newUser.City = entity.UserCity;
            newUser.Address = entity.UserAddress;
            newUser.Country = entity.UserCountry;
            newUser.QualificationRef = entity.QualificationRef;
            newUser.ReasonOfRegistration = entity.ReasonOfRegistration;
            newUser.Right = UserRights.Write;
            newUser.IsActive = true;
            newUser.NewsMail = false;
            newUser.MustChangePassword = true;
            newUser.FailedAttemptCount = 0;
            newUser.LockedOut = false;

            //set mail:
            Email mail = new Email(Guid.NewGuid());
            mail.Category = EmailCategory.OrganisationRegistrationAccept;
            mail.To = entity.UserEmail;

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

            mail.Subject = subject;

            body = body.Replace("<FULL_USER_NAME>", entity.Name);
            body = body.Replace("<LOGIN_NAME>", entity.LoginName);
            body = body.Replace("<ORGANIZATION>", newOrg.Name);
            body = body.Replace("<PASSWORD>", generatedPassword);
            mail.MailBody = body;

            // Save data to database
            EmailService emailSrv = new EmailService(m_DataContext);
            m_DataContext.BeginNestedTran();
            try
            {
              UserServiceBase userSrv = new UserServiceBase(m_DataContext);
              OrganisationService orgSrv = new OrganisationService(m_DataContext);
              orgSrv.OrganisationInsert(newOrg);
              userSrv.UserInsert(newUser);
              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("OrganisationID", newOrg.ID.ToString()),
              new EventParameter("OrganisationName", entity.Name),
              new EventParameter("LoginName", entity.LoginName)
              );
            TraceCallReturnEvent.Raise();
            return true;
              }
              catch (Exception ex)
              {
            ExceptionManager.Publish(ex);
            BusinessAuditEvent.Fail(
              new EventParameter("Exception", ex.ToString()),
              new EventParameter("RegisterOrganisationID", entity.ID.ToString()),
              new EventParameter("OrganisationName", entity.Name),
              new EventParameter("LoginName", entity.LoginName)
              );
            TraceCallReturnEvent.Raise(false);
            throw;
              }
        }