コード例 #1
0
        public async Task <CreateAccountVm> Handle(CreateAccountCommand request, CancellationToken cancellationToken)
        {
            CreateAccountVm vm          = new CreateAccountVm();
            bool            emailExists = await _identityService.AccountExistsByEmailAsync(request.Email);

            if (emailExists)
            {
                vm.Errors = new List <string>()
                {
                    "Account with this email already exists"
                };
                return(vm);
            }
            var auth = await _identityService.CreateAccountAsync(request.Email, request.Password, request.Name);

            if (auth.Result)
            {
                vm.Result = true;
                vm.Token  = auth.Token;
            }
            else
            {
                vm.Errors = auth.Errors;
            }
            return(vm);
        }