示例#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, NoterContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStatusCodePages();

            app.UseAuthentication();

            context.EnsureData();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Topic, TopicDto>().ForMember(dest => dest.CommentariesCount, opts => opts.MapFrom(src => src.Commentaries.Count));
                cfg.CreateMap <TopicForCreationDto, Topic>();
                cfg.CreateMap <Commentary, CommentaryDto>();//.ForMember(dest => dest.Created, opts => opts.MapFrom(src => src.Created.ToShortDateString()));
                cfg.CreateMap <CommentaryForCreation, Commentary>();
                cfg.CreateMap <Commentary, CommentaryForUpdate>();
                cfg.CreateMap <CommentaryForUpdate, Commentary>();
                cfg.CreateMap <Topic, TopicForUpdateDto>();
                cfg.CreateMap <TopicForUpdateDto, Topic>();
            });

            app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().AllowCredentials().WithExposedHeaders("X-Pagination"));

            app.UseMvc();
        }
示例#2
0
        public static void EnsureData(this NoterContext context)
        {
            if (context.Topics.Any())
            {
                return;
            }
            var topics = new List <Topic>
            {
                new Topic
                {
                    Title        = "Personal Page",
                    Description  = "This topic is about me",
                    Commentaries = new List <Commentary>
                    {
                        new Commentary
                        {
                            Title    = "I know how to prepare guacamole",
                            Content  = "First you prepare the blyat.. hahaha cyka blyat. I am just kidding.",
                            Approval = 3
                        },
                        new Commentary
                        {
                            Title    = "Hihihi",
                            Content  = "you are such a moron, you are such an idiot",
                            Approval = 1
                        }
                    }
                },
                new Topic
                {
                    Title        = "How to prepare cake?",
                    Description  = "This topic is about how to prepare cake fast and in a proper manner.",
                    Commentaries = new List <Commentary>
                    {
                        new Commentary
                        {
                            Title    = "I know how to prepare cake instead",
                            Content  = "Boooring",
                            Approval = 5
                        },
                        new Commentary
                        {
                            Title    = "Hahaha",
                            Content  = "you are such a moron twoo.. tooo.. get it ????",
                            Approval = 4
                        }
                    }
                }
            };

            context.Topics.AddRange(topics);
            context.SaveChanges();;
        }
 public NotesRepository(NoterContext context)
 {
     this.context = context;
 }
示例#4
0
 public TopicsRepository(NoterContext context)
 {
     this.context = context;
 }
示例#5
0
 public NoterUserStore(NoterContext context)
 {
     this.context = context;
 }
示例#6
0
 public TestController(NoterContext context)
 {
     this.context = context;
 }
示例#7
0
 public AuthRepository(NoterContext context)
 {
     this.context = context;
 }