diff --git a/Web/Controllers/UserController.cs b/Web/Controllers/UserController.cs index b5ab0af..881dd25 100644 --- a/Web/Controllers/UserController.cs +++ b/Web/Controllers/UserController.cs @@ -11,10 +11,17 @@ namespace MileageTraker.Web.Controllers { public ActionResult Index() { - return View(DataService.GetUsers().ToList()); + var users = + DataService + .GetUsers() + .ToList() + //.Where(u => u.Filter(q)) + .OrderBy(u => u.Username); + + return View(users); } - public ActionResult Details(Guid id) + public ActionResult Details(Guid id) { var user = Membership.GetUser(id); if (user == null) @@ -24,6 +31,17 @@ namespace MileageTraker.Web.Controllers return View(DataService.GetUser(id)); } + public ActionResult DetailsFullName(string employeeName) + { + var user = DataService.FindUserByFullName(employeeName); + if (user == null) + { + TempData["StatusMessage"] = "User " + employeeName + " not found"; + return RedirectToAction("Index"); + } + return View("Details", user); + } + public JsonResult UsernameAvailable(string username) { var user = DataService.FindUserByUsername(username); diff --git a/Web/DAL/DataService.cs b/Web/DAL/DataService.cs index 14f7196..3ce5fc8 100644 --- a/Web/DAL/DataService.cs +++ b/Web/DAL/DataService.cs @@ -506,6 +506,11 @@ namespace MileageTraker.Web.DAL return _db.Users.FirstOrDefault(u => username.Equals(u.Username, StringComparison.InvariantCultureIgnoreCase)); } + public User FindUserByFullName(string fullName) + { + return _db.Users.FirstOrDefault(u => fullName.Equals(u.FullName, StringComparison.InvariantCultureIgnoreCase)); + } + public User FindUserByEmail(string email) { return _db.Users.FirstOrDefault(u => email.Equals(u.Email, StringComparison.InvariantCultureIgnoreCase)); diff --git a/Web/Models/User.cs b/Web/Models/User.cs index 56616d9..64b38cc 100644 --- a/Web/Models/User.cs +++ b/Web/Models/User.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Data.SqlTypes; +using System.Linq; using System.Web.Mvc; using System.Web.Security; @@ -96,5 +97,17 @@ namespace MileageTraker.Web.Models LastLoginDate, LastActivityDate, LastPasswordChangedDate, LastLockoutDate); } + + public bool Filter(string q) + { + if (string.IsNullOrEmpty(q)) + return true; + + var queries = q.Split(' '); + + return queries.Any(query => + Username.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0 + || FullName.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0); + } } } \ No newline at end of file diff --git a/Web/Scripts/Shared/Site.js b/Web/Scripts/Shared/Site.js index c0e870f..1a78918 100644 --- a/Web/Scripts/Shared/Site.js +++ b/Web/Scripts/Shared/Site.js @@ -58,7 +58,7 @@ $(function () { }); }); - if ($("input#EmployeeName").filter(':not(:hidden)').length > 0) { + if ($("input#EmployeeName").filter(':not(:hidden)').filter(':not(.search-query)').length > 0) { $("input#EmployeeName") .after('') diff --git a/Web/Views/User/Index.cshtml b/Web/Views/User/Index.cshtml index ca3552e..400d63e 100644 --- a/Web/Views/User/Index.cshtml +++ b/Web/Views/User/Index.cshtml @@ -10,9 +10,15 @@

@ViewBag.Title

+
+ @using (Html.BeginForm("DetailsFullName", "User", FormMethod.Get, new {@class = "navbar-search form-inline" })) + { + + } +
+
@Html.ActionLink("Add new User", "Create", null, new{@class="btn"}) -
Users online now: @Membership.GetNumberOfUsersOnline()
@@ -44,6 +50,10 @@ No Role } ), + grid.Column("LastActivityDate", "Last Activity", format: + @ + @Html.Partial("_LastActivity", (DateTime)item.LastActivityDate) + ), grid.Column(format: @
@*Html.ActionLink("Edit", "Edit", new { id = item.UserId }, new { @class = "btn btn-mini" })*@ diff --git a/Web/Views/User/_LastActivity.cshtml b/Web/Views/User/_LastActivity.cshtml new file mode 100644 index 0000000..1024a69 --- /dev/null +++ b/Web/Views/User/_LastActivity.cshtml @@ -0,0 +1,12 @@ +@using MileageTraker.Web.Utility +@model DateTime + +@if (!Model.IsSqlMinValue()) +{ + @Html.Encode(Model) + (@Html.Encode((DateTime.Now - Model).ToVerboseStringHistoric())) +} +else +{ + No Activity +} \ No newline at end of file diff --git a/Web/Web.csproj b/Web/Web.csproj index bdf8486..a1394e7 100644 --- a/Web/Web.csproj +++ b/Web/Web.csproj @@ -293,6 +293,7 @@ +