I'm having trouble creating an item search box. I'm already a beginner.
I want the user to type a name in the search box to display the items that contain the name that the user entered or a part of it, for example: the user entered materials or mat should then appear:
- file materials
- automotive materials
- etc ...
My biggest question is how to implement this using DDD. I saw this example , and I found it relatively simple, but I can not imagine a way to implement it. I saw that it implements PagedList.Mvc and found it simple, but how to leave decoupled (Using DDD)?
An example of what was implemented there
public ViewResult Index(string sortOrder, string currentFilter, string searchString, int? page)
{
ViewBag.CurrentSort = sortOrder;
ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date";
if (searchString != null)
{
page = 1;
}
else
{
searchString = currentFilter;
}
ViewBag.CurrentFilter = searchString;
var students = from s in db.Students
select s;
if (!String.IsNullOrEmpty(searchString))
{
students = students.Where(s => s.LastName.Contains(searchString)
|| s.FirstMidName.Contains(searchString));
}
switch (sortOrder)
{
case "name_desc":
students = students.OrderByDescending(s => s.LastName);
break;
case "Date":
students = students.OrderBy(s => s.EnrollmentDate);
break;
case "date_desc":
students = students.OrderByDescending(s => s.EnrollmentDate);
break;
default: // Name ascending
students = students.OrderBy(s => s.LastName);
break;
}
int pageSize = 3;
int pageNumber = (page ?? 1);
return View(students.ToPagedList(pageNumber, pageSize));
}
In my understanding, there is another way to do this to leave it unbound.