public async Task CleanAsync(UsuarioContext context, IHostingEnvironment env, IOptions <UsuarioSettings> settings, ILogger <UsuarioContextSeed> logger) { var policy = CreatePolicy(logger, nameof(UsuarioContextSeed)); try { await policy.ExecuteAsync(async() => { var useCustomizationData = settings.Value.UseCustomizationData; var contentRootPath = env.ContentRootPath; context.SetorItems.FromSql("SELECT * FROM SETOR"); IEnumerable <UsuarioItem> st; st = useCustomizationData ? GetSetorItemsFromFile(contentRootPath, context, logger) : GetPreconfiguredItems(); foreach (UsuarioItem it in st) { var item = await context.SetorItems.SingleOrDefaultAsync(ci => ci.id_Setor == it.id_Setor); if (item != null) { context.SetorItems.Remove(item); } } await context.SaveChangesAsync(); }); } catch (DbUpdateConcurrencyException ex) { } }
public async Task SeedAsync(UsuarioContext context, IHostingEnvironment env, IOptions <UsuarioSettings> settings, ILogger <UsuarioContextSeed> logger) { var policy = CreatePolicy(logger, nameof(UsuarioContextSeed)); await policy.ExecuteAsync(async() => { var useCustomizationData = settings.Value.UseCustomizationData; var contentRootPath = env.ContentRootPath; await context.SetorItems.AddRangeAsync(useCustomizationData ? GetSetorItemsFromFile(contentRootPath, context, logger) : GetPreconfiguredItems()); await context.SaveChangesAsync(); }); }