/// <summary> /// Default page load method /// </summary> /// <returns>Index page</returns> public ActionResult Index() { List <Models.Customer> customers = new List <Models.Customer>(); try { //retrieval of oldest (by age) 5 customers using (Models.IDbContext context = dbContext) { var customerRepository = new CustomerRepository(context); customers = customerRepository.GetOldestFive(); } //ordering of customers by lastname customers = customers.OrderByDescending(o => o.LastName).Reverse().ToList(); } catch (SqlException) { TempData["Message"] = "Unable to connect to database"; } //catch all catch (Exception e) { //temporary logging till a logger can be implemented Console.Out.WriteLine(e.Message); TempData["Message"] = "Unable to connect to database"; } return(View(customers)); }
public Repository(Models.IDbContext dataContext) { DbSet = dataContext.Set <T>(); }
//Dependancy Injection public CustomerController(Models.IDbContext repo) { dbContext = repo; }
public HomeController(Models.IDbContext repo) { dbContext = repo; }
//Dependency Injection public HomeController() { dbContext = new Models.DatabaseContext(); }