예제 #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,
                              ILoggerFactory loggerFactory, PersonsCollectivesContext personsCollectivesContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(appBuilder =>
                {
                    appBuilder.Run(async context =>
                    {
                        context.Response.StatusCode = 500;
                        await context.Response.WriteAsync("An unexpected fault happened. Try again later.");
                    });
                });
            }

            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Entities.Person, Models.PersonDto>()
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src =>
                                                                 $"{src.Name} {src.Surname}"))
                .ForMember(dest => dest.Age, opt => opt.MapFrom(src =>
                                                                src.DateOfBirth.GetCurrentAge()));
                //.ForMember(dest => dest.Collectives, opt => opt.MapFrom(src =>
                //src.Collectives);

                cfg.CreateMap <Models.CreatePersonDto, Entities.Person>();

                cfg.CreateMap <Models.CollectiveDto, Entities.Collective>();
            });


            personsCollectivesContext.EnsureSeedDataForContext();

            app.UseMvcWithDefaultRoute();
        }
예제 #2
0
 public PersonRepository(PersonsCollectivesContext context)
 {
     _context = context;
 }