public static void EnsureSeedDataForContext(this AlbumInfoContext context)
        {
            if (context.Albums.Any())
            {
                return;
            }

            var albums = new List <Album>()
            {
                new Album()
                {
                    Name   = "The Slim Shady",
                    Artist = "Eminem",
                    Tracks = new List <Track>()
                    {
                        new Track()
                        {
                            Name     = "My Name Is",
                            Duration = 1.59f
                        },
                        new Track()
                        {
                            Name     = "RoleModel",
                            Duration = 3.56f
                        },
                        new Track()
                        {
                            Name     = "Bad Meets Evil",
                            Duration = 5.22f
                        },
                        new Track()
                        {
                            Name     = "My Fault",
                            Duration = 6.43f
                        },
                    }
                },
                new Album()
                {
                    Name   = "Daytona",
                    Artist = "Pusha T",
                    Tracks = new List <Track>()
                    {
                        new Track()
                        {
                            Name     = "Infrared",
                            Duration = 2.13f
                        },
                        new Track()
                        {
                            Name     = "Santeria",
                            Duration = 12.43f
                        },
                    }
                },
                new Album()
                {
                    Name   = "To Pimp A Butterfly",
                    Artist = "Kendrick Lamar",
                    Tracks = new List <Track>()
                    {
                        new Track()
                        {
                            Name     = "King Kunta",
                            Duration = 4.00f
                        },
                        new Track()
                        {
                            Name     = "u",
                            Duration = 4.45f
                        },
                        new Track()
                        {
                            Name     = "i",
                            Duration = 3.22f
                        },
                        new Track()
                        {
                            Name     = "Alright",
                            Duration = 5.43f
                        },
                        new Track()
                        {
                            Name     = "Mortal Man",
                            Duration = 3.53f
                        },
                    }
                },
                new Album()
                {
                    Name   = "Lenske",
                    Artist = "Amelie Lens",
                    Tracks = new List <Track>()
                    {
                        new Track()
                        {
                            Name     = "NeverTheSame",
                            Duration = 9.9f
                        }
                    }
                }
            };

            context.Albums.AddRange(albums);
            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, ILoggerFactory loggerFactory, AlbumInfoContext albumInfoContext)
        {
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();
            loggerFactory.AddNLog();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            albumInfoContext.EnsureSeedDataForContext();
            //app.UseHttpsRedirection();
            app.UseStatusCodePages();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Entities.Album, Models.AlbumWithoutTracksDto>();
                cfg.CreateMap <Entities.Album, Models.AlbumDto>();
                cfg.CreateMap <Entities.Track, Models.TrackDto>();
                cfg.CreateMap <Models.TrackForCreationDto, Entities.Track>();
                cfg.CreateMap <Models.TrackForUpdateDto, Entities.Track>();
                cfg.CreateMap <Entities.Track, Models.TrackForUpdateDto>();
            });
            app.UseMvc();
        }
Exemplo n.º 3
0
 public DummyController(AlbumInfoContext ctx)
 {
     _ctx = ctx;
 }
 public AlbumInfoRepository(AlbumInfoContext context)
 {
     _context = context;
 }