public override BookContainer <Detective> GetAll(string type = null, BookContainer <Detective> section = null, int?sectionId = null) { DetectiveSection books = new DetectiveSection(); base.GetAll("Detective", books, 1); return(GetDetectives(books, type, section, sectionId)); }
public override BookContainer <Detective> Search(string text, BookFilter filter, string type = null, BookContainer <Detective> section = null, int?sectionId = null) { DetectiveSection books = new DetectiveSection(); base.Search(text, filter, "Detective", books, 1); return(GetDetectives(books, type, section, sectionId)); }
private BookContainer <Detective> GetDetectives(DetectiveSection books, string type, BookContainer <Detective> section, int?sectionId, string query = GetAllDetectivesQuery) { using (SqlConnection connection = new SqlConnection(_connectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand(query, connection)) { using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var bookId = (int)reader["id"]; if (books.Books.FirstOrDefault(b => b.Id == bookId) != null) { books.Books.First(b => b.Id == bookId).HeroesNumber = (int)reader["heroes_number"]; } } return(books); } } } }