コード例 #1
0
        public async Task <IdentityResult> CreateNewUser(ApplicationUser user, string password, string requestedOrganization)
        {
            var userSettings =
                _organizationDbSet.Where(o => o.ShortName == requestedOrganization)
                .Select(u => new { u.CultureCode, u.TimeZone })
                .First();

            user.OrganizationId        = _organizationService.GetOrganizationByName(requestedOrganization).Id;
            user.EmploymentDate        = DateTime.UtcNow;
            user.CultureCode           = userSettings.CultureCode ?? ConstBusinessLayer.DefaultCulture;
            user.TimeZone              = userSettings.TimeZone;
            user.NotificationsSettings = null;

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

            if (!result.Succeeded)
            {
                return(result);
            }

            var userLoginInfo  = new UserLoginInfo(AuthenticationConstants.InternalLoginProvider, user.Id);
            var addLoginResult = await _userManager.AddLoginAsync(user.Id, userLoginInfo);

            if (!addLoginResult.Succeeded)
            {
                return(addLoginResult);
            }

            AddNewUserRoles(user.Id);

            await SendUserVerificationEmail(user, requestedOrganization);

            return(result);
        }