public static void Initialize(SistemaContexto context)
        {
            context.Database.EnsureCreated();

            //Buscar si existen registros en la tabla categoria
            if (context.Categoria.Any())
            {
                return;
            }
            var categorias = new Categoria[]
            {
                new Categoria {
                    Nombre = "Programacion", Descripcion = "Cursos de programacion",
                    Estado = true
                },
                new Categoria {
                    Nombre = "Diseño", Descripcion = "Cursos de diseño grafico",
                    Estado = true
                }
            };

            foreach (Categoria c in categorias)
            {
                context.Categoria.Add(c);
            }

            context.SaveChanges();
        }
示例#2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, SistemaContexto 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: context);
        }
 public CategoriasController(SistemaContexto context)
 {
     _context = context;
 }