diff options
| -rw-r--r-- | Project-Unite/Controllers/HomeController.cs | 20 | ||||
| -rw-r--r-- | Project-Unite/Models/SearchModels.cs | 22 | ||||
| -rw-r--r-- | Project-Unite/Project-Unite.csproj | 2 | ||||
| -rw-r--r-- | Project-Unite/Views/Home/Search.cshtml | 75 | ||||
| -rw-r--r-- | Project-Unite/Views/Wiki/Index.cshtml | 2 |
5 files changed, 120 insertions, 1 deletions
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<ForumPost> ForumPosts { get; set; } + public IEnumerable<ForumTopic> ForumTopics { get; set; } + public IEnumerable<ApplicationUser> Users { get; set; } + public IEnumerable<Skin> Skins { get; set; } + public IEnumerable<Download> Downloads { get; set; } + public IEnumerable<WikiPage> 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 @@ <Compile Include="Models\ManageViewModels.cs" /> <Compile Include="Models\Notification.cs" /> <Compile Include="Models\Role.cs" /> + <Compile Include="Models\SearchModels.cs" /> <Compile Include="Models\Skin.cs" /> <Compile Include="Models\WikiModels.cs" /> <Compile Include="NotificationDaemon.cs" /> @@ -547,6 +548,7 @@ <Content Include="Views\Developer\AddWikiCategory.cshtml" /> <Content Include="Views\Wiki\AddPage.cshtml" /> <Content Include="Views\Wiki\EditPage.cshtml" /> + <Content Include="Views\Home\Search.cshtml" /> </ItemGroup> <ItemGroup> <Folder Include="App_Data\" /> 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"; +} + +<h2>Search results</h2> + +<p>Here's what we found for that query.</p> + + +<ul id="tabs" data-tabs="tabs" class="nav nav-tabs" role="tablist"> + <li class="active"><a data-toggle="tab" href="#t_topics"><span class="glyphicon glyphicon-list"></span> Forum Topics (@Model.ForumTopics.Count())</a></li> + <li><a data-toggle="tab" href="#t_downloads"><span class="glyphicon glyphicon-arrow-down"></span> Downloads (@Model.Downloads.Count())</a></li> + <li><a data-toggle="tab" href="#t_skins"><span class="glyphicon glyphicon-eye-open"></span> Skins (@Model.Skins.Count())</a></li> + <li><a data-toggle="tab" href="#t_users"><span class="glyphicon glyphicon-user"></span> Users (@Model.Users.Count())</a></li> + <li><a data-toggle="tab" href="#t_wiki"><span class="glyphicon glyphicon-book"></span> Wiki Pages (@Model.WikiPages.Count())</a></li> +</ul> + +<div class="tab-content"> + <div class="tab-pane fade in active" id="t_topics"> + <h4>Forum Topics</h4> + <table class="table"> + <tr> + <th style="width:45%">Topic</th> + <th style="width:20%">Popularity</th> + <th>Most Recent Post</th> + </tr> + @foreach (var topic in Model.ForumTopics.OrderByDescending(x=>x.StartedAt)) + { + <tr> + <td> + @Html.TopicLinkFor(topic.Id) <br/> + <p>by @Html.UserLink(topic.AuthorId) at @topic.StartedAt</p> + </td> + <td> + <span class="glyphicon glyphicon-thumbs-up"></span> @topic.Likes.Length <span class="glyphicon glyphicon-thumbs-down"></span> @topic.Dislikes.Length + </td> + <td> + @{ + var mostrecent = topic.Posts.OrderByDescending(x => x.PostedAt).First(); + } + <p>By @Html.UserLink(mostrecent.AuthorId) at @mostrecent.PostedAt</p> + </td> + </tr> + } + </table> + </div> + + <div class="tab-pane fade in active" id="t_downloads"> + <h4>Downloads</h4> + <table class="table"> + <tr> + <th style="width:65%">Download</th> + <th>Actions</th> + </tr> + @foreach (var download in Model.Downloads.OrderByDescending(x => x.PostDate)) + { + <tr> + <td> + <p>@download.Name <br/> ...released by @Html.UserLink(download.ReleasedBy), released at @download.PostDate</p> + </td> + <td> + @if (!string.IsNullOrEmpty(download.DevUpdateId)) + { + <a href="http://youtube.com/[email protected]" class="btn btn-default"><span class="glyphicon glyphicon-play"></span> Watch dev update</a> + <a href="@Url.Action("ViewRelease", "Download", new {id=download.Id})" class="btn btn-default"><span class="glyphicon glyphicon-eye-open"></span> View details</a> + <a href="@download.DownloadUrl" class="btn btn-default"><span class="glyphicon glyphicon-arrow-down"></span> Download</a> + } + </td> + </tr> + } + </table> + </div> + +</div>
\ 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) { - <ul> + <ul class="nav nav-pills"> <li><a href="@Url.Action("EditPage", new { id = Model.Page.Id })"><span class="glyphicon glyphicon-pencil"></span> Edit this page</a></li> </ul> } |
