/// <summary> /// Create a new MediaMusic in the database /// </summary> /// <param name="title">The title of the media</param> /// <param name="description">The description</param> /// <param name="artist">The artist</param> /// <param name="genre">The genre</param> /// <param name="tracklist">The tracklist</param> /// <param name="tag">The tag</param> /// <param name="categoryId">The category ID</param> public void CreateMediaMusic(string title, string description, string artist, string genre, string tracklist, string tag, int categoryId) { using (MediathekEntities context = new MediathekEntities()) { MediaMusic media = new MediaMusic(); media.Title = title; media.Description = description; media.Artist = artist; media.Genre = genre; media.Tracklist = tracklist; media.Tag = tag; media.Category = context.Categories.FirstOrDefault(c => c.CategoryId == categoryId); media.CreationDate = DateTime.Now; // set media state to "available" media.MediaState = context.MediaStates.FirstOrDefault(s => s.MediaSateId == 1); // set media type media.MediaType = context.MediaTypes.FirstOrDefault(mt => mt.MediaTypeId == 2); context.AddToMediaSet(media); context.SaveChanges(); } }
/// <summary> /// Create a new media /// </summary> /// <param name="mediaTypeId">The type ID of the media</param> /// <param name="title">The title of the media</param> /// <param name="description">The description of the media</param> /// <param name="categoryId">The category of the media</param> /// <returns>The ID of the created media</returns> public int CreateMedia(int mediaTypeId, string title, string description, int categoryId) { using (MediathekEntities context = new MediathekEntities()) { Media media = null; switch (mediaTypeId) { case 1: media = new MediaBook(); break; case 2: media = new MediaMusic(); break; case 3: media = new MediaVideo(); break; case 4: media = new MediaMisc(); break; default: throw new ConditionException(Localization.MsgErrorMediaTypeUnknown); } media.Title = title; media.Description = description; media.Category = context.Categories.FirstOrDefault(c => c.CategoryId == categoryId); media.CreationDate = DateTime.Now; // set media state to "available" media.MediaState = context.MediaStates.FirstOrDefault(s => s.MediaSateId == 1); // set media type media.MediaType = context.MediaTypes.FirstOrDefault(mt => mt.MediaTypeId == mediaTypeId); context.AddToMediaSet(media); context.SaveChanges(); // give back the ID of the created media return media.MediaId; } }