public static List <Resource> GetResources(GetResourcesRequest request)
        {
            var context = Exigo.ODataResources();
            var model   = new List <Resource>();

            // Establish the base query
            var query = context.ResourceManagement.Expand("ResourceManagerCategory,ResourceType")
                        .AsQueryable();

            // Apply any filters
            if (request.ResourceID != null)
            {
                query = query.Where(c => c.ResourceID == (int)request.ResourceID);
            }

            if (request.ResourceCategoryID != null)
            {
                query = query.Where(c => c.ResourceCategoryID == (int)request.ResourceCategoryID);
            }

            if (request.ResourceStatusID != null)
            {
                query = query.Where(c => c.ResourceStatusID == (int)request.ResourceStatusID);
            }

            if (request.ResourceTypeID != null)
            {
                query = query.Where(c => c.ResourceTypeID == (int)request.ResourceTypeID);
            }

            if (request.SearchFilter.IsNotNullOrEmpty())
            {
                query = query.Where(c => c.Title.Contains(request.SearchFilter) || c.Description.Contains(request.SearchFilter));
            }

            // Get the data
            var apiResources = query.ToList();

            foreach (var category in apiResources)
            {
                var cat = new Resource();

                cat.CreatedDate        = category.CreatedDate;
                cat.Description        = category.Description;
                cat.ResourceCategoryID = category.ResourceCategoryID;
                cat.ResourceID         = category.ResourceID;
                cat.ResourceStatusID   = category.ResourceStatusID;
                cat.ResourceTypeID     = category.ResourceTypeID;
                cat.Title            = category.Title;
                cat.UploadedFilePath = category.UploadedFilePath;
                cat.ResourceOrder    = category.ResourceOrder;
                cat.Url = category.Url;

                model.Add(cat);
            }
            return(model);
        }
        public static List<Resource> GetResources(GetResourcesRequest request)
        {
            var context = Exigo.ODataResources();
            var model = new List<Resource>();

            // Establish the base query
            var query = context.ResourceManagement.Expand("ResourceManagerCategory,ResourceType")
                .AsQueryable();

            // Apply any filters
            if (request.ResourceID != null)
            {
                query = query.Where(c => c.ResourceID == (int)request.ResourceID);
            }

            if (request.ResourceCategoryID != null)
            {
                query = query.Where(c => c.ResourceCategoryID == (int)request.ResourceCategoryID);
            }

            if (request.ResourceStatusID != null)
            {
                query = query.Where(c => c.ResourceStatusID == (int)request.ResourceStatusID);
            }

            if (request.ResourceTypeID != null)
            {
                query = query.Where(c => c.ResourceTypeID == (int)request.ResourceTypeID);
            }

            if (request.SearchFilter.IsNotNullOrEmpty())
            {
                query = query.Where(c => c.Title.Contains(request.SearchFilter) || c.Description.Contains(request.SearchFilter));
            }

            // Get the data
            var apiResources = query.ToList();

            foreach (var category in apiResources)
            {
                var cat = new Resource();

                cat.CreatedDate = category.CreatedDate;
                cat.Description = category.Description;
                cat.ResourceCategoryID = category.ResourceCategoryID;
                cat.ResourceID = category.ResourceID;
                cat.ResourceStatusID = category.ResourceStatusID;
                cat.ResourceTypeID = category.ResourceTypeID;
                cat.Title = category.Title;
                cat.UploadedFilePath = category.UploadedFilePath;
                cat.Url = category.Url;

                model.Add(cat);
            }
            return model;
        }
Exemple #3
0
        public static List <ResourceItem> GetResourceItems(GetResourcesRequest request)
        {
            // Establish the base query
            var query = "SELECT ItemID, typeID, Title, Url, UrlThumbnail, CreatedDate, PostDate, ItemDescription, StatusID, Language FROM ExigoWebContext.ResourceItems";

            // Apply any filters
            var filters = 0;

            if (request.ItemID != Guid.Empty)
            {
                query += " WHERE ItemID = @itemid";
                filters++;
            }

            if (request.TypeID != Guid.Empty)
            {
                var filterText = (filters > 0) ? "AND" : "WHERE";

                query += String.Format(" {0} TypeID = @typeid", filterText);
                filters++;
            }

            if (request.ItemIDs != null && request.ItemIDs.Count() > 0)
            {
                var filterText = (filters > 0) ? "AND" : "WHERE";

                query += String.Format(" {0} ItemID in @itemidlist", filterText);
                filters++;
            }

            if (request.SearchFilter.IsNotNullOrEmpty())
            {
                var filterText = (filters > 0) ? "AND" : "WHERE";

                query += String.Format(" {0} Title LIKE @searchfilter", filterText);
                filters++;
            }



            var model = new List <ResourceItem>();

            using (var context = Exigo.Sql())
            {
                model = context.Query <ResourceItem>(query, new { itemid = request.ItemID, typeid = request.TypeID, itemidlist = request.ItemIDs, searchfilter = request.SearchFilter }).ToList();
            }
            return(model);
        }