/// <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; }
partial void DeleteGenre(Genre instance);
partial void UpdateGenre(Genre instance);
partial void InsertGenre(Genre instance);
private void detach_Genres(Genre entity) { this.SendPropertyChanging(); entity.Media_type1 = null; }