Ejemplo n.º 1
0
        /// <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="author">The author</param>
        /// <param name="publisher">The publisher</param>
        /// <param name="publishingYear">The publishing year</param>
        /// <param name="tag">The tag</param>
        /// <param name="categoryId">The category ID</param>
        public void CreateMediaBook(string title,
            string description,
            string author,
            string publisher,
            int? publishingYear,
            string tag,
            int categoryId)
        {
            using (MediathekEntities context = new MediathekEntities())
            {
                MediaBook media = new MediaBook();
                media.Title = title;
                media.Description = description;
                media.Author = author;
                media.Publisher = publisher;
                media.PublishingYear = publishingYear;
                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 == 1);

                context.AddToMediaSet(media);
                context.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        /// <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;
            }
        }