public static IAnimalRepository GetInMemoryRepo() //This helper function creates a new AnimalRepository using In-Memory Database which we can use to test repo functions
        {
            DbContextOptions <AnimalCrossingContext> options;
            var builder = new DbContextOptionsBuilder <AnimalCrossingContext>();

            builder.UseInMemoryDatabase("testDB");
            options = builder.Options;
            AnimalCrossingContext animalCrossingContextTest = new AnimalCrossingContext(options);

            animalCrossingContextTest.Database.EnsureDeleted();
            animalCrossingContextTest.Database.EnsureCreated();

            return(new AnimalRepository(animalCrossingContextTest));
        }
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new AnimalCrossingContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <AnimalCrossingContext> >()))
            {
                // You add more code here to seed database.
                // See: https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/working-with-sql?view=aspnetcore-3.0&tabs=visual-studio
                if (!context.Species.Any())
                {
                    var species = new Species[] {
                        new Species {
                            Name = "Maine Coon", Description = "Very big cat..."
                        },
                        new Species {
                            Name = "Sphynx", Description = "With the right spelling"
                        },
                    };

                    context.Species.AddRange(species);
                    //foreach(var spec in species)
                    //{
                    //    context.Species.Add(spec);
                    //}

                    context.SaveChanges();
                }

                if (!context.Cats.Any())
                {
                    var speciesType = context.Species.ToList();

                    var cats = new Cat[]
                    {
                        new Cat {
                            Name = "Missy", Description = "Likes walks on the beach", Gender = Gender.Female, BirthDate = new DateTime(2000, 4, 3), ProfilePicture = "https://www.zooplus.dk/magasin/wp-content/uploads/2018/01/fotolia_138361424-768x658.jpg", SpeciesId = speciesType[0].SpeciesId
                        },
                        new Cat {
                            Name = "Baldy", Description = "Likes something ", Gender = Gender.Female, BirthDate = new DateTime(2004, 4, 3), ProfilePicture = "https://images2.minutemediacdn.com/image/upload/c_fill,g_auto,h_1248,w_2220/f_auto,q_auto,w_1100/v1555382975/shape/mentalfloss/sphinxhed.png", SpeciesId = speciesType[1].SpeciesId
                        },
                    };
                    context.Cats.AddRange(cats);


                    context.SaveChanges();
                }
            }
        }
示例#3
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new AnimalCrossingContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <AnimalCrossingContext> >()))


                // look for any species
                if (!context.Species.Any())
                {
                    var species = new Species[] {
                        new Species {
                            Name = "Sphynx", Description = "A species of cat that has no fur because of selective breeding starting in the 1960s"
                        },
                        new Species {
                            Name = "Black-footed cat", Description = "Smallest african cat and it has black spots"
                        }
                    };


                    foreach (Species s in species)
                    {
                        context.Species.Add(s);
                    }
                    context.SaveChanges();


                    var speciesType = context.Species.ToList();
                    var cats        = new Cat[]

                    {
                        new Cat {
                            Name = "McMittens", Gender = Gender.Male, BirthDate = DateTime.Parse("2018-10-12"), ProfilePicture = "http://www.karoocats.org/application/storage/image/resize/blackfooted_cat_16.jpg", Description = "Mcmittens likes catnip and female cats without fur", SpeciesId = speciesType[0].SpeciesId
                        },
                        new Cat {
                            Name = "zoe", Gender = Gender.Female, BirthDate = DateTime.Parse("2017-05-05"), ProfilePicture = "https://images2.minutemediacdn.com/image/upload/c_fill,g_auto,h_1248,w_2220/f_auto,q_auto,w_1100/v1555382975/shape/mentalfloss/sphinxhed.png", Description = "Fur less cat with no interest in plants", SpeciesId = speciesType[0].SpeciesId
                        }
                    };
                    foreach (Cat c in cats)
                    {
                        context.Cats.Add(c);
                    }
                    context.SaveChanges();
                }
        }
示例#4
0
 public AnimalRepository(AnimalCrossingContext _context)
 {
     this._context = _context;
 }
示例#5
0
 public DateRepository(AnimalCrossingContext context)
 {
     this._context = context;
 }
示例#6
0
 public SpeciesRepository(AnimalCrossingContext context)
 {
     this._context = context;
 }
示例#7
0
 public CatsController(AnimalCrossingContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }
示例#8
0
 public AnimalController(AnimalCrossingContext context)
 {
     _context = context;
 }
示例#9
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new AnimalCrossingContext(
                       serviceProvider.GetRequiredService <
                           Microsoft.EntityFrameworkCore.DbContextOptions <AnimalCrossingContext> >()))
            {
                if (!context.Species.Any()) //linq function
                {
                    var species = new Species[]
                    {
                        new Species {
                            Name = "Tabby", Description = "A tabby cat"
                        },                                            //not 0-indexed so this is id=1
                        new Species {
                            Name = "Calico", Description = "A Calico cat"
                        },                                              //notice you don't have to call constructor, but instead just add properties
                        new Species {
                            Name = "Norwegian Forest Cat", Description = "A Norwegian Forest cat"
                        },                                                                      //You can call constructor if you want though
                        new Species {
                            Name = "Siamese", Description = "A Siamese cat"
                        }
                    };
                    foreach (Species s in species)
                    {
                        context.Species.Add(s);
                    }
                    context.SaveChanges();
                }

                if (!context.Cats.Any())
                {
                    var speciesType = context.Species.ToList(); //Since the primary key is not reset when deleting a database, you have to create a list to be able to robustly pick the right speciesId
                                                                //It is better to do the ToList call here, since every time that function is called, the database is accessed. If you used it while creating the cat, you would end up using a lot of data

                    var cats = new Cat[]
                    {
                        new Cat {
                            Name = "Fat Cat", BirthDate = new DateTime(2019, 9, 23), Description = "Fat as f**k lil kitty", Gender = Gender.Male, SpeciesId = speciesType[0].SpeciesId, ProfilePicture = "https://pbs.twimg.com/media/DtBuHPeWkAAu9q8.jpg"
                        },                                                                                                                                                                                                                   //Notice that you access the Gender enum, then choose your gender within that
                        new Cat {
                            Name = "Spunky", BirthDate = new DateTime(2019, 9, 23), Description = "Got a lotta spunk", Gender = Gender.Male, SpeciesId = speciesType[1].SpeciesId, ProfilePicture = "https://upload.wikimedia.org/wikipedia/en/8/87/Keyboard_cat.jpg"
                        },                                                                                                                                                                                                                              //Notice the speciesType allows us to access the first (0th) index of species, instead of the SpeciesID
                        new Cat {
                            Name = "TipTop", BirthDate = new DateTime(2019, 9, 23), Description = "Best cat", Gender = Gender.Female, SpeciesId = speciesType[2].SpeciesId, ProfilePicture = "https://i.kym-cdn.com/entries/icons/original/000/026/638/cat.jpg"
                        },
                        new Cat {
                            Name = "Somebody", BirthDate = new DateTime(2019, 9, 23), Description = "Just a cat", Gender = Gender.Male, SpeciesId = speciesType[3].SpeciesId, ProfilePicture = "https://66.media.tumblr.com/31aca5977137e87fd301d79781c4263c/tumblr_inline_ofu86bnxV21r7k951_540.jpg"
                        },
                        new Cat {
                            Name = "Pugio", BirthDate = new DateTime(2019, 12, 15), Description = "A cat you used to know", Gender = Gender.Other, SpeciesId = speciesType[2].SpeciesId, ProfilePicture = "https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/cute-cat-breeds-ragdoll-1568332272.jpg?crop=0.668xw:1.00xh;0.104xw,0&resize=480:*"
                        }
                    };
                    foreach (Cat c in cats)
                    {
                        context.Cats.Add(c);

                        context.SaveChanges();
                    }
                }
            }
        }
示例#10
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new AnimalCrossingContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <AnimalCrossingContext> >()))
            {
                // You add more code here to seed database.
                // See: https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/working-with-sql?view=aspnetcore-3.0&tabs=visual-studio
                if (!context.Species.Any())
                {
                    var species = new Species[] {
                        new Species {
                            Name = "Curl", Description = "American Curl"
                        },
                        new Species {
                            Name = "Bengal", Description = "Bengalise Cat"
                        },
                        new Species {
                            Name = "Chartreux", Description = "French Breed"
                        },
                        new Species {
                            Name = "Himalayan", Description = "Himalayan Cat Breed"
                        },
                        new Species {
                            Name = "Persian", Description = "Persian Cat Breed"
                        },
                        new Species {
                            Name = "Siberian", Description = "Siberian Cat Breed"
                        }
                    };

                    context.Species.AddRange(species);

                    context.SaveChanges();
                }

                if (!context.Cats.Any())
                {
                    var speciesType = context.Species.ToList();

                    var cats = new Cat[]
                    {
                        new Cat {
                            Name = "Findus", BirthDate = new DateTime(2019, 9, 23), Description = "Fat and lazy", Gender = Gender.Female, SpeciesId = speciesType[0].SpeciesId, ProfilePicture = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/American_curl_2.jpg/1200px-American_curl_2.jpg"
                        },
                        new Cat {
                            Name = "Tigeren", BirthDate = new DateTime(2017, 12, 25), Description = "A Wild boy", Gender = Gender.Male, SpeciesId = speciesType[1].SpeciesId, ProfilePicture = "https://fluffyplanet.com/wp-content/uploads/2019/07/shutterstock_582832921.jpg"
                        },
                        new Cat {
                            Name = "Makronen", BirthDate = new DateTime(2017, 5, 7), Description = "Always loves a treat", Gender = Gender.Male, SpeciesId = speciesType[2].SpeciesId, ProfilePicture = "https://www.madpaws.com.au/wp-content/uploads/2019/11/Chartreux.jpg"
                        },
                        new Cat {
                            Name = "Lama", BirthDate = new DateTime(2012, 4, 10), Description = "Always relaxed", Gender = Gender.Male, SpeciesId = speciesType[3].SpeciesId, ProfilePicture = "https://www.holidogtimes.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-15-at-12.55.48-1-810x411.png"
                        },
                        new Cat {
                            Name = "Darius", BirthDate = new DateTime(2015, 7, 14), Description = "Comes from a respectably dynasty", Gender = Gender.Male, SpeciesId = speciesType[4].SpeciesId, ProfilePicture = "https://vetstreet.brightspotcdn.com/dims4/default/7cc218c/2147483647/thumbnail/645x380/quality/90/?url=https%3A%2F%2Fvetstreet-brightspot.s3.amazonaws.com%2Fa5%2F69%2Fe639b7ab40c2a290e3296de726d8%2FPersian-AP-PIFN6J-645sm3614.jpg"
                        },
                        new Cat {
                            Name = "Sevasto", BirthDate = new DateTime(2018, 9, 9), Description = "Loves the winter", Gender = Gender.Female, SpeciesId = speciesType[5].SpeciesId, ProfilePicture = "https://lh3.googleusercontent.com/MYu5kqr9f8JjBqMkIyzRLvD_PR_dQtFtbu1IAm6e_cwgKBFbY42Wg55cw36l07bah0r_"
                        },
                        new Cat {
                            Name = "Sorte", BirthDate = new DateTime(2014, 12, 17), Description = "Loves the dark", Gender = Gender.Female, SpeciesId = speciesType[2].SpeciesId, ProfilePicture = "https://www.dogalize.com/wp-content/uploads/2017/03/Chartreux-cat.jpg"
                        },
                        new Cat {
                            Name = "Nougat", BirthDate = new DateTime(2017, 3, 19), Description = "Very Playful", Gender = Gender.Female, SpeciesId = speciesType[0].SpeciesId, ProfilePicture = "https://i.pinimg.com/originals/fb/b7/0e/fbb70ee540d2f7e9f90739b4f0903fba.jpg"
                        }
                    };
                    context.Cats.AddRange(cats);


                    context.SaveChanges();
                }
            }
        }
示例#11
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new AnimalCrossingContext(
                       serviceProvider.GetRequiredService <
                           Microsoft.EntityFrameworkCore.DbContextOptions <AnimalCrossingContext> >()))
            {
                if (!context.Species.Any())
                {
                    var species = new Species[]
                    {
                        new Species {
                            Name = "Curl", Description = "American Curl"
                        },
                        new Species {
                            Name = "Bengal", Description = "Bengalise Cat"
                        },
                        new Species {
                            Name = "Chartreux", Description = "French Breed"
                        },
                        new Species {
                            Name = "Himalayan", Description = "Himalayan Cat Breed"
                        },
                        new Species {
                            Name = "Persian", Description = "Persian Cat Breed"
                        },
                        new Species {
                            Name = "Siberian", Description = "Siberian Cat Breed"
                        }
                    };
                    foreach (Species s in species)
                    {
                        context.Species.Add(s);
                    }
                    context.SaveChanges();
                }

                if (!context.Cats.Any())
                {
                    var speciesType = context.Species.ToList();

                    var cats = new Cat[] {
                        new Cat {
                            Name = "Findus", BirthDate = new DateTime(2019, 9, 23), Description = "Fat and lazy", Gender = Gender.Female, SpeciesId = speciesType[0].SpeciesId
                        },
                        new Cat {
                            Name = "Tigeren", BirthDate = new DateTime(2017, 12, 25), Description = "A Wild boy", Gender = Gender.Male, SpeciesId = speciesType[1].SpeciesId
                        },
                        new Cat {
                            Name = "Makronen", BirthDate = new DateTime(2017, 5, 7), Description = "Always loves a treat", Gender = Gender.Male, SpeciesId = speciesType[2].SpeciesId
                        },
                        new Cat {
                            Name = "Lama", BirthDate = new DateTime(2012, 4, 10), Description = "Always relaxed", Gender = Gender.Male, SpeciesId = speciesType[3].SpeciesId
                        },
                        new Cat {
                            Name = "Darius", BirthDate = new DateTime(2015, 7, 14), Description = "Comes from a respectably dynasty", Gender = Gender.Male, SpeciesId = speciesType[4].SpeciesId
                        },
                        new Cat {
                            Name = "Sevasto", BirthDate = new DateTime(2018, 9, 9), Description = "Loves the winter", Gender = Gender.Female, SpeciesId = speciesType[5].SpeciesId
                        },
                        new Cat {
                            Name = "Sorte", BirthDate = new DateTime(2014, 12, 17), Description = "Loves the dark", Gender = Gender.Female, SpeciesId = speciesType[2].SpeciesId
                        },
                        new Cat {
                            Name = "Nougat", BirthDate = new DateTime(2017, 3, 19), Description = "Very Playful", Gender = Gender.Female, SpeciesId = speciesType[0].SpeciesId
                        }
                    };
                    foreach (Cat c in cats)
                    {
                        context.Cats.Add(c);

                        context.SaveChanges();
                    }
                }
            }
        }
 public AnimalController(AnimalCrossingContext context, IAnimalRepository iAnimalRepo, ISpeciesRepository Species)
 {
     _context    = context;
     IAnimalRepo = iAnimalRepo;
     SpeciesRepo = Species;
 }