Created
January 23, 2019 23:01
-
-
Save ivanvs/66d1dddc4138e8b0e157c1dee3a99a7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Microsoft.AspNet.Identity.EntityFramework; | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Data.Entity; | |
| using System.Linq; | |
| using System.Web; | |
| using TestWebApp.Infrastructure; | |
| using TestWebApp.Models; | |
| using TestWebApp.Repositories; | |
| namespace TestWebApp.Models | |
| { | |
| public class DataAccessContext : IdentityDbContext<User> | |
| { | |
| //ovo bi trebao da je AuthContex, ali Marko kaze da je svejedno kako se zove... | |
| //moguce da treba drugacije da izgleda, mozda bazu nisam dobro napravila, ali mi ona inace uvek radi | |
| public DataAccessContext() : base("DataAccessConnection") | |
| { | |
| Database.SetInitializer(new InitializeWithDefaultData()); | |
| } | |
| protected override void OnModelCreating(DbModelBuilder modelBuilder) | |
| { | |
| base.OnModelCreating(modelBuilder); | |
| // must define for db relations | |
| modelBuilder.Entity<Student>().ToTable("Student"); | |
| modelBuilder.Entity<Admin>().ToTable("Admin"); | |
| modelBuilder.Entity<Student>().HasRequired(s => s.User).WithOptional(u => u.Student); | |
| modelBuilder.Entity<Grade>().HasRequired(g => g.Student).WithMany(s => s.Grades); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Microsoft.AspNet.Identity; | |
| using Microsoft.AspNet.Identity.EntityFramework; | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Data.Entity; | |
| using System.Linq; | |
| using System.Web; | |
| using TestWebApp.Models; | |
| namespace TestWebApp.Infrastructure | |
| { | |
| public class InitializeWithDefaultData : DropCreateDatabaseAlways<DataAccessContext> | |
| { | |
| protected override void Seed(DataAccessContext context) | |
| { | |
| using (var store = new RoleStore<IdentityRole>(context)) | |
| { | |
| using (var manager = new RoleManager<IdentityRole>(store)) | |
| { | |
| manager.Create(new IdentityRole("admin")); | |
| manager.Create(new IdentityRole("student")); | |
| manager.Create(new IdentityRole("parent")); | |
| manager.Create(new IdentityRole("teacher")); | |
| } | |
| } | |
| context.SaveChanges(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment