From my experience, I can generate Controllers and Views for CRUD using EntityFrameWork(MVC 5 Controllers with Views, using EntityFramework) for Job and any other classes that are NOT derived from IdentityUser. I want to have a feature in my application where User of Role admin will be able to delete other users in the same User Table. How can I generate Controllers and Views for that using EF ? Any help would be appreciated. Thank you!
public class User : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
public ICollection<Job> Jobs { get; set; }
}
public class Job
{
public int Id JobId {get; set;}
public string JobDetails {get; set;}
public bool isDone {get; set;}
public virtual User User {get; set;}
}
public class ApplicationDbContext : IdentityDbContext<User>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
public DbSet<Job> Jobs { get; set; }
}
}
There are pretty good blog posts around, talking about this very specific topic. I'll give you a quick headsup on how and where to start.
I am taking John Attens example postes here as reference.
Since you already have a
User
class, you can go right into your AccountController and implement an index method. You'd want to display all users first, so you can choose which one you want to delete.From there you can implement the delete methods (GET and POST):
EditUserViewModel
*AGAIN: This is not my own code. It is an example written by John Atten at http://typecastexception.com. *