Creating the Family Page – Part 7, Beginning on the Wish List

Now that all the user and role code is done, it is time to add some real functionality. This time we will add the data model for the wish list and create a basic controller and view for it. This means that we will not handle anything that relates to connection specific wishes to specifics users today.

First we add a Wish class to the Models folder

namespace TheFamilyPage.Models
  public class Wish
    public int Id { get; set; }
    public virtual ApplicationUser User { get; set; }
    public string TheWish { get; set; }
    public string Url { get; set; }
    public string Shop { get; set; }
    public string Note { get; set; }

A wish has the following data:

– A user that has the wish on his/her wish list.
– A wish name “TheWish”
– A URL to be used if it can be found on the internet
– A shop name so people know where to find the wish in the real world
– A note, that can describe the wish in more detail (clothes size, colors, preferences etc.)

Then we need to add the wishes to the ApplicationDbContext class which is defined in the IdentityModels.cs file. I chose to make the class partial and add a new file called AppilcationDbContext.cs with the parts that is relevant to our data model.

namespace TheFamilyPage.Models
  public partial class ApplicationDbContext
    public DbSet<Wish> Wishes { get; set; } 

In the PackageManager console I write

PM> Add-Migration WishList
Scaffolding migration 'WishList'.
The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration WishList' again.

And then

PM> Update-Database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [201404281925350_WishList].
Applying explicit migration: 201404281925350_WishList.
Running Seed method.


Now our database is ready for use with the new datastructure.


At this time we will add a generic MVC controller for the wish list and also generate a view.Right-click on the controllers folder and select Add / Controller


Select ´Controller with View Usinger Entity Framework. In the following dailog choose a name for the controller and the data model to use (Wish):


Click Add.

Now a WishesController with all the CRUD actions has been added. Views for these actions have also been added. If we try to run our application we can try to access the wish list, by changing the URL to http://localhost:<port>/wishes – we have to do this manually, since we haven’t added any links to the wish list yet.


It is possible to add, edit and remove wishes.


We now have the ability to show, create, edit and delete wishes. So the basics of the wish list is in place.

Next time I want to implement.

  • Anonymous users to be able to view the wish lists
  • Logged in users to be able to edit their own wish lists.
  • Users with the role of editor to be able to edit all wish lists.
  • Links to view wish lists, and links to edit wish lists.

About Lund

Owner of iCodeIT, a software consulting company. I am primarily working the .NET development and architecture.
This entry was posted in ASP.NET MVC, C#, Web and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s