private static void PopulateInitialUser(WebAPIDemoDbContext context)
        {
            if (context.Users.Any())
            {
                return;
            }

            var primaryUserID   = new Guid("9338B511-C135-41A9-9ACE-48211DB19BE9");
            var currentDateTime = DateTime.Now;

            var(primarySalt, primaryHash) = CreatePasswordHash("jrrtolkien");

            context.Users.Add(new User
            {
                ID           = primaryUserID,
                UserName     = "******",
                FirstName    = "Aragorn",
                LastName     = "Elessar",
                PasswordHash = primaryHash,
                PasswordSalt = primarySalt,
                UserRoles    = new List <UserRole>
                {
                    new UserRole {
                        RoleID = new Guid("dab0807c-822c-4258-ad79-07dd543cb253")
                    }
                },
                CreateDate     = currentDateTime,
                UpdateDate     = currentDateTime,
                CreateByUserID = primaryUserID,
                UpdateByUserID = primaryUserID
            });

            var secondaryUserID = new Guid("30B801CC-216B-4F1B-6243-08D8312EBC95");

            var(secondarySalt, secondaryHash) = CreatePasswordHash("eruilluvatar");

            context.Users.Add(new User
            {
                ID           = secondaryUserID,
                UserName     = "******",
                FirstName    = "Arwen",
                LastName     = "Undomiel",
                PasswordHash = secondaryHash,
                PasswordSalt = secondarySalt,
                UserRoles    = new List <UserRole>
                {
                    new UserRole {
                        RoleID = new Guid("99626019-0a7d-4c79-9058-b727ed7b1fa9")
                    }
                },
                CreateDate     = currentDateTime,
                UpdateDate     = currentDateTime,
                CreateByUserID = primaryUserID,
                UpdateByUserID = primaryUserID
            });

            context.SaveChanges();
        }
 public static void Initialise(WebAPIDemoDbContext context)
 {
     PopulateInitialUser(context);
 }
示例#3
0
 public UnitOfWork(ISystemClock systemClock, WebAPIDemoDbContext context, IHttpContextAccessor httpContextAccessor)
 {
     _systemClock         = systemClock ?? throw new ArgumentNullException(nameof(systemClock));
     _context             = context ?? throw new ArgumentNullException(nameof(context));
     _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
 }