//declare a delegate public delegate Comics DelegateComic(string inSearchBy, string inSearchString); //implement Delegate for dropdownlist public Comics GetComicByDDL(string inSearchBy, string inSearchString) { Comics comic = new Comics(); comic = db.Comics.Where(c => c.Title == inSearchString).FirstOrDefault(); return comic; } //implement Delegate for Search public Comics GetComicBySearch(string inSearchBy, string inSearchString) { Comics comic = new Comics(); comic = db.Comics.Where(c => c.Title.Contains(inSearchString)).FirstOrDefault(); return comic; }
class iComicsList : ComicsInterface { //implement iComicsListAsc method public List iComicsListAsc() { //AlbacoreComicsDB db = new AlbacoreComicsDB(); MvcBootstrapDB db = new MvcBootstrapDB(); List comicsList = db.Comics.OrderBy(c => c.Title).ToList(); return comicsList; } //implement iComicsListDesc method public List iComicsListDesc() { AlbacoreComicsDB db = new AlbacoreComicsDB(); List comicsList = db.Comics.OrderByDescending(c => c.Title).ToList(); return comicsList; } } //end of iComicsList Class //Controller method public ActionResult InterfaceIndex() { //instantiate new iComicsList iComicsList i = new iComicsList(); //use iComicsList implementations ViewBag.iComicsListAsc = i.iComicsListAsc(); ViewBag.iComicsListDesc = i.iComicsListDesc(); return View(); } //InterfaceIndex html <div class="col-sm-5" style="border:2px solid fuchsia;"> <div id="dvAscInterface" data-toggle="modal" data-target="#modalAscInterface" class="row text-center"> <h2>Interface with ascending method</h2> </div> @if (ViewBag.iComicsListAsc != null) { foreach (var item in ViewBag.iComicsListAsc) { <div class="row" style="padding-left:25px;"> @item.Title @item.Issue </div> } } else { <dv class="row" style="padding-left:25px;"> ViewBag.iComicsListAsc is null</dv>} </div> }
class iComicsList : ComicsInterface { //implement iComicsListAsc method public List iComicsListAsc() { //AlbacoreComicsDB db = new AlbacoreComicsDB(); MvcBootstrapDB db = new MvcBootstrapDB(); List comicsList = db.Comics.OrderBy(c => c.Title).ToList(); return comicsList; } //implement iComicsListDesc method public List iComicsListDesc() { AlbacoreComicsDB db = new AlbacoreComicsDB(); List comicsList = db.Comics.OrderByDescending(c => c.Title).ToList(); return comicsList; } } //end of iComicsList Class //Controller method public ActionResult InterfaceIndex() { //instantiate new iComicsList iComicsList i = new iComicsList(); //use iComicsList implementations ViewBag.iComicsListAsc = i.iComicsListAsc(); ViewBag.iComicsListDesc = i.iComicsListDesc(); return View(); } //InterfaceIndex html <div class="col-sm-5" style="border:2px solid fuchsia;"> <div id="dvDescInterface" data-toggle="modal" data-target="#modalDescInterface" class="row text-center"> <h2>Interface with descending method</h2> </div> @if (ViewBag.iComicsListDesc != null) { foreach (var item in ViewBag.iComicsListDesc) { <div class="row" style="padding-left:25px;"> @item.Title @item.Issue </div> } } else { <dv class="row" style="padding-left:25px;"> ViewBag.iComicsListDesc is null</dv>} </div> }