예제 #1
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 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;
              }
        }