Beispiel #1
0
        public IdentityOperationResult GetResult(bool success, IEnumerable <string> messages = null)
        {
            var result = new IdentityOperationResult(success);

            if (messages != null && messages.Any())
            {
                foreach (var message in messages)
                {
                    result.AddError(message);
                }
            }

            return(result);
        }
Beispiel #2
0
        public async Task <IdentityOperationResult> SetupUser(Credential credential)
        {
            var roles   = memberQuery.GetMembersByEmail(club.Guid, credential.Email).Select(m => m.Membership).Distinct();
            var newUser = new ApplicationUser {
                UserName = credential.Email, Email = credential.Email
            };

            try {
                var result = await userManager.CreateAsync(newUser, credential.Password);

                if (result.Succeeded)
                {
                    foreach (var role in roles)
                    {
                        var roleResult = await userManager.AddToRoleAsync(newUser, role.ToString().ToLowerInvariant());

                        if (!roleResult.Succeeded)
                        {
                            var operationResult = new IdentityOperationResult(false);
                            foreach (var e in result.Errors)
                            {
                                operationResult.AddError(e.Description);
                            }

                            return(operationResult);
                        }
                    }
                    return(new IdentityOperationResult(true));
                }
                else
                {
                    var operationResult = new IdentityOperationResult(false);
                    foreach (var e in result.Errors)
                    {
                        operationResult.AddError(e.Description);
                    }

                    return(operationResult);
                }
            }catch (Exception ex) {
                var operationResult = new IdentityOperationResult(false);
                operationResult.AddError(ex.Message);
                return(operationResult);
            }
        }