// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, SistemaAcademicoContext 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?}"); }); //inicializa la base DbInitializer.Initialier(context); }
public static void Initialier(SistemaAcademicoContext context) { context.Database.EnsureCreated(); //cre la base de datos //buscar si existen registros en la tabla categoria if (context.Categoria.Any()) //si hay categorias solo retorna eso y ya { return; } var categorias = new Categoria[] { new Categoria { Nombre = "Programación", Descripcion = "Cursos de Asp.-net", Estado = true }, new Categoria { Nombre = "Diseño", Descripcion = "Diseño grafico", Estado = true }, new Categoria { Nombre = "Reparación ", Descripcion = "Reparacion de celulares", Estado = true } }; foreach (Categoria c in categorias) { context.Categoria.Add(c); } context.SaveChanges(); }
public static void Initialize(SistemaAcademicoContext context) { context.Database.EnsureCreated(); //Se crea la base dedatos //Buscar si existen registros en la tabla Categoria if (context.Categoria.Any()) { return; } var categorias = new Categoria[] { new Categoria { Nombre = "Programación", Descripcion = "Curso de Programación", Estado = true }, new Categoria { Nombre = "Diseño gráfico", Descripcion = "Curso de diseño gráfico", Estado = true } }; foreach (Categoria categoria in categorias) { context.Categoria.Add(categoria); } 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, SistemaAcademicoContext context) { if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DBInitializer.Initialize(context); }
private readonly SistemaAcademicoContext _context;//contecto de datos public CategoriasController(SistemaAcademicoContext context) { _context = context; }
public EstudiantesController(SistemaAcademicoContext context) { _context = context; }
public CarrerasController(SistemaAcademicoContext context) { _context = context; }