public static void Initialize(sistemaWebContext context) { context.Database.EnsureCreated(); //buscar si existen registros en la tabla categoria if (context.Categoria.Any()) { return; } var categorias = new Categoria[] { new Categoria { Nombre = "Programación", Descripcion = "Cursos de programación", Estado = true }, new Categoria { Nombre = "Diseño gráfico", Descripcion = "Cursos de diseño gráfico", Estado = true } }; foreach (Categoria c in categorias) { context.Categoria.Add(c); } context.SaveChanges(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, sistemaWebContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DbInitializer.Initialize(context); }
public CategoriasController(sistemaWebContext context) { _context = context; }