Beispiel #1
0
        public static async Task SeedAsync(LinContext linContext,
                                           ILoggerFactory loggerFactory, int retry = 0)
        {
            var retryForAvailability = retry;

            try
            {
                // TODO: Only run this if using a real database
                // linContext.Database.Migrate();

                if (!linContext.LinUsers.Any())
                {
                    linContext.LinUsers.Add(
                        new LinUser
                    {
                        Username = "******",
                        Email    = "*****@*****.**",
                        Password = Pbkdf2Encrypt.EncryptPassword("123456"),
                        Admin    = (short)UserAdmin.Admin,
                        Active   = (short)UserActive.Active
                    }
                        );
                    await linContext.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                if (retryForAvailability < 10)
                {
                    retryForAvailability++;
                    var logger = loggerFactory.CreateLogger <LinContextSeed>();
                    logger.LogError(ex.Message);
                    await SeedAsync(linContext, loggerFactory, retryForAvailability);
                }
            }
        }
 public async Task <bool> SaveAsync()
 {
     return(await _linContext.SaveChangesAsync() > 0);
 }