1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

Simple Introduction to MVC Ajax (ASP.NET MVC 5)

14/09/2014

The jQuery Ajax built into ASP.NET MVC is very powerful but it's hard to know exactly where to start. This tutorial is a result of a few hours investigation so it's written from the point of view of a beginner.

I intend to upload code samples at some point but I need to add a code hosting feature to my website.

Setting up our test environment

We're going to use a very simple example to work with only the details we need. As always we're using a dog class, here's a picture of a dog:

A picture of a dog.

...

Error Creating a DACPAC in Visual Studio 2013 from SQL Server 2014

31/08/2014

Working on projects in your spare time is great because you're free to pursue every little diversion; it means you make no real progress with your actual project but you learn a lot.

When I had to add a column to one of my database tables I decided to investigate creating a DACPAC(1). A DACPAC allows you to turn your existing database into a database project in Visual Studio which means your schema can be placed under source control. Changes can then be pushed to your database in a friendly wizard format.

To create a DACPAC you right click on your existing database and choose Extract Data Tier Application under tasks:

Right click Database, choose tasks.

...

ASP.NET Identity 1.0 - Database First

16/08/2014

Note: This tutorial applies to Identity 1.0 which is the previous version of ASP.NET Identity. I have a newer post on the same subject here

If you've read my previous posts you probably know I'm working on some EF Database first stuff, this seems to be the least popular way to use EF but to me seems like a common business use-case for it.

The MVC template in Visual Studio comes with the new Asp.NET Identity system built in, but it's designed to be used with Code First. This leads to people asking how to use Identity with Database First? The suggested soultion is to use the table structure provided when you use Code First and port it to your pre-existing database.

This seemed like an unpleasant approach to me (and a lot of work), especially because I think the database layout for those tables is kinda sucky. This is when it occurred to me that we're basically trying to implement Identity without using what the documentation thinks of as Entity Framework.

When you Google how to do that, you get this great post from Mark Johnson. You can follow his approach and just substitute his use of Dapper for use of Entity Framework. for instance:

public Task CreateAsync(User user)
{
    if (user == null)
    {
        throw new ArgumentNullException("user was null");
    }

    return Task.Factory.StartNew(() =>
        {
            db.Users.Add(user);
            db.SaveChanges();
        });
}

public Task DeleteAsync(User user)
{
    User checkUser = db.Users.Find(user.Id);

    if (user == null || checkUser == null)
    {
        throw new ArgumentNullException("user was null");
    }

    return Task.Factory.StartNew(() =>
    {
        db.Users.Remove(user);
        db.SaveChanges();
    });
}

Where db is your DbContext. Hopefully this helps you as much as it helped me, it's a far nicer solution than rolling your own Auth system.

...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17