コード例 #1
0
        public async Task <string> RegisterAsync(UserModel userModel, string password)
        {
            var user = new User
            {
                UserName          = userModel.UserName,
                Email             = userModel.Email,
                DefaultCurrencyID = userModel.DefaultCurrencyID
            };
            var result = await _userManager.CreateAsync(user, password);

            if (result.Succeeded)
            {
                _categoryService.AddDefaultCategories(user.Id);
                _emailSenderService.SendRegistrationEmail(user.Email);
            }
            else
            {
                string _errors = string.Empty;
                foreach (var error in result.Errors)
                {
                    _errors = $"{_errors}{error};";
                }

                throw new Exception(_errors);
            }

            return(user.Id);
        }