Ejemplo n.º 1
0
        public IList<MediaItem> GetProfileMediaItems(Guid profileID)
        {
            MediaItemFilter filter = new MediaItemFilter
            {
                OwnerID = profileID
            };

            return Repository.SearchMediaItems(filter);
        }
Ejemplo n.º 2
0
        public void SearchMediaItemsTest()
        {
            IMediaRepository repository = new MediaRepository();

            MediaItemFilter filter = new MediaItemFilter()
            {
                Name = "spoungebob",
                Type = MediaType.Image
            };

            IList<MediaItem> searchResult = repository.SearchMediaItems(filter);

            Assert.AreEqual<int>(1, searchResult.Count);
            Assert.AreEqual<string>("spoungebob", searchResult[0].Name);
            Assert.AreEqual<string>("Bob Esponja", searchResult[0].Title);
            Assert.AreEqual<MediaType>(MediaType.Image, searchResult[0].Type);
            Assert.AreEqual<MediaFormat>(MediaFormat.JPG, searchResult[0].Format);
        }
Ejemplo n.º 3
0
 public IList<MediaItem> SearchMediaItems(MediaItemFilter filter)
 {
     return Repository.SearchMediaItems(filter);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// This method does a search using parameters passed in the filter object.
        /// </summary>
        /// <param name="filter">Filter containing search criteria.</param>
        /// <returns>List of media items that match the specified filter.</returns>
        public IList<MediaItem> SearchMediaItems(MediaItemFilter filter)
        {
            IList<MediaItem> searchResult;

            using (ISession session = NHibernateHelper.OpenSession())
            {
                IQuery query = BuildQuery(session, filter);
                searchResult = query.List<MediaItem>();
            }

            return searchResult;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="session"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        private IQuery BuildQuery(ISession session, MediaItemFilter filter)
        {
            StringBuilder queryString = new StringBuilder();
            IDictionary<string, string> parameters = new Dictionary<string, string>();

            queryString.Append("from MediaItem m where ");
            bool first = true;

            // Name parameter
            if (!string.IsNullOrEmpty(filter.Name))
            {
                if (!first) { queryString.Append("and "); }
                queryString.Append("m.Name like :name");
                parameters["name"] = string.Format("%{0}%", filter.Name);
                first = false;
            }

            // Title parameter
            if (!string.IsNullOrEmpty(filter.Title))
            {
                if (!first) { queryString.Append("and "); }
                queryString.Append("m.Title like :title");
                parameters["title"] = string.Format("%{0}%", filter.Title);
                first = false;
            }

            // OwnerID parameter
            if (filter.OwnerID != Guid.Empty)
            {
                if (!first) { queryString.Append("and "); }
                queryString.Append("m.OwnerID = :ownerID");
                parameters["ownerID"] = filter.OwnerID.ToString();
                first = false;
            }

            IQuery query = session.CreateQuery(queryString.ToString());

            foreach (string key in parameters.Keys)
            {
                query.SetString(key, parameters[key]);
            }

            return query;
        }