Advertisement
Guest User

Untitled

a guest
Nov 30th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.91 KB | None | 0 0
  1. using EUCYS.Models;
  2. using System.Data.Entity.Migrations;
  3.  
  4. namespace EUCYS.Migrations
  5. {
  6. using AspNetExtendingIdentityRoles.Models;
  7. using AspNetExtendingIdentityRoles.Models.Status;
  8. using AspNetExtendingIdentityRoles.Models.Users;
  9. using Models.Status;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data.Entity;
  13. using System.Data.Entity.Migrations;
  14. using System.Linq;
  15.  
  16. internal sealed class Configuration : DbMigrationsConfiguration<ApplicationDbContext>
  17. {
  18. public Configuration()
  19. {
  20. AutomaticMigrationsEnabled = true;
  21. }
  22.  
  23.  
  24. protected override void Seed(ApplicationDbContext context)
  25. {
  26. this.AddEnums(context);
  27. this.AddEdition(context);
  28. this.AddUserAndRoles();
  29. this.AddUsers(context);
  30. this.AddTheses(context);
  31. }
  32.  
  33. void AddEdition(ApplicationDbContext ctx)
  34. {
  35. 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) });
  36. }
  37.  
  38. bool AddUserAndRoles()
  39. {
  40. bool success = false;
  41.  
  42. var idManager = new IdentityManager();
  43. success = idManager.CreateRole("Admin", "Global Access");
  44. if (!success == true) return success;
  45.  
  46. success = idManager.CreateRole("Jury", "Reviewing and grant places");
  47. if (!success == true) return success;
  48.  
  49. success = idManager.CreateRole("Expert", "Reviewing");
  50. if (!success) return success;
  51.  
  52. success = idManager.CreateRole("User", "Restricted to business domain activity");
  53. if (!success) return success;
  54.  
  55.  
  56. var newUser = new ApplicationUser()
  57. {
  58. UserName = "admin",
  59. FirstName = "John",
  60. LastName = "Atten",
  61. Email = "jatten@typecastexception.com"
  62. };
  63.  
  64. // Be careful here - you will need to use a password which will
  65. // be valid under the password rules for the application,
  66. // or the process will abort:
  67. success = idManager.CreateUser(newUser, "Admin1");
  68. if (!success) return success;
  69.  
  70. success = idManager.AddUserToRole(newUser.Id, "Admin");
  71. if (!success) return success;
  72.  
  73. success = idManager.AddUserToRole(newUser.Id, "Expert");
  74. if (!success) return success;
  75.  
  76. success = idManager.AddUserToRole(newUser.Id, "Jury");
  77. if (!success) return success;
  78.  
  79. success = idManager.AddUserToRole(newUser.Id, "User");
  80. if (!success) return success;
  81.  
  82. return success;
  83. }
  84.  
  85. public bool AddEnums(ApplicationDbContext context)
  86. {
  87. //UserStatus
  88. context.UserStatuses.AddOrUpdate(i => i.Name, new UserStatus { Name = "Niekatywny" });
  89. context.UserStatuses.AddOrUpdate(i => i.Name, new UserStatus { Name = "Aktywny" });
  90.  
  91. //ThesisStatus
  92. context.ThesisVerificationStatus.AddOrUpdate(i => i.Name, new ThesisVerificationStatus { Name = "Do weryfykacji" });
  93. context.ThesisVerificationStatus.AddOrUpdate(i => i.Name, new ThesisVerificationStatus { Name = "Odrzucona" });
  94. context.ThesisVerificationStatus.AddOrUpdate(i => i.Name, new ThesisVerificationStatus { Name = "Przyjęta" });
  95. context.ThesisVerificationStatus.AddOrUpdate(i => i.Name, new ThesisVerificationStatus { Name = "Finałowa" });
  96.  
  97. //Parameters - kryteria
  98. context.Parameters.AddOrUpdate(i => i.Name, new Parameter { Name = "Inwencja, oryginalność i kreatywność" });
  99. context.Parameters.AddOrUpdate(i => i.Name, new Parameter { Name = "Stopień samodzielności" });
  100. context.Parameters.AddOrUpdate(i => i.Name, new Parameter { Name = "Poprawność metodologiczna" });
  101. context.Parameters.AddOrUpdate(i => i.Name, new Parameter { Name = "Jasność i rzetelność dowodu i analizy" });
  102. context.Parameters.AddOrUpdate(i => i.Name, new Parameter { Name = "Jakość pisemnej wersji pracy" });
  103. context.Parameters.AddOrUpdate(i => i.Name, new Parameter { Name = "Wiedza i umiejętność prezentacji" });
  104.  
  105. //Kategorie
  106. context.Categories.AddOrUpdate(i => i.Name, new Category { Name = "Nauki ścisłe" });
  107. context.Categories.AddOrUpdate(i => i.Name, new Category { Name = "Nauki techniczne" });
  108. context.Categories.AddOrUpdate(i => i.Name, new Category { Name = "Nauki przyrodnicze" });
  109. context.Categories.AddOrUpdate(i => i.Name, new Category { Name = "Nauki ekonomiczne" });
  110. context.Categories.AddOrUpdate(i => i.Name, new Category { Name = "Nauki społeczne" });
  111.  
  112. //Statusy edycji
  113. context.EditionStatuses.AddOrUpdate(i => i.Name, new EditionStatus { Name = "Zakończona" });
  114. context.EditionStatuses.AddOrUpdate(i => i.Name, new EditionStatus { Name = "Aktywna" });
  115. context.EditionStatuses.AddOrUpdate(i => i.Name, new EditionStatus { Name = "Planowana" });
  116.  
  117. context.SaveChanges();
  118.  
  119. return true;
  120. }
  121.  
  122. public bool AddUsers(ApplicationDbContext context)
  123. {
  124. var idManager = new IdentityManager();
  125.  
  126. //exper1
  127. var expert1 = new ApplicationUser()
  128. {
  129. UserName = "expert1",
  130. FirstName = "Jan",
  131. LastName = "Noga",
  132. Email = "kekeke@mail.com"
  133. };
  134.  
  135.  
  136. idManager.CreateUser(expert1, "Kokos1");
  137. idManager.AddUserToRole(expert1.Id, "Expert");
  138.  
  139. //expert2
  140. var expert2 = new ApplicationUser()
  141. {
  142. UserName = "expert2",
  143. FirstName = "Jan",
  144. LastName = "Noga",
  145. Email = "kekeke1@mail.com"
  146. };
  147.  
  148.  
  149. idManager.CreateUser(expert2, "Kokos1");
  150. idManager.AddUserToRole(expert2.Id, "Expert");
  151.  
  152. //jury1
  153. var jury1 = new ApplicationUser()
  154. {
  155. UserName = "jury1",
  156. FirstName = "Jan",
  157. LastName = "Noga",
  158. Email = "kekeke2@mail.com"
  159. };
  160.  
  161.  
  162. idManager.CreateUser(jury1, "Kokos1");
  163. idManager.AddUserToRole(jury1.Id, "Jury");
  164.  
  165. //jury2
  166. var jury2 = new ApplicationUser()
  167. {
  168. UserName = "jury2",
  169. FirstName = "Jan",
  170. LastName = "Noga",
  171. Email = "kekeke3@mail.com"
  172. };
  173.  
  174.  
  175. idManager.CreateUser(jury2, "Kokos1");
  176. idManager.AddUserToRole(jury2.Id, "Jury");
  177.  
  178. //Dodanie w bazie jury i reviewers
  179. context.Reviewers.AddOrUpdate(i => i.Id, new Reviewer { IdUser = expert1.Id });
  180. context.Reviewers.AddOrUpdate(i => i.Id, new Reviewer { IdUser = expert2.Id });
  181.  
  182. context.Jury.AddOrUpdate(i => i.Id, new Jury { IdUser = jury1.Id });
  183. context.Jury.AddOrUpdate(i => i.Id, new Jury { IdUser = jury2.Id });
  184.  
  185. context.SaveChanges();
  186.  
  187. return true;
  188. }
  189.  
  190. void AddTheses(ApplicationDbContext ctx)
  191. {
  192. ctx.Theses.AddOrUpdate(i => i.Title, new Thesis
  193. {
  194. IdCategory = 1,
  195. IdThesisStatus = 1,
  196. DayCreated = DateTime.Today,
  197. Authors = new List<Participant> { ctx.Participants.Where(i => i.Id == 1).SingleOrDefault(),
  198. ctx.Participants.Where(i => i.Id == 2).SingleOrDefault()},
  199. Title = "Tytul 1"
  200. });
  201. }
  202.  
  203. }
  204.  
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement