Esempio n. 1
0
        public static void EnsureSeedDataForContext(this OwnerPetsContext context)
        {
            if (context.Owners.Any())
            {
                return;
            }

            // init seed data
            var Owners = new List <Owner>()
            {
                new Owner()
                {
                    Name     = "Shaun",
                    Surname  = "Mynhardt",
                    PetInfos = new List <PetInfos>()
                    {
                        new PetInfos()
                        {
                            Name        = "Zoe",
                            Type        = "Chow",
                            Description = "Very active for her age"
                        },
                        new PetInfos()
                        {
                            Name        = "Misty",
                            Type        = "Chow",
                            Description = "Naughty and slight agressive"
                        },
                    }
                },
                new Owner()
                {
                    Name     = "Billy",
                    Surname  = "Bob",
                    PetInfos = new List <PetInfos>()
                    {
                        new PetInfos()
                        {
                            Name        = "King Shark",
                            Type        = "Pitbul",
                            Description = "AWesome pet to have :O!!"
                        }
                    }
                },
            };// end of dummy data

            context.Owners.AddRange(Owners);
            context.SaveChanges();
        }
Esempio n. 2
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, OwnerPetsContext ownerPetsContext)
        {
            loggerFactory.AddNLog();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            ownerPetsContext.EnsureSeedDataForContext();



            //set up MVC controler,models
            app.UseStatusCodePages();


            //map entinites with Dtos

            AutoMapper.Mapper.Initialize(cfg =>
            {
                //  cfg.CreateMap<Entities.Owner, OwnerDto>();
                cfg.CreateMap <Entities.Owner, Models.OwnerDto>();
                cfg.CreateMap <Entities.PetInfos, Models.PetInfoDto>();

                cfg.CreateMap <Models.PetInfoCreationDto, Entities.PetInfos>();
                cfg.CreateMap <PetInfoUpdateDto, PetInfos>();
            });

            app.UseMvc();


            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("Default Page");
            });
        }
Esempio n. 3
0
 public PetInfoController(OwnerPetsContext ownerPetsContext, IOwnerPetsRepository ownerPetsRepository)
 {
     _Owner   = ownerPetsContext;
     _Context = ownerPetsRepository;
 }
Esempio n. 4
0
 //create the link to DbCOntext
 public OwnerPetsRepository(OwnerPetsContext ownerPetsContext)
 {
     _Context = ownerPetsContext;
 }