Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Problem with my controller when using dapper on Asp.Net Core identity.

$
0
0

my user model

    public class User : IdentityUser
    {

    }

my userStore

public class UserStore : IUserStore<User>
{ private readonly string connectionString; public UserStore() { IConfiguration configuration = null; connectionString = configuration.GetValue<string>("DBInfo:ConnectionString"); } public void Dispose() { } public async Task<IdentityResult> CreateAsync(User user, CancellationToken cancellationToken = default(CancellationToken)) { using (SqlConnection conn = new SqlConnection(connectionString)) { if (user == null) throw new ArgumentNullException("user"); using (SqlConnection connection = new SqlConnection(connectionString)) { await connection.ExecuteAsync("INSERT INTO Users(Id,UserName,Nickname,PasswordHash,SecurityStamp,IsConfirmed,ConfirmationToken,CreatedDate) VALUES(@Id,@UserName,@Nickname,@PasswordHash,@SecurityStamp,@IsConfirmed,@ConfirmationToken,@CreatedDate)", user); } return IdentityResult.Success; } } public Task<string> GetUserIdAsync(User user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult<string>(user.Id); } public Task<string> GetUserNameAsync(User user, CancellationToken cancellationToken = default(CancellationToken)) { return Task.FromResult<string>(user.UserName); } public async Task<IdentityResult> UpdateAsync(User user, CancellationToken cancellationToken = default(CancellationToken)) { if (user == null) throw new ArgumentNullException("user"); using (SqlConnection connection = new SqlConnection(connectionString)) { await connection.ExecuteAsync("UPDATE Users SET UserName = @userName, PasswordHash = @passwordHash, SecurityStamp = @securityStamp WHERE UserId = @userId", user); } return IdentityResult.Success; } public async Task<IdentityResult> DeleteAsync(User user, CancellationToken cancellationToken = default(CancellationToken)) { if (user == null) throw new ArgumentNullException("user"); using (SqlConnection connection = new SqlConnection(connectionString)) { await connection.ExecuteAsync("DELETE FROM Users WHERE UserId = @userId", user); } return IdentityResult.Success; } public async Task<User> FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrWhiteSpace(userId)) throw new ArgumentNullException("userId"); Guid parsedUserId; if (!Guid.TryParse(userId, out parsedUserId)) throw new ArgumentOutOfRangeException("userId", string.Format("'{0}' is not a valid GUID.", new { userId })); using (SqlConnection connection = new SqlConnection(connectionString)) { var user = await connection.QueryAsync<User>("SELECT * FROM Users WHERE Id = @Id", new {userId = parsedUserId}); return user.SingleOrDefault(); //connection.Query<User>("select * from Users where UserId = @userId", new { userId = parsedUserId }).SingleOrDefault(); } } public async Task<User> FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrWhiteSpace(normalizedUserName)) throw new ArgumentNullException("userName"); using (SqlConnection connection = new SqlConnection(connectionString)) { var user = await connection.QueryAsync<User>("SELECT * FROM Users WHERE lower(UserName) = lower(@userName)", new {normalizedUserName}); return user.FirstOrDefault(); } }
}


And the problem is here. In my controller, when trying to use UserManager it says has 9 parameters...but is this an core.identity model, because in asp.identity it doesn't need all arguments.

        public LoginController()
            : this(new UserManager<User>(new UserStore()))
        {
        }

        public LoginController(UserManager<User> userManager)
        {
            this.userManager = userManager;
        }

        public UserManager<User> UserManager { get; private set; }

thanx 


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>