public static List<ResourceCategory> GetResourceCategories(GetResourceCategoriesRequest request) { var context = Exigo.ODataResources(); var query = context.ResourceManagerCategories.AsQueryable(); var model = new List<ResourceCategory>(); // Apply the filters if (request.ResourceCategoryID != null) { query = query.Where(c => c.ResourceCategoryID == (int)request.ResourceCategoryID); } var categories = query.ToList(); foreach (var category in categories) { var cat = new ResourceCategory(); cat.ResourceCategoryDescription = category.ResourceCategoryDescription; cat.ResourceCategoryID = category.ResourceCategoryID; cat.ResourceCategoryOrder = category.ResourceCategoryOrder; //Added the field to the model model.Add(cat); } return model; }
public static List <ResourceCategory> GetResourceCategories(GetResourceCategoriesRequest request) { var context = Exigo.ODataResources(); var query = context.ResourceManagerCategories.AsQueryable(); var model = new List <ResourceCategory>(); // Apply the filters if (request.ResourceCategoryID != null) { query = query.Where(c => c.ResourceCategoryID == (int)request.ResourceCategoryID); } var categories = query.ToList(); foreach (var category in categories) { var cat = new ResourceCategory(); cat.ResourceCategoryDescription = category.ResourceCategoryDescription; cat.ResourceCategoryID = category.ResourceCategoryID; cat.ResourceCategoryOrder = category.ResourceCategoryOrder; model.Add(cat); } return(model); }
public static List <ResourceCategory> GetResourceCategories(GetResourceCategoriesRequest request) { var query = "SELECT CategoryDescription, CategoryID, CategoryOrder, ParentID FROM ExigoWebContext.ResourceCategories"; // Apply the filters var filters = 0; if (request.CategoryID != null && request.CategoryID != Guid.Empty) { query += " WHERE CategoryID = @catid"; filters++; } if (request.CategoryIDs != null && request.CategoryIDs.Count() > 0) { var filterText = (filters > 0) ? "AND" : "WHERE"; query += String.Format(" {0} CategoryID in @catidlist", filterText); filters++; } if (request.CategoryOrder != 0) { var filterText = (filters > 0) ? "AND" : "WHERE"; query += String.Format(" {0} CategoryOrder > @categoryorder", filterText); filters++; } if (request.ParentID != null && request.ParentID != Guid.Empty) { var filterText = (filters > 0) ? "AND" : "WHERE"; query += String.Format(" {0} ParentID = @parentid", filterText); filters++; } var model = new List <ResourceCategory>(); using (var context = Exigo.Sql()) { model = context.Query <ResourceCategory>(query, new { catid = request.CategoryID, catidlist = request.CategoryIDs, categoryorder = request.CategoryOrder, parentid = request.ParentID }).ToList(); }; return(model); }