From 5eea4787f1bdc384451c18d5a693e65a4ed38601 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 7 Apr 2017 10:47:11 -0400 Subject: [PATCH] add search system (downloads and topics) --- Project-Unite/Controllers/HomeController.cs | 20 ++++++ Project-Unite/Models/SearchModels.cs | 22 ++++++ Project-Unite/Project-Unite.csproj | 2 + Project-Unite/Views/Home/Search.cshtml | 75 +++++++++++++++++++++ Project-Unite/Views/Wiki/Index.cshtml | 2 +- 5 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 Project-Unite/Models/SearchModels.cs create mode 100644 Project-Unite/Views/Home/Search.cshtml diff --git a/Project-Unite/Controllers/HomeController.cs b/Project-Unite/Controllers/HomeController.cs index 1c648e9..85570a8 100644 --- a/Project-Unite/Controllers/HomeController.cs +++ b/Project-Unite/Controllers/HomeController.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Net; using System.Web; using System.Web.Mvc; +using Project_Unite.Models; namespace Project_Unite.Controllers { @@ -33,5 +34,24 @@ namespace Project_Unite.Controllers { return View(); } + + [HttpPost] + public ActionResult Search(string query) + { + var result = new SearchResult(); + query = query.ToLower(); + using(var db = new ApplicationDbContext()) + { + result.Downloads = db.Downloads.Where(x => x.Name.ToLower().Contains(query) || x.Changelog.ToLower().Contains(query)); + result.ForumPosts = db.ForumPosts.Where(x => x.Body.ToLower().Contains(query)); + result.ForumTopics = db.ForumTopics.Where(x => x.Subject.ToLower().Contains(query)); + result.Skins = db.Skins.Where(x => x.Name.ToLower().Contains(query) || x.ShortDescription.ToLower().Contains(query) || x.FullDescription.ToLower().Contains(query)); + result.Users = db.Users.Where(x => x.DisplayName.ToLower().Contains(query)||x.Bio.ToLower().Contains(query)||x.Interests.ToLower().Contains(query)||x.Hobbies.ToLower().Contains(query)); + result.WikiPages = db.WikiPages.Where(x => x.Name.ToLower().Contains(query) || x.Contents.ToLower().Contains(query)); + } + + //Holy crap that search was... long. + return View(result); + } } } \ No newline at end of file diff --git a/Project-Unite/Models/SearchModels.cs b/Project-Unite/Models/SearchModels.cs new file mode 100644 index 0000000..a0c79e9 --- /dev/null +++ b/Project-Unite/Models/SearchModels.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Project_Unite.Models +{ + public class SimpleSearch + { + public string Query { get; set; } + } + + public class SearchResult + { + public IEnumerable ForumPosts { get; set; } + public IEnumerable ForumTopics { get; set; } + public IEnumerable Users { get; set; } + public IEnumerable Skins { get; set; } + public IEnumerable Downloads { get; set; } + public IEnumerable WikiPages { get; set; } + } +} \ No newline at end of file diff --git a/Project-Unite/Project-Unite.csproj b/Project-Unite/Project-Unite.csproj index b5724bd..3050e2a 100644 --- a/Project-Unite/Project-Unite.csproj +++ b/Project-Unite/Project-Unite.csproj @@ -427,6 +427,7 @@ + @@ -547,6 +548,7 @@ + diff --git a/Project-Unite/Views/Home/Search.cshtml b/Project-Unite/Views/Home/Search.cshtml new file mode 100644 index 0000000..e786832 --- /dev/null +++ b/Project-Unite/Views/Home/Search.cshtml @@ -0,0 +1,75 @@ +@model Project_Unite.Models.SearchResult +@{ + ViewBag.Title = "Search"; +} + +

Search results

+ +

Here's what we found for that query.

+ + + + +
+
+

Forum Topics

+ + + + + + + @foreach (var topic in Model.ForumTopics.OrderByDescending(x=>x.StartedAt)) + { + + + + + + } +
TopicPopularityMost Recent Post
+ @Html.TopicLinkFor(topic.Id)
+

by @Html.UserLink(topic.AuthorId) at @topic.StartedAt

+
+ @topic.Likes.Length @topic.Dislikes.Length + + @{ + var mostrecent = topic.Posts.OrderByDescending(x => x.PostedAt).First(); + } +

By @Html.UserLink(mostrecent.AuthorId) at @mostrecent.PostedAt

+
+
+ +
+

Downloads

+ + + + + + @foreach (var download in Model.Downloads.OrderByDescending(x => x.PostDate)) + { + + + + + } +
DownloadActions
+

@download.Name
...released by @Html.UserLink(download.ReleasedBy), released at @download.PostDate

+
+ @if (!string.IsNullOrEmpty(download.DevUpdateId)) + { + Watch dev update + View details + Download + } +
+
+ +
\ No newline at end of file diff --git a/Project-Unite/Views/Wiki/Index.cshtml b/Project-Unite/Views/Wiki/Index.cshtml index 02c2845..3cebce7 100644 --- a/Project-Unite/Views/Wiki/Index.cshtml +++ b/Project-Unite/Views/Wiki/Index.cshtml @@ -83,7 +83,7 @@ if (Request.IsAuthenticated) { -