Пример #1
0
        /// <summary>
        /// Create a new MediaMisc in the database
        /// </summary>
        /// <param name="title">The title of the media</param>
        /// <param name="description">The description</param>
        /// <param name="shortDescription">The short description</param>
        /// <param name="tag">The tag</param>
        /// <param name="categoryId">The category ID</param>
        public void CreateMediaMisc(string title,
            string description,
            string shortDescription,
            string tag,
            int categoryId)
        {
            using (MediathekEntities context = new MediathekEntities())
            {
                MediaMisc media = new MediaMisc();
                media.Title = title;
                media.Description = description;
                media.ShortDescription = shortDescription;
                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 == 4);

                context.AddToMediaSet(media);
                context.SaveChanges();
            }
        }
Пример #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;
            }
        }