Пример #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,
            OnlineTaskListsContext taskListContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            //this is used for autherization
            app.UseAuthentication();

            //This is for Seeding comment this when ading migration, comment this out when creating new migration
            taskListContext.EnsureSeedDataForContext();

            AutoMapper.Mapper.Initialize(
                cfg =>
            {
                cfg.CreateMap <Models.UserTaskForCreateDTO, Entities.UserTask>()
                .ForMember(dest => dest.UserTaskID, opt => opt.MapFrom(o => new Guid()))
                .ForMember(dest => dest.DateCreated, opt => opt.MapFrom(o => DateTime.Now))
                .ForMember(dest => dest.IsDone, opt => opt.MapFrom(o => false));
                cfg.CreateMap <Models.UserTaskForUpdateDTO, Entities.UserTask>();
            });

            app.UseMvc();
        }
Пример #2
0
        private static void SeedTaskLists(OnlineTaskListsContext ctx)
        {
            if (ctx.UserTasks.Any())
            {
                return;
            }

            var userTaskLists = new List <UserTask>()
            {
                new UserTask()
                {
                    UserTaskID  = new Guid(),
                    UserID      = "3142b052-f32a-408a-ace9-f6a556e92c1b",
                    Title       = "Initial",
                    Description = "sample Description",
                    DateCreated = DateTime.Now,
                    IsDone      = true
                },
                new UserTask()
                {
                    UserTaskID  = new Guid(),
                    UserID      = "3142b052-f32a-408a-ace9-f6a556e92c1b",
                    Title       = "Secondary",
                    Description = "sample 2 Description",
                    DateCreated = (DateTime.Now).AddDays(1),
                    IsDone      = true
                },
                new UserTask()
                {
                    UserTaskID  = new Guid(),
                    UserID      = "00875856-227c-4649-90b9-4846e79d2730",
                    Title       = "Trionary",
                    Description = "sample 3 Description",
                    DateCreated = (DateTime.Now).AddDays(1),
                    IsDone      = true
                }
            };

            ctx.UserTasks.AddRange(userTaskLists);
            ctx.SaveChanges();
        }
 public OnlineTaskListsRepository(OnlineTaskListsContext ctx)
 {
     _ctx = ctx;
 }
Пример #4
0
 public static void EnsureSeedDataForContext(this OnlineTaskListsContext ctx)
 {
     SeedTaskLists(ctx);
 }