コード例 #1
0
 public static void EnsureSeedData(this DiplomContext context)
 {
     if (context.AllMigrationsApplied())
     {
         if (!context.Roles.Any())
         {
             context.Roles.AddRange(Role.Admin, Role.Owner, Role.Student, Role.Teacher);
             context.SaveChanges();
         }
         if (!context.Users.Any())
         {
             context.Users.Add(new User {
                 Id           = 1,
                 Login        = "******",
                 PasswordHash = @"WgHWgYQpzkpETS0VemCGE15u2LNPjTbtocMdxtqLll8=",
                 Roles        = new List <UserRole>
                 {
                     new UserRole
                     {
                         UserId = 1,
                         RoleId = 1
                     }
                 }
             });
         }
     }
 }
コード例 #2
0
 public RepositoryBase(DiplomContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     _context = context;
 }
コード例 #3
0
        private static bool AllMigrationsApplied(this DiplomContext context)
        {
            var applied = context.GetService <IHistoryRepository>()
                          .GetAppliedMigrations()
                          .Select(m => m.MigrationId);

            var total = context.GetService <IMigrationsAssembly>()
                        .Migrations
                        .Select(m => m.Key);

            return(!total.Except(applied).Any());
        }
コード例 #4
0
 public static void EnsureSeedData(this DiplomContext context)
 {
     if (context.AllMigrationsApplied())
     {
         if (!context.Periods.Any())
         {
             context.Periods.Add(Period.Current);
         }
         if (!context.TeachersPositions.Any())
         {
             context.TeachersPositions.AddRange(TeacherPosition.HighTeacher, TeacherPosition.Professor, TeacherPosition.Doctor);
         }
         if (!context.Roles.Any())
         {
             context.Roles.AddRange(Role.Admin, Role.Owner, Role.Student, Role.Teacher);
         }
         if (!context.MaterialTypes.Any())
         {
             context.MaterialTypes.AddRange(
                 MaterialType.Other,
                 MaterialType.Image,
                 MaterialType.LatexFile,
                 MaterialType.Preambula,
                 MaterialType.Introduction,
                 MaterialType.Chapter,
                 MaterialType.Subchapter,
                 MaterialType.Conclusion,
                 MaterialType.Bibliography,
                 MaterialType.Abbreviations,
                 MaterialType.Appendix
                 );
         }
         if (!context.Users.Any())
         {
             context.Users.Add(new User {
                 Id           = 1,
                 Login        = "******",
                 PasswordHash = @"WgHWgYQpzkpETS0VemCGE15u2LNPjTbtocMdxtqLll8=",
                 Roles        = new List <UserRole>
                 {
                     new UserRole
                     {
                         UserId = 1,
                         RoleId = 1
                     }
                 }
             });
         }
         context.SaveChanges();
     }
 }
コード例 #5
0
ファイル: UserRepository.cs プロジェクト: vanonavi/dcs
 public UserRepository(DiplomContext context) : base(context)
 {
 }