public void InsertRole(Role role) { _context.CreateCommand( false, CommandType.Text, "INSERT INTO [Roles] ([RoleName],[IsEnabled]) OUTPUT INSERTED.RoleId VALUES (@RoleName, 1);", new List <SqlParameter> { new SqlParameter("@RoleName", role.RoleName) } ); var output = _context.ExecuteScalar(); role.RoleId = AdoConverter.ReadResult(output, -1); }
public void InsertUser(User newUser) { _context.CreateCommand( false, CommandType.Text, "INSERT INTO [USERS] ([Username], [Password], [DisplayName], [Culture], [RoleId], [IsEnabled]) OUTPUT INSERTED.UserId VALUES (@Username, @Password, @DisplayName, @Culture, @RoleId, 1);", new List <SqlParameter> { new SqlParameter("@username", newUser.Username), new SqlParameter("@password", newUser.Password), new SqlParameter("@DisplayName", newUser.DisplayName), new SqlParameter("@Culture", newUser.Culture), new SqlParameter("@RoleId", newUser.Role.RoleId) } ); var output = _context.ExecuteScalar(); newUser.UserId = AdoConverter.ReadResult <Int64>(output, -1); //output.Value as int? ?? default(int); }