private void InsertEveryMailAccountFor(Employee theEmployee) { foreach (MailAccount ma in theEmployee.TheMailAccounts) { SqlCommand cmd1 = new SqlCommand(); cmd1.Parameters.Add(_PKID, SqlDbType.Int).Direction = ParameterDirection.Output; cmd1.Parameters.Add(_EmployeeID, SqlDbType.Int).Value = theEmployee.Account.Id; cmd1.Parameters.Add(_LoginName, SqlDbType.NVarChar, 255).Value = ma.LoginName; cmd1.Parameters.Add(_Password, SqlDbType.NVarChar, 255).Value = DalUtility.EncryptThePassword(ma.Password, ma.LoginName); cmd1.Parameters.Add(_ConfigurationId, SqlDbType.Int, 255).Value = ma.TheMailConfiguration.Id; int pkidOut; SqlHelper.TransExecuteNonQueryReturnPKID("InsertAMailAccount", cmd1, _Conn, _Trans, out pkidOut); ma.Id = pkidOut; } }
public void LoadMailAccountsFor(Employee theEmployee) { CheckTheObject(theEmployee); SqlCommand cmd = new SqlCommand(); cmd.Parameters.Add(_EmployeeID, SqlDbType.Int).Value = theEmployee.Account.Id; using (SqlDataReader sdr = SqlHelper.ExecuteReader("GetEmployeeMailAccount", cmd)) { while (sdr.Read()) { MailAccount mailAccount = new MailAccount(sdr[_DBLoginName].ToString(), DalUtility.DecryptPassword(sdr[_DBPassword].ToString(), sdr[_DBLoginName].ToString()), MailConfiguration.GetMailConfigurationById(int.Parse(sdr[_DBConfigurationId].ToString()))); mailAccount.Id = int.Parse(sdr[_DBPKID].ToString()); theEmployee.TheMailAccounts.Add(mailAccount); } } }