public void Register(Account account) { if (account == null) throw new ArgumentNullException("account"); using (AccountRepository accountRepository = new AccountRepository()) { if (accountRepository.CheckAccountExistByName(account.AccountName)) { // throw account name exists exception throw new AccountIsExistException(string.Format(Resource.ResourceMessage.ex_AccountExist, account.AccountName)); } var accounts = accountRepository.GetFiltered(a => a.Email == account.Email); if (accounts.Count<Account>() > 0) { // throw email exists exception throw new AccountEmailExistException(string.Format(Resource.ResourceMessage.ex_EmailExist, account.Email)); } accounts = accountRepository.GetFiltered(a => a.IdentityCardNumber == account.IdentityCardNumber); if (accounts.Count<Account>() > 0) { // throw IdentityCardNumber exists exception throw new AccountIdCardExistException(string.Format(Resource.ResourceMessage.ex_IdentityCardNumberExist, account.IdentityCardNumber)); } accountService.Register(account); accountRepository.Add(account); accountRepository.Commit(); // send a email to tell use his activation code so that he can activate the account SendMail(account, HostSendMail.EmailCategory.ActivationCode); } }