public void AddMediaItemTest()
        {
            MediaItem media = new MediaItem
            {
                Name = "patrickstar",
                Title = "Patrick Star",
                Type = MediaType.Image,
                Format = MediaFormat.JPG,
                AlternativeText = "Patricio Estrella",
                Bytes = TestData.GetResourceBytes("Babel.Services.Tests.media.patrickstar.jpg"),
                Owner = TestData.profiles[1]
            };

            MediaRepository repository = new MediaRepository();
            Guid guid = repository.Add(media);

            Assert.AreNotEqual<Guid>(Guid.Empty, guid);

            using (ISession session = _sessionFactory.OpenSession())
            {
                var mediaFromDB = session.Get<MediaItem>(media.ID);

                Assert.IsNotNull(mediaFromDB);
                Assert.AreNotSame(media, mediaFromDB);
                Assert.AreEqual<string>(media.Name, mediaFromDB.Name);
                Assert.AreEqual<string>(media.Title, mediaFromDB.Title);
                Assert.AreEqual<MediaType>(media.Type, mediaFromDB.Type);
                Assert.AreEqual<MediaFormat>(media.Format, mediaFromDB.Format);
                Assert.AreEqual<string>(media.AlternativeText, mediaFromDB.AlternativeText);
            }
        }
 /// <summary>
 /// This method removes an existing media item.
 /// </summary>
 /// <param name="mediaItem">Media item to remove.</param>
 public void Remove(MediaItem mediaItem)
 {
     using (ISession session = NHibernateHelper.OpenSession())
     {
         using (ITransaction transaction = session.BeginTransaction())
         {
             session.Delete(mediaItem);
             transaction.Commit();
         }
     }
 }
        public Guid CreateMediaItem(string name, string title, MediaType type, MediaFormat format, string alt)
        {
            MediaItem newMediaItem = new MediaItem();

            newMediaItem.Name = name;
            newMediaItem.Title = title;
            newMediaItem.Type = type;
            newMediaItem.Format = format;
            newMediaItem.AlternativeText = alt;

            Repository.Add(newMediaItem);

            return newMediaItem.ID;
        }
        /// <summary>
        /// Adds a new media item.
        /// </summary>
        /// <param name="mediaItem">Media item.</param>
        /// <returns>New media item unique identifier.</returns>
        public Guid Add(MediaItem mediaItem)
        {
            Guid guid = Guid.Empty;

            using (ISession session = NHibernateHelper.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    mediaItem.UploadedOn = DateTime.Now;
                    guid = (Guid)session.Save(mediaItem);
                    transaction.Commit();
                }
            }

            return guid;
        }
 public void ModifyMediaItem(MediaItem item)
 {
     Repository.Update(item);
 }
 /// <summary>
 /// This method updates an existing media item.
 /// </summary>
 /// <param name="mediaItem">Media item to update.</param>
 public void Update(MediaItem mediaItem)
 {
     using (ISession session = NHibernateHelper.OpenSession())
     {
         using (ITransaction transaction = session.BeginTransaction())
         {
             mediaItem.UploadedOn = DateTime.Now;
             session.Update(mediaItem);
             transaction.Commit();
         }
     }
 }