Esempio n. 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, ToDoDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                DbSeeder.Migrate(context);
            }

#pragma warning disable 618
            Mapper.Initialize(cfg =>
#pragma warning restore 618
            {
                cfg.CreateMap <ToDo, ToDoDto>().ForMember(dest => dest.ToDoPriority, opt =>
                                                          opt.MapFrom(src => src.ToDoPriority.Name))
                .ForMember(dest => dest.Status, opt => opt.MapFrom(src =>
                                                                   src.Status.ToString()))
                .ForMember(dest => dest.ToDoTime, opt => opt.MapFrom(src =>
                                                                     src.ToDoTime.ToString("dd MMM yy HH:mm")))
                .ForMember(dest => dest.CreatedAt, opt => opt.MapFrom(src =>
                                                                      src.CreatedAt.ToString("dd MMM yy HH:mm")));
                cfg.CreateMap <AddNewToDoCommand, ToDo>().ForMember(dest => dest.ToDoTime,
                                                                    opt => opt.MapFrom(src => src.ConvertTime()))
                .ForMember(dest => dest.CreatedAt, opt => opt.MapFrom(
                               src => DateTime.Now))
                .ForMember(dest => dest.Status, opt => opt.MapFrom(
                               src => ToDoStatus.Open));
            });

            app.UseMvc();

            //app.Run(async (context) =>
            //{
            //    await context.Response.WriteAsync("Hello World!");
            //});
        }