Exemple #1
0
        public List <UserFile> GetFilesList(string type = "", string search = "", int sort = 1, int page = 1, int pageSize = 30)
        {
            //sort -> 1(created on), 2(filename alpha)
            //type -> image,document,audio,video
            var skipCount = (page - 1) * pageSize;


            var listSorts = new List <QuerySortObject>();

            switch (sort)
            {
            case 1:
                listSorts.Add(new QuerySortObject("created_on", QuerySortType.Descending));
                break;

            case 2:
                listSorts.Add(new QuerySortObject("name", QuerySortType.Ascending));
                break;
            }

            var filters = new List <QueryObject>();

            if (!String.IsNullOrWhiteSpace(search))
            {
                filters.Add(EntityQuery.QueryOR(EntityQuery.QueryContains("name", search), EntityQuery.QueryContains("alt", search), EntityQuery.QueryContains("caption", search)));
            }
            if (!String.IsNullOrWhiteSpace(type))
            {
                filters.Add(EntityQuery.QueryContains("type", type));
            }
            var filterQuery = EntityQuery.QueryAND(filters.ToArray());

            EntityQuery   query    = new EntityQuery("user_file", UserFile.GetQueryColumns(), filterQuery, listSorts.ToArray(), skipCount, pageSize);
            QueryResponse response = RecMan.Find(query);

            if (!response.Success)
            {
                throw new Exception(response.Message);
            }

            var files = response.Object.Data.MapTo <UserFile>();

            return(files);
        }