public async Task <ApplicationRole> FindByIdAsync(int roleId) { ApplicationRole role = new ApplicationRole(); using (SqlCommand cmd = _context.CreateCommand()) { cmd.CommandText = @"SELECT Id, Name FROM ApplicationRole WHERE Name = @roleId "; cmd.Parameters.AddWithValue("@roleId", roleId); cmd.CommandType = CommandType.Text; using (SqlDataReader reader = await cmd.ExecuteReaderAsync(CommandBehavior.SequentialAccess)) { while (await reader.ReadAsync()) { role.Id = await reader.GetFieldValueAsync <int>(0); role.Name = await reader.GetTextReader(1).ReadToEndAsync(); } } } return(role); }
public async Task CreateAsync(ApplicationUser user) { using (SqlCommand cmd = _context.CreateCommand()) { cmd.CommandText = @" INSERT INTO ApplicationUser ( UserName, Title, Name, Surname, Cellphone, HomeAddress, PasswordHash) VALUES ( @UserName, @Title, @Name, @surname, @Cellphone, @HomeAddress, @PasswordHash)"; cmd.Parameters.AddWithValue("@UserName", user.UserName); cmd.Parameters.AddWithValue("@Title", user.Title); cmd.Parameters.AddWithValue("@Name", user.Name); cmd.Parameters.AddWithValue("@Surname", user.Surname); cmd.Parameters.AddWithValue("@Cellphone", user.Cellphone); cmd.Parameters.AddWithValue("@HomeAddress", user.HomeAddress); cmd.Parameters.AddWithValue("@PasswordHash", user.PasswordHash); await cmd.ExecuteNonQueryAsync(); } }