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.

  1. Go to Model > right click > Add > Class > name it with ComicBook.
  2. 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; }
    }
    
  3. Go to our controller class. Take a look at our data structure.
  4. Therefore, we need some changes in our data model.
  5. Create a new class and name it with Artist.
    public class Artist
    {
        public string Name { get; set; }
        public string Role { get; set; }
    }
    
  6. 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; }
    }
    

results matching ""

    No results matching ""