示例#1
0
        // 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();
        }
示例#2
0
 public SimpleQaRepository(SimpleQaContext context)
 {
     _context = context;
 }
示例#3
0
        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();
        }