Controllers/HomeController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using MvcBootstrap.Models;
using System.Web.Hosting;

namespace MvcBootstrap.Controllers
{
	public class HomeController : Controller
	{
		//AlbacoreComicsDB db = new AlbacoreComicsDB();
        MvcBootstrapDB db = new MvcBootstrapDB();
		public ActionResult Index()
		{
			ViewBag.lblErrMsg = "Welcome to MvcBoostrap. Thanks for stopping by.";
			return View();
		}

		public ActionResult About()
		{
			return View();
		}

		//------------------------------------------------------------------
		// derive AbstractComicClass
		class AbstractComicClassDerived : AbstractComicClass
		{
			//implement abstract method GetAllComicsAbstract
			public override List GetAllComicsAbstract()
			{
				//AlbacoreComicsDB db = new AlbacoreComicsDB();
                 MvcBootstrapDB db = new MvcBootstrapDB();
				List comicsList = new List();
				comicsList = db.Comics.OrderBy(c => c.Title).ToList();
				return comicsList;
			}

		}

		public ActionResult AbstractClassIndex()
		{
			//I can instantiate two instances of AbstractComicClassDerived class
			//instantiation 1
			AbstractComicClassDerived child1 = new AbstractComicClassDerived();

			//use nonAbstract method of child1 derived class
			List comicsList1 = child1.GetAllComicsNonAbstract();

			//implement Abstract method of child1 derived class
			List comicsList2 = child1.GetAllComicsAbstract();

			//pass implementations to ViewBag
			ViewBag.ComicsList1 = comicsList1;
			ViewBag.ComicsList2 = comicsList2;
			//-----------------------------------------------------------------

			//instantiation 2
			AbstractComicClassDerived child2 = new AbstractComicClassDerived();

			//use nonAbstract method of child2 derived class
			List comicsList3 = child2.GetAllComicsNonAbstract();

			//implement Abstract method of child2 derived class
			List comicsList4 = child2.GetAllComicsAbstract();

			ViewBag.ComicsList3 = comicsList3;
			ViewBag.ComicsList4 = comicsList4;

			return View(comicsList1);
		}

		public ActionResult Angular1()
		{
			return View();
		}

		public ActionResult Angular2()
		{
			return View();
		}

		public ActionResult Carousel()
		{
			return View();
		}

		public ActionResult Columnizer()
		{
			return View();
		}

		public ActionResult ComicsAPI()
		{
			//get the default URI for ComicsAPI
			string comicsAPIUrl = Url.HttpRouteUrl("DefaultApi", new { controller = "ComicsAPI", id = "" });
			string Uri = new Uri(Request.Url, comicsAPIUrl).AbsoluteUri.ToString();
			ViewBag.comicsAPIUrl = Uri;

			return View();
		}

		public ActionResult ComicsByTitle(string inString)
		{
			return RedirectToAction("ComicsByTitle", "Home",
										new { Area = "AlbacoreComics", id = inString });
		}

		public ActionResult ContactUs()
		{
			return View();
		}

		//declare a delegate
		public delegate Comics DelegateComic(string inSearchBy, string inSearchString);

		public Comics GetComicByDDL(string inSearchBy, string inSearchString)
		{
			Comics comic = new Comics();
			comic = db.Comics.Where(c => c.Title == inSearchString).FirstOrDefault();

			return comic;
		}

		public Comics GetComicBySearch(string inSearchBy, string inSearchString)
		{
			Comics comic = new Comics();
			comic = db.Comics.Where(c => c.Title.Contains(inSearchString)).FirstOrDefault();
			//comic = db.Comics.Where(c => c.Title == inSearchString).FirstOrDefault();


			return comic;
		}

		//Controller method to call View
		public ActionResult DelegateIndex(string inSearchBy, string inSearchString)
		{
			LoadTitlesDDL();
			Comics comic = new Comics();

			//instantiate new DelegateComic reference
			DelegateComic getComicByDDL = new DelegateComic(GetComicByDDL);
			DelegateComic getComicBySearch = new DelegateComic(GetComicBySearch);

			//use the Delegate method to retrieve a comic
			if (inSearchBy == "ByDDL")
			{
				comic = getComicByDDL(inSearchBy, inSearchString);
			}
			else if (inSearchBy == "BySearch")
			{
				comic = getComicBySearch(inSearchBy, inSearchString);
			}

			return View(comic);
		}
		public ActionResult ForgotLogIn()
		{
			return View();
		}

		class iComicsList : ComicsInterface
		{
			AlbacoreComicsDB db = new AlbacoreComicsDB();

			public List iComicsListAsc()
			{
				//AlbacoreComicsDB db = new AlbacoreComicsDB();
				List comicsList = db.Comics.OrderBy(c => c.Title).ToList();
				return comicsList;
			}

			public List iComicsListDesc()
			{
				//AlbacoreComicsDB db = new AlbacoreComicsDB();
				List comicsList = db.Comics.OrderByDescending(c => c.Title).ToList();
				return comicsList;
			}
		}

		public ActionResult InterfaceIndex()
		{
			iComicsList i = new iComicsList();
			ViewBag.iComicsListAsc = i.iComicsListAsc();
			ViewBag.iComicsListDesc = i.iComicsListDesc();
			return View();
		}

		public void LoadTitlesDDL()
		{
			List titlesList = db.Titles.ToList();
			List selTitles = new List();

			foreach (Titles title in titlesList)
			{
				selTitles.Add(new SelectListItem { Text = title.Title, Value = title.TitleID.ToString() });

			}

			ViewBag.Titles = selTitles;
		}

		public Boolean LogInn(string inString)
		{
			LogInModel lim = new LogInModel();
			bool stat = lim.LogInn(inString);
			return stat;
		}

		public ActionResult NestedDropdown()
		{
			return View();
		}

		public ActionResult RecursionIndex()
		{
			String d = HostingEnvironment.MapPath(@"/Areas/AlbacoreComics/Images");

			List fileList = new List();
			findFiles(d, fileList);
			return View();
		}

		private void findFiles(string path, IList fileList)
		{
			
			foreach(string fileName in Directory.GetFiles(path))
			{
				int loc = 0;
				loc = fileName.IndexOf("Images");
				string f = fileName.Substring(loc);
				fileList.Add(f);
			}

			foreach(string directory in Directory.GetDirectories(path))
			{
				findFiles(directory, fileList);
			}

			ViewBag.ImageFiles = fileList;
		}

		public ActionResult Register()
		{
			ViewBag.lblErrMsg = "Enter your information below";
			return View();
		}

		public ActionResult TableAPI()
		{
			//get the default URI for ComicsAPI
			string comicsAPIUrl = Url.HttpRouteUrl("DefaultApi", new { controller = "ComicsAPI", id = "" });
			string Uri = new Uri(Request.Url, comicsAPIUrl).AbsoluteUri.ToString();
			ViewBag.comicsAPIUrl = Uri;

			return View();
		}

	}
}