Add user search
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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('<span id="icon-employee-history" class="add-on"><i class="icon-search" /></span>')
|
||||
|
||||
@@ -10,9 +10,15 @@
|
||||
|
||||
<h2 id="user-title">@ViewBag.Title</h2>
|
||||
|
||||
<div class="btn-toolbar pull-right">
|
||||
@using (Html.BeginForm("DetailsFullName", "User", FormMethod.Get, new {@class = "navbar-search form-inline" }))
|
||||
{
|
||||
<input type="text" name="EmployeeName" id="EmployeeName" class="search-query" placeholder="Search">
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="btn-toolbar pull-left">
|
||||
@Html.ActionLink("Add new User", "Create", null, new{@class="btn"})
|
||||
|
||||
</div>
|
||||
|
||||
<div id="users-online">Users online now: <span class="badge badge-info">@Membership.GetNumberOfUsersOnline()</span></div>
|
||||
@@ -44,6 +50,10 @@
|
||||
<span class='label label-warning'>No Role</span>
|
||||
}
|
||||
</text>),
|
||||
grid.Column("LastActivityDate", "Last Activity", format:
|
||||
@<text>
|
||||
@Html.Partial("_LastActivity", (DateTime)item.LastActivityDate)
|
||||
</text>),
|
||||
grid.Column(format:
|
||||
@<div class='btn-group'>
|
||||
@*Html.ActionLink("Edit", "Edit", new { id = item.UserId }, new { @class = "btn btn-mini" })*@
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
@using MileageTraker.Web.Utility
|
||||
@model DateTime
|
||||
|
||||
@if (!Model.IsSqlMinValue())
|
||||
{
|
||||
@Html.Encode(Model)
|
||||
<span class="muted">(@Html.Encode((DateTime.Now - Model).ToVerboseStringHistoric()))</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class='label label-info'>No Activity</span>
|
||||
}
|
||||
@@ -293,6 +293,7 @@
|
||||
<Content Include="Views\User\_UserStatusLabels.cshtml" />
|
||||
<Content Include="Views\Account\ResetPassword.cshtml" />
|
||||
<Content Include="Views\Account\NewPassword.cshtml" />
|
||||
<Content Include="Views\User\_LastActivity.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="packages.config">
|
||||
|
||||
Reference in New Issue
Block a user