Example #1
0
        /// <author>Per Mortensen</author>
        /// <summary>
        /// Adds a new genre to the database, if it doesn't already exist.
        /// </summary>
        /// <param name="genreName">The name of the new genre.</param>
        /// <param name="mediaType">The media type for which the new genre will be available.</param>
        /// <returns>The id of the newly added genre. If the genre already exists, the
        /// existing genre id is returned.</returns>
        public static int AddGenre(string genreName, MediaType mediaType)
        {
            var db = new DatabaseDataContext();

            // Get media type id
            int mediaTypeId = (from t in db.Media_types
                               where t.name.Equals(StringValueOfMediaType(mediaType))
                               select t).Single().id;

            // Check if genre already exists for the given media type
            if (db.Genres.Exists(g => g.media_type == mediaTypeId && g.name.ToLower().Equals(genreName.ToLower())))
                return (from g in db.Genres
                        where g.media_type == mediaTypeId && g.name.ToLower().Equals(genreName.ToLower())
                        select g).Single().id; // Genre and media type combination already exists, return its genre id

            // add genre to database
            var newGenre = new RentItDatabase.Genre { media_type = mediaTypeId, name = genreName };
            db.Genres.InsertOnSubmit(newGenre);
            db.SubmitChanges();

            // Return the newly added genre id
            return newGenre.id;
        }
Example #2
0
 partial void DeleteGenre(Genre instance);
Example #3
0
 partial void UpdateGenre(Genre instance);
Example #4
0
 partial void InsertGenre(Genre instance);
Example #5
0
 private void detach_Genres(Genre entity)
 {
     this.SendPropertyChanging();
     entity.Media_type1 = null;
 }