// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, PostsInfoContext postsInfoContext) { //if (env.IsDevelopment()) //{ // app.UseDeveloperExceptionPage(); //} //app.Run(async (context) => //{ // await context.Response.WriteAsync("Hello World!"); //}); postsInfoContext.EnsureSeedDataForContext(); app.UseStatusCodePages(); AutoMapper.Mapper.Initialize(cfg => { //Mapper to get the posts cfg.CreateMap <Entities.Posts, Models.AllPostsDto>(); cfg.CreateMap <Entities.Posts, Models.PostsDto>(); cfg.CreateMap <Models.CreatePostDto, Entities.Posts>(); }); app.UseCors("CorsPolicy"); app.UseMvc(); }
public static void EnsureSeedDataForContext(this PostsInfoContext context) { //If posts exist, don't create the data if (context.Post != null) { if (context.Post.Any()) { return; } } if (context.Post.Any()) { return; } var posts = new List <Posts>() { new Posts() { Title = "Title 1", Category = "Testing Category 1", Message = "This is my message for Title 1 in Category 1" }, new Posts() { Title = "Title 2", Category = "Testing Category 2", Message = "This is my message for Title 1 in Category 2" }, new Posts() { Title = "Title 3", Category = "Testing Category 3", Message = "This is my message for Title 1 in Category 3" }, }; context.Post.AddRange(posts); context.SaveChanges(); }
public DummyController(PostsInfoContext ctx) { _ctx = ctx; }
public PostsInfoRepository(PostsInfoContext context) { _context = context; }