Skip to content

04 Hosting

Robert Friberg edited this page May 28, 2014 · 5 revisions

This module covers the different options hosting the engine and in-memory model.

Exercise 1

In this exercise you will create a skeleton ASP.NET MVC application hosting the Todo.Core model. We will have VS generate some CRUD scaffolding that we can use as a starting point. For this purpose we need some fake classes which will be deleted once the scaffolding has been generated.

  1. Open the Todo solution located in the 'Ex01' folder.
  2. Add an MVC application to the solution called Todo.Mvc
  3. Add the following classes somewhere in the project, note the namespace!
    namespace Todo.Core
    {
        public class Todo
        {
            public int Id { get; set; }
            public string Title { get; set; }
            public DateTime? Due { get; set; }
            public DateTime? Completed { get; set; }
        }
    
        public class TodoContext : DbContext
        {
            public DbSet<Todo> Todos { get; set; }
        }
    }
  4. Build the solution
  5. Add an MVC controller with read/write actions and views, using Entity Framework. Choose the Todo and TodoContext classes. (Right click controllers in solution explorer)
  6. Add a reference to the Todo.Core project
  7. Modify the Core.TodoView class to include the Due and Completed fields
  8. In the generated controller, replace the TodoContext field with the following:
    IEngine<TodoModel> engine = Engine.For<TodoModel>();
  9. Change the model type of all the generated views from Todo to TodoView
  10. Make all the controller methods work, modifying the core library and views as needed.
Clone this wiki locally