Beispiel #1
0
 public void Handle(ICommandContext context, AddExpressAddressCommand command)
 {
     context.Get <User>(command.AggregateRootId).AddExpressAddress(new ExpressAddressInfo(
                                                                       command.Region,
                                                                       command.Address,
                                                                       command.Name,
                                                                       command.Mobile,
                                                                       command.Zip
                                                                       ));
 }
        public static AddExpressAddressCommand ToAddExpressAddressCommand(this ExpressAddressViewModel expressAddressViewModel)
        {
            var command = new AddExpressAddressCommand(expressAddressViewModel.UserId,
                                                       expressAddressViewModel.Name,
                                                       expressAddressViewModel.Mobile,
                                                       expressAddressViewModel.Region,
                                                       expressAddressViewModel.Address,
                                                       expressAddressViewModel.Zip);

            return(command);
        }
Beispiel #3
0
        public async Task <BaseApiResponse> AddExpressAddress([FromBody] AddExpressAddressRequest request)
        {
            var currentAccount = _contextService.GetCurrentAccount(HttpContext);

            request.CheckNotNull(nameof(request));
            if (!request.Mobile.IsMobileNumber())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "请输入正确的手机号"
                });
            }

            var expressAddressViewModel = new ExpressAddressViewModel
            {
                UserId  = currentAccount.UserId.ToGuid(),
                Mobile  = request.Mobile,
                Name    = request.Name,
                Region  = request.Region,
                Address = request.Address,
                Zip     = request.Zip
            };
            var command = new AddExpressAddressCommand(currentAccount.UserId.ToGuid(),
                                                       request.Name,
                                                       request.Mobile,
                                                       request.Region,
                                                       request.Address,
                                                       request.Zip);
            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            return(new BaseApiResponse());
        }