public async Task <BaseApiResponse> AddExpressAddress(AddExpressAddressRequest request) { TryInitUserModel(); request.CheckNotNull(nameof(request)); if (!request.Mobile.IsMobileNumber()) { return(new BaseApiResponse { Code = 400, Message = "请输入正确的手机号" }); } var expressAddressViewModel = new ExpressAddressViewModel { UserId = _user.Id, Mobile = request.Mobile, Name = request.Name, Region = request.Region, Address = request.Address, Zip = request.Zip }; var command = expressAddressViewModel.ToAddExpressAddressCommand(); var result = await ExecuteCommandAsync(command); if (!result.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } return(new BaseApiResponse()); }
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); }
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()); }