/// <summary> /// Create a new MediaBook in the database /// </summary> /// <param name="title">The title of the media</param> /// <param name="description">The description</param> /// <param name="director">The director</param> /// <param name="actors">Actors</param> /// <param name="runtime">The runtime of the video</param> /// <param name="tag">The tag</param> /// <param name="categoryId">The category ID</param> public void CreateMediaVideo(string title, string description, string director, string actors, int? runtime, string tag, int categoryId) { using (MediathekEntities context = new MediathekEntities()) { MediaVideo media = new MediaVideo(); media.Title = title; media.Description = description; media.Director = director; media.Actors = actors; media.Length = runtime; 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 == 3); 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; } }