Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Store the Controllers name and Actions Name into my Custom Tables that I Add them into Identity in CodeFirst Asp.Net MVC Project

$
0
0

Seniors, <br/>
I'm using ASP.NET Identity on my ASP.Net web application and I Add my custom Tables(with their relations) to Identity on myCodeFirst ASP.Net MVC Project.when I Run Project for the first time,the databace is created automatically with the custom tables and relations between them in SqlServer. <br/>
Custom Tables :

1. MvcControllers
2. ActionsTbls
3. GroupsTbls
4. AspNetUser_Action
5. AspNetUser_Group
6. Action_Group

* This is The Diagram of my Database Image :Database Diagram Click Here

For Creating Custom tables,I Add Some Codes to IdentityModels.cs. <br/>
IdentityModels.cs :

namespace Admin_Base_SN.Models
{
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit https://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
public virtual AspNetUser_Action AspNetUser_Action { get; set; }

public virtual AspNetUser_Group AspNetUser_Group { get; set; }

}

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{


public DbSet<MvcController> MvcController { get; set; }
public DbSet<ActionsTbls> ActionsTbls { get; set; }
public DbSet<AspNetUser_Action> AspNetUser_Actions { get; set; }

public DbSet<GroupsTbl> GroupsTbls { get; set; }
public DbSet<Action_Group> Action_Groups { get; set; }

public DbSet<AspNetUser_Group> AspNetUser_Groups { get; set; }
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}

public static ApplicationDbContext Create()
{
return new ApplicationDbContext();

}

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

// one-to-zero or one relationship between ApplicationUser and Customer
// UserId column in Customers table will be foreign key
modelBuilder.Entity<ApplicationUser>()
.HasOptional(m => m.AspNetUser_Action)
.WithRequired(m => m.ApplicationUser)
.Map(p => p.MapKey("AspNetUser_Id"));

modelBuilder.Entity<ApplicationUser>()
.HasOptional(m => m.AspNetUser_Group)
.WithRequired(m => m.ApplicationUser)
.Map(p => p.MapKey("AspNetUser_Id"));

}

}
}


What I want <br/>
At first,I want to save All the Controllers Names and Actions Names of Project into separated Lists,then insert them into MvcController Table & ActionsTbl Table.This process should be done automatically when I Run Project for the first time.I mean When the Database is Created, the Lists inert to their tables automatically.

* I think it's better to Add a New Custom Function to the Identity for inserting Lists to the Tables.

I appreciate your efforts in reaching a solution for my problem.


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>