示例#1
0
 public static DataSet GetLetterDataSet(int personId)
 {
     IDalSession session = NHSessionFactory.CreateSession();
     try
     {
         LetterPrintCommand letterPrintCommand = new LetterPrintCommand(session, "LetterLoginName", "Letters");
         return letterPrintCommand.BuildTestDataSet(session, personId);
     }
     finally
     {
         session.Close();
     }
 }
示例#2
0
        public BatchExecutionResults2 GenerateSendLogins(int[] personKeys)
        {
            BatchExecutionResults2 batchExecutionResults = new BatchExecutionResults2();

            LetterPrintCommand letterPrintCommand = null;
            using (IDalSession session = NHSessionFactory.CreateSession())
            {
                letterPrintCommand = new LetterPrintCommand(session, "LetterLoginName", "Letters");
            }

            int[] filteredPersonKeys = getPersonKeysWhere(personKeys, p => p.NeedsLoginSending);

            foreach (int personKey in filteredPersonKeys)
                generateSendLogin(personKey, false, letterPrintCommand, batchExecutionResults);

            return batchExecutionResults;
        }
示例#3
0
        private void generateSendLogin(int personKey, bool isActive, LetterPrintCommand letterPrintCommand, 
                                       BatchExecutionResults2 batchExecutionResults)
        {
            using (IDalSession session = NHSessionFactory.CreateSession())
            {
                string personErrorString = personKey.ToString();

                try
                {
                    AssertUserHasPermissions(session);

                    LoginPerson loginPerson = GetOwnedLoginPerson(session, personKey);
                    personErrorString = string.Format("{0} ('{1}')", loginPerson.PersonKey, loginPerson.FullName);

                    string userName = generateUniqueUserName(session, loginPerson.ShortNameAlphaCharsOnly, 3, 5);
                    string password = SecurityManager.GeneratePassword(passwordLength);

                    string[] initialClientUserRoleList = loginPerson.InitialClientUserRoleList;

                    loginPerson.AssertAddressIsComplete();
                    loginPerson.AssertHasEmail();
                    SecurityManager.CreateUser(userName, password, loginPerson.Email, isActive);

                    IExternalLogin blankLogin = CreateBlankLogin();
                    blankLogin.UserName = userName;
                    blankLogin.IsActive = isActive;
                    loginPerson.Login = blankLogin;
                    LoginMapper.Insert(session, blankLogin);

                    try
                    {
                        foreach (string roleName in initialClientUserRoleList)
                            SecurityManager.AddUserToRole(userName, roleName);

                        letterPrintCommand.PrintLetter(userName, loginPerson);
                    }
                    catch
                    {
                        deleteLogin(session, loginPerson);
                        throw;
                    }

                    batchExecutionResults.MarkSuccess();
                }
                catch (Exception ex)
                {
                    batchExecutionResults.MarkError(
                        new ApplicationException(string.Format("Error sending login name to {0} {1}.", PersonType, personErrorString), ex));
                }
            }
        }