// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, SimpleQaContext simpleQaContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); // Only useful when having web server with ssl app.UseExceptionHandler("/error"); } simpleQaContext.EnsureSeedDataForContext(); app.UseStatusCodePages(); app.UseHttpsRedirection(); // Only useful when having web server with ssl app.UseMvc(); }
public SimpleQaRepository(SimpleQaContext context) { _context = context; }
public static void EnsureSeedDataForContext(this SimpleQaContext context) { if (context.Question.Any()) { return; } var questions = new List <Question>() { new Question() { Title = "What is the best programming language?", Message = "Tried the best language", Comments = new List <Comment>() { new Comment() { Content = "Python duuuuuude" }, new Comment() { Content = "No, don't listen to the guy, its JavaScript all the way" } } }, new Question() { Title = "How do I learn programming?", Message = "Can I get sources", Comments = new List <Comment>() { new Comment() { Content = "W3 schools try it" }, new Comment() { Content = "You are not worthy" } } }, new Question() { Title = "What is better ios or android", Message = "Trying to buy a new phone right, please keep it holy", Comments = new List <Comment>() { new Comment() { Content = "F*** Android !!!!" }, new Comment() { Content = "Apple sheeps!!!" } } } }; context.Question.AddRange(questions); context.SaveChanges(); }