Guest User

Untitled

a guest
Oct 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. public class ItemViewModel
  2. {
  3. public int itemId { get; set; }
  4.  
  5. public string itemName { get; set; }
  6.  
  7. public int? categoryId { get; set; }
  8. }
  9.  
  10. public List<ItemViewModel> GetData(int?[] categoryIds){
  11.  
  12. var data = db.Query<ItemViewModel>("SELECT itemId, itemName, categoryId FROM items;").ToList();
  13.  
  14. // So far so good. Getting data as List<ItemViewModel>
  15. // Now, if there are any categoryIds passed in to the controller, filter the data accordingly:
  16.  
  17. if(categoryIds!= null && categoryIds.Any()){
  18. data = data.Where(x => x.categoryId != null && categoryIds.Contains((int)x.categoryId));
  19. }
  20.  
  21. return data
  22. }
Add Comment
Please, Sign In to add comment