Пример #1
0
 private static void Register()
 {
     RegisterAccount registerAccount = new RegisterAccount
     {
         AccountName = "夜未U",
         AccountNO = "225654454",
         Mail = "*****@*****.**",
         Mobile = "ssss",
         Password = "******",
         PayPassword = null,
     };
     var rel = AccountService.Register(registerAccount);
 }
Пример #2
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="registerAccount">注册信息</param>
        /// <returns>注册结果</returns>
        public static Result Register(RegisterAccount registerAccount)
        {
            Result result = new Result();
            try
            {
                // 创建用户对象 执行注册方法和创建验证码方法
                var account = new Account(registerAccount);
                account.Register();

                // 将领域对象转化成数据库实体对象
                var mAccount = account.ToMAccount();
                var mVerificationCode = account.VerificationCode.ToMVerificationCode();

                // 通过工资单元持久化数据
                using (var unit = DbContext.CreateIPowerUnitOfWork())
                {
                    var accountesRepository = DbContext.CreateIAccountesRepository(unit);
                    var verificationCodeRepository = DbContext.CreateIVerificationCodeRepository(unit);

                    accountesRepository.Add(mAccount);
                    verificationCodeRepository.Add(mVerificationCode);

                    unit.Complete();
                }

                result.IsSucceed = true;

                // 异步调用发送邮件的方法
                Task.Factory.StartNew(() =>
                {
                    RegisterSendMail(account);
                });
            }
            catch (CustomException ex)
            {
                result.IsSucceed = false;
                result.Message = ex.Message;
            }
            catch (Exception ex)
            {
                result.IsSucceed = false;
                result.Message = "注册失败";

                // 记录异常日志
                LogService.WriteLog(ex, "注册帐号");
            }
            return result;
        }