Ejemplo n.º 1
0
 public async Task <BaseApiResult <bool> > Excute(AccountCreateDto input)
 {
     return(await HandleAsync(input, async() =>
     {
         using (var tran = transaction.BeginTransaction())
         {
             //工厂构建用户领域对象
             var user = new UserFactory().CreateUser(input.Account);
             //调用领域对象创建密码
             user.CreatePassword(globalTool.GetMD5SaltCode(input.Password, user.Id.ToString()));
             //调用规约校验
             if (await new CreateUserSpecification(userRepository).SatisfiedBy(user))
             {
                 //仓储添加
                 userRepository.Add(user);
                 //发送用户创建成功事件
                 await eventBus.PublishAsync("EshopSample.UserCreateEvent", new UserCreateEvent(user.Id));
                 //工作单元持久化
                 await userRepository.SaveAsync();
                 tran.Commit();
                 return true;
             }
             else
             {
                 return false;
             }
         }
     }));
 }
Ejemplo n.º 2
0
 public async Task <BaseApiResult <UserLoginResponse> > Excute(UserLoginDto input)
 {
     return(await HandleAsync(input, async() =>
     {
         //仓储返回领域对象
         var user = await userRepository.GetAsync(x => x.Account.Equals(input.Account));
         if (user == null)
         {
             throw new ApplicationException("用户名或密码错误");
         }
         //调用领域对象校验是否可以登录
         if (user.CheckLogin(globalTool.GetMD5SaltCode(input.Password, user.Id.ToString())))
         {
             //远程调用用户金额服务
             return new UserLoginResponse()
             {
                 UserId = user.Id,
                 Account = input.Account,
                 Balance = (await getMyAccountBalance.Query(new MyAccountBalanceDto()
                 {
                     UserId = user.Id
                 })).Data.Balance                                                                                         //获取用户余额
             };
         }
         return null;
     }));
 }