Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ItemViewModel
- {
- public int itemId { get; set; }
- public string itemName { get; set; }
- public int? categoryId { get; set; }
- }
- public List<ItemViewModel> GetData(int?[] categoryIds){
- var data = db.Query<ItemViewModel>("SELECT itemId, itemName, categoryId FROM items;").ToList();
- // So far so good. Getting data as List<ItemViewModel>
- // Now, if there are any categoryIds passed in to the controller, filter the data accordingly:
- if(categoryIds!= null && categoryIds.Any()){
- data = data.Where(x => x.categoryId != null && categoryIds.Contains((int)x.categoryId));
- }
- return data
- }
Add Comment
Please, Sign In to add comment