Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. <form asp-action="SearchByText" asp-route-topicId="@Model.Id">
  2. <div asp-validation-summary="ModelOnly" class="text-danger"></div>
  3. <div class="form-group">
  4. <label name="query" class="col-md-2 control-label"></label>
  5. <div class="col-md-10">
  6. <input name="query" class="form-control" />
  7. </div>
  8. </div>
  9. <div class="form-group">
  10. <input type="submit" value="Search" class="btn btn-default" />
  11. </div>
  12. </form>
  13.  
  14. [AllowAnonymous]
  15. public async Task<IActionResult> SearchByText(Guid? topicId, String query)
  16. {
  17. if (topicId == null)
  18. {
  19. return NotFound();
  20. }
  21.  
  22. var forumTopic = await context.ForumTopics
  23. .Include(f => f.Creator)
  24. .Include(f => f.Forum)
  25. .Include(f => f.Messages)
  26. .ThenInclude(f => f.Creator)
  27. .Include(f => f.Messages)
  28. .ThenInclude(f => f.Attachments)
  29. .SingleOrDefaultAsync(m => m.Id == topicId);
  30.  
  31. forumTopic.Messages = forumTopic.Messages.Where(p => p.Creator.Email.Equals(query)).ToList();
  32. if (forumTopic == null)
  33. {
  34. return NotFound();
  35. }
  36.  
  37. this.ViewBag.Query = query;
  38. return View(forumTopic);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement