Modelling and Presenting Data
The comic book data that we have in our Controller's detail action method is just a collection of variables.
Updating code without changing its external behavior is often referred as Refactoring.
The process of defining the structure of your application's data is called Data Modeling.
- Go to Model > right click > Add > Class > name it with ComicBook.
- Define the attributes for comic book class.
public class ComicBook { public int Id { get; set; } public string SeriesTitle { get; set; } public int IssueNumber { get; set; } public string Description { get; set; } public string[] Artists { get; set; } public bool Favorite { get; set; } }
- Go to our controller class. Take a look at our data structure.
- Therefore, we need some changes in our data model.
- Create a new class and name it with Artist.
public class Artist { public string Name { get; set; } public string Role { get; set; } }
- Change the structure of our ComicBook model.
public class ComicBook { public int Id { get; set; } public string SeriesTitle { get; set; } public int IssueNumber { get; set; } public string DescriptionHTML { get; set; } public Artist[] Artists { get; set; } public bool Favorite { get; set; } }