/// <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 = AccountBuilder.ToMAccount(account); 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); }
/// <summary> /// 删除用户 /// </summary> /// <param name="userId">用户信息</param> /// <param name="operational">操作信息</param> /// <returns>结果</returns> public static Result RemoveUser(Guid userId, Operational operational) { Result result = new Result(); try { using (var accountesRepository = DbContext.CreateIAccountesRepository()) { var mAccount = AccountBuilder.ToMAccount(userId); accountesRepository.Remove(mAccount); } result.IsSucceed = true; result.Message = "删除成功"; } catch (Exception ex) { result.IsSucceed = false; result.Message = Const.ErrorMessage; LogService.WriteLog(ex, "删除用户"); } return(result); }
/// <summary> /// 添加用户 /// </summary> /// <param name="registerAccount">用户信息</param> /// <param name="operational">操作信息</param> /// <returns>结果</returns> public static Result AddUser(RegisterAccount registerAccount, Operational operational) { Result result = new Result(); try { // 创建用户对象 var account = new Account(registerAccount); account.AddUser(); // 将领域对象转化成数据库实体对象 var mAccount = AccountBuilder.ToMAccount(account); using (var accountesRepository = DbContext.CreateIAccountesRepository()) { accountesRepository.Add(mAccount); } result.IsSucceed = true; result.Message = "添加成功"; } catch (CustomException ex) { result.IsSucceed = false; result.Message = ex.Message; } catch (Exception ex) { result.IsSucceed = false; result.Message = "添加失败"; // 记录异常日志 LogService.WriteLog(ex, "添加用户"); } return(result); }