예제 #1
0
        /// <summary>
        /// Get all genres.
        /// </summary>
        /// <returns>The genre collection.</returns>
        public IList<Genre> Get()
        {
            using (PlanetWrox.GenreDataTable dtGenre = new PlanetWrox.GenreDataTable())
            using (GenreTableAdapter adptGenre = new GenreTableAdapter())
            {
                adptGenre.Fill(dtGenre);

                if (dtGenre != null && dtGenre.Rows.Count > 0)
                {
                    IEnumerable<Genre> genres = from drGenre in dtGenre
                                                select new Genre
                                                {
                                                    Id = drGenre.Id,
                                                    Name = drGenre.Name,
                                                    SortOrder = drGenre.SortOrder
                                                };

                    return genres.ToList();
                }
            }
            return null;
        }
예제 #2
0
        /// <summary>
        /// Get genre by id.
        /// </summary>
        /// <param name="genreId">The genre id.</param>
        /// <returns>The genre object.</returns>
        public Genre Get(int genreId)
        {
            using (PlanetWrox.GenreDataTable dtGenre = new PlanetWrox.GenreDataTable())
            using (GenreTableAdapter adptGenre = new GenreTableAdapter())
            {
                adptGenre.FillById(dtGenre, genreId);

                if (dtGenre != null && dtGenre.Rows.Count > 0)
                {
                    Genre genre = (from drGenre in dtGenre
                                   select new Genre
                                   {
                                       Id = drGenre.Id,
                                       Name = drGenre.Name,
                                       SortOrder = drGenre.SortOrder
                                   }).Single();

                    return genre;
                }
            }
            return null;
        }