Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using EUCYS.Models;
- using System.Data.Entity.Migrations;
- namespace EUCYS.Migrations
- {
- using AspNetExtendingIdentityRoles.Models;
- using AspNetExtendingIdentityRoles.Models.Status;
- using AspNetExtendingIdentityRoles.Models.Users;
- using Models.Status;
- using System;
- using System.Collections.Generic;
- using System.Data.Entity;
- using System.Data.Entity.Migrations;
- using System.Linq;
- internal sealed class Configuration : DbMigrationsConfiguration<ApplicationDbContext>
- {
- public Configuration()
- {
- AutomaticMigrationsEnabled = true;
- }
- protected override void Seed(ApplicationDbContext context)
- {
- this.AddEnums(context);
- this.AddEdition(context);
- this.AddUserAndRoles();
- this.AddUsers(context);
- this.AddTheses(context);
- }
- void AddEdition(ApplicationDbContext ctx)
- {
- ctx.Editions.AddOrUpdate(i => i.Number, new Edition { IdEditionStatus=2, DayStart = DateTime.Today, DayEnd = new DateTime(2017, 12, 31), DueTimeEntry = new DateTime(2017, 11, 30) });
- }
- bool AddUserAndRoles()
- {
- bool success = false;
- var idManager = new IdentityManager();
- success = idManager.CreateRole("Admin", "Global Access");
- if (!success == true) return success;
- success = idManager.CreateRole("Jury", "Reviewing and grant places");
- if (!success == true) return success;
- success = idManager.CreateRole("Expert", "Reviewing");
- if (!success) return success;
- success = idManager.CreateRole("User", "Restricted to business domain activity");
- if (!success) return success;
- var newUser = new ApplicationUser()
- {
- UserName = "admin",
- FirstName = "John",
- LastName = "Atten",
- Email = "jatten@typecastexception.com"
- };
- // Be careful here - you will need to use a password which will
- // be valid under the password rules for the application,
- // or the process will abort:
- success = idManager.CreateUser(newUser, "Admin1");
- if (!success) return success;
- success = idManager.AddUserToRole(newUser.Id, "Admin");
- if (!success) return success;
- success = idManager.AddUserToRole(newUser.Id, "Expert");
- if (!success) return success;
- success = idManager.AddUserToRole(newUser.Id, "Jury");
- if (!success) return success;
- success = idManager.AddUserToRole(newUser.Id, "User");
- if (!success) return success;
- return success;
- }
- public bool AddEnums(ApplicationDbContext context)
- {
- //UserStatus
- context.UserStatuses.AddOrUpdate(i => i.Name, new UserStatus { Name = "Niekatywny" });
- context.UserStatuses.AddOrUpdate(i => i.Name, new UserStatus { Name = "Aktywny" });
- //ThesisStatus
- context.ThesisVerificationStatus.AddOrUpdate(i => i.Name, new ThesisVerificationStatus { Name = "Do weryfykacji" });
- context.ThesisVerificationStatus.AddOrUpdate(i => i.Name, new ThesisVerificationStatus { Name = "Odrzucona" });
- context.ThesisVerificationStatus.AddOrUpdate(i => i.Name, new ThesisVerificationStatus { Name = "Przyjęta" });
- context.ThesisVerificationStatus.AddOrUpdate(i => i.Name, new ThesisVerificationStatus { Name = "Finałowa" });
- //Parameters - kryteria
- context.Parameters.AddOrUpdate(i => i.Name, new Parameter { Name = "Inwencja, oryginalność i kreatywność" });
- context.Parameters.AddOrUpdate(i => i.Name, new Parameter { Name = "Stopień samodzielności" });
- context.Parameters.AddOrUpdate(i => i.Name, new Parameter { Name = "Poprawność metodologiczna" });
- context.Parameters.AddOrUpdate(i => i.Name, new Parameter { Name = "Jasność i rzetelność dowodu i analizy" });
- context.Parameters.AddOrUpdate(i => i.Name, new Parameter { Name = "Jakość pisemnej wersji pracy" });
- context.Parameters.AddOrUpdate(i => i.Name, new Parameter { Name = "Wiedza i umiejętność prezentacji" });
- //Kategorie
- context.Categories.AddOrUpdate(i => i.Name, new Category { Name = "Nauki ścisłe" });
- context.Categories.AddOrUpdate(i => i.Name, new Category { Name = "Nauki techniczne" });
- context.Categories.AddOrUpdate(i => i.Name, new Category { Name = "Nauki przyrodnicze" });
- context.Categories.AddOrUpdate(i => i.Name, new Category { Name = "Nauki ekonomiczne" });
- context.Categories.AddOrUpdate(i => i.Name, new Category { Name = "Nauki społeczne" });
- //Statusy edycji
- context.EditionStatuses.AddOrUpdate(i => i.Name, new EditionStatus { Name = "Zakończona" });
- context.EditionStatuses.AddOrUpdate(i => i.Name, new EditionStatus { Name = "Aktywna" });
- context.EditionStatuses.AddOrUpdate(i => i.Name, new EditionStatus { Name = "Planowana" });
- context.SaveChanges();
- return true;
- }
- public bool AddUsers(ApplicationDbContext context)
- {
- var idManager = new IdentityManager();
- //exper1
- var expert1 = new ApplicationUser()
- {
- UserName = "expert1",
- FirstName = "Jan",
- LastName = "Noga",
- Email = "kekeke@mail.com"
- };
- idManager.CreateUser(expert1, "Kokos1");
- idManager.AddUserToRole(expert1.Id, "Expert");
- //expert2
- var expert2 = new ApplicationUser()
- {
- UserName = "expert2",
- FirstName = "Jan",
- LastName = "Noga",
- Email = "kekeke1@mail.com"
- };
- idManager.CreateUser(expert2, "Kokos1");
- idManager.AddUserToRole(expert2.Id, "Expert");
- //jury1
- var jury1 = new ApplicationUser()
- {
- UserName = "jury1",
- FirstName = "Jan",
- LastName = "Noga",
- Email = "kekeke2@mail.com"
- };
- idManager.CreateUser(jury1, "Kokos1");
- idManager.AddUserToRole(jury1.Id, "Jury");
- //jury2
- var jury2 = new ApplicationUser()
- {
- UserName = "jury2",
- FirstName = "Jan",
- LastName = "Noga",
- Email = "kekeke3@mail.com"
- };
- idManager.CreateUser(jury2, "Kokos1");
- idManager.AddUserToRole(jury2.Id, "Jury");
- //Dodanie w bazie jury i reviewers
- context.Reviewers.AddOrUpdate(i => i.Id, new Reviewer { IdUser = expert1.Id });
- context.Reviewers.AddOrUpdate(i => i.Id, new Reviewer { IdUser = expert2.Id });
- context.Jury.AddOrUpdate(i => i.Id, new Jury { IdUser = jury1.Id });
- context.Jury.AddOrUpdate(i => i.Id, new Jury { IdUser = jury2.Id });
- context.SaveChanges();
- return true;
- }
- void AddTheses(ApplicationDbContext ctx)
- {
- ctx.Theses.AddOrUpdate(i => i.Title, new Thesis
- {
- IdCategory = 1,
- IdThesisStatus = 1,
- DayCreated = DateTime.Today,
- Authors = new List<Participant> { ctx.Participants.Where(i => i.Id == 1).SingleOrDefault(),
- ctx.Participants.Where(i => i.Id == 2).SingleOrDefault()},
- Title = "Tytul 1"
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement