i am getting multi-level dynamic menus from database. Currently i have called it successfully but i want to make it async.
here is my code;
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
var menus = Uow.Menus.GetAll()
.Select(m => new ParentMenuViewModel()
{
MenuId = m.MenuId,
Name = m.Name,
ParentId = m.ParentId
})
.ToList<ParentMenuViewModel>();
ViewBag.Menus = CreateVM(0, menus);
base.OnActionExecuting(filterContext);
}
public IEnumerable<ParentMenuViewModel> CreateVM(int parentid, List<ParentMenuViewModel> list)
{
return list.Where(m=> m.ParentId==parentid)
.Select(m=> new ParentMenuViewModel()
{
MenuId = m.MenuId,
Name = m.Name,
ParentId = m.ParentId,
ChildMenus = CreateVM(m.MenuId, list)
});
}
So, how can i make this asynchronous using async and await keywords?
Notice that, it loops until the children are loaded completely;
Is it even a good practice to make it async (the above code)?