Пример #1
0
        public async Task <User> MakeAsync(AdminCreateUserDto model)
        {
            model.CheckArgumentIsNull(nameof(model));
            var user = new User {
                Description  = model.Description,
                Email        = model.Email,
                Status       = model.Status,
                WebUrl       = model.WebUrl,
                PhoneNumber  = model.PhoneNumber,
                UserName     = model.UserName,
                RegisterDate = _dateService.UtcNow(),
                Title        = model.Title
            };

            return(await Task.FromResult(user));
        }
Пример #2
0
        public async Task CreateAsync(AdminCreateUserDto model)
        {
            model.CheckArgumentIsNull(nameof(model));
            var user = await _userManager.FindByNameAsync(model.UserName);

            if (user != null)
            {
                throw new UserNameExistException();
            }

            user = await _factory.MakeAsync(model);

            var result = await _userManager.CreateAsync(user, model.Password);

            if (result == IdentityResult.Failed())
            {
                var msg = $"User Registration failed : {result.DumpErrors()}";
                throw new UserRegistrationException(message: msg);
            }

            await _userManager.AddClaimAsync(user, new Claim(
                                                 "WebsiteId", _websiteInfo.Id.ToString()
                                                 ));
        }