public async Task <IActionResult> Index([FromQuery] string q) { if (!CheckQ(q)) { return(BadRequest()); } var userLeftMenuModel = await UserLeftMenuModel.FromDatabase(DbConnection, User.Identity.Name, User); ViewData["User"] = userLeftMenuModel; var users = await SearchUsersAsync(userLeftMenuModel.Id, 0, UsersPortion, q); if (users.DefaultText == null) { users.DefaultText = "No users found"; } var posts = await SearchPostsAsync(userLeftMenuModel.Id, 0, PostsPortion, q); if (posts.DefaultText == null) { posts.DefaultText = "No posts found"; } var model = new SearchModel() { Q = q, Users = users, Posts = posts, }; return(View("~/Views/Search.cshtml", model)); }
protected async Task <IActionResult> Get(string userName, ItemsLoaderDelegate itemsLoader, int offset, int count, Func <IUser, string> itemsDefaultText, Func <IUser, string> title, Func <IUser, string> main) { int sum = OffsetCountResolver.ResolveOffsetCountWithReserve(offset, ref count); var userLeftMenuModel = await UserLeftMenuModel.FromDatabase(DbConnection, userName, User); if (userLeftMenuModel == null) { return(NotFound()); } var items = await itemsLoader(userLeftMenuModel.Id, 0, sum, userLeftMenuModel); if (items.DefaultText == null) { items.DefaultText = itemsDefaultText(userLeftMenuModel); } ViewData["User"] = userLeftMenuModel; ViewData["Title"] = title(userLeftMenuModel); ViewData["Main"] = main(userLeftMenuModel); return(View("~/Views/SimpleListWithLoadMoreView.cshtml", items)); }