static void TemplateFile(BlogSystemContext dataBaseContext,
                          IHostingEnvironment hostingEnvironment)
 {
     Template.AddZipFile(dataBaseContext, hostingEnvironment,
                         (_dataBaseContext, _hostingEnvironment) =>
                         new UploadUnit(dataBaseContext, _hostingEnvironment).SaveZipFiles(
                             File.OpenRead($"{hostingEnvironment.ContentRootPath}/default-template.zip")));
     dataBaseContext.SaveChanges();
 }
        static void Config(BlogSystemContext dataBaseContext, IDistributedCache cache, Configs configs)
        {
            var configUnit = new ConfigUnit(dataBaseContext, cache)
            {
                Email        = configs.Email,
                Password     = PasswordHelper.CreateDbPassword(configs.Password, false),
                BlogName     = configs.BlogName,
                UserName     = configs.UserName,
                TemplateGuid = Guid.Parse("dd5f4fa2-545d-4d95-927b-94df4103483e")
            };

            configUnit.SaveAll();
        }
 internal static void Seed(BlogSystemContext dataBaseContext, IDistributedCache cache,
                           IHostingEnvironment hostingEnvironment, Configs configs)
 {
     FormatVerificationHelper.FormatVerification(
         configs.Email, FormatVerificationHelper.FormatType.Email,
         new ParametersFormatErrorException("邮箱格式错误。"));
     FormatVerificationHelper.FormatVerification(
         configs.Password, FormatVerificationHelper.FormatType.Password,
         new ParametersFormatErrorException("密码格式错误。"));
     FormatVerificationHelper.FormatVerification(
         configs.BlogName, FormatVerificationHelper.FormatType.BlogName,
         new ParametersFormatErrorException("博客名称格式错误。"));
     FormatVerificationHelper.FormatVerification(
         configs.UserName, FormatVerificationHelper.FormatType.UserName,
         new ParametersFormatErrorException("昵称格式错误。"));
     dataBaseContext.Database.EnsureDeleted();
     dataBaseContext.Database.EnsureCreated();
     using (var transaction = dataBaseContext.Database.BeginTransaction())
     {
         Config(dataBaseContext, cache, configs);
         TemplateFile(dataBaseContext, hostingEnvironment);
         transaction.Commit();
     }
 }