public void Generators_are_associated_with_database_root()
        {
            var serviceProvider1 = new ServiceCollection()
                                   .AddEntityFrameworkInMemoryDatabase()
                                   .BuildServiceProvider();

            var serviceProvider2 = new ServiceCollection()
                                   .AddEntityFrameworkInMemoryDatabase()
                                   .BuildServiceProvider();

            var root = new InMemoryDatabaseRoot();

            var olives = new Olive[2];
            var toasts = new Toast[2];

            using (var context = new PetsContext("Drink", root, serviceProvider1))
            {
                olives[0] = context.Add(new Olive()).Entity;
                toasts[0] = context.Add(new Toast()).Entity;

                Assert.Equal(1, olives[0].Id);
                Assert.Equal(1, toasts[0].Id);

                context.SaveChanges();
            }

            using (var context = new PetsContext("Drink", root, serviceProvider2))
            {
                olives[1] = context.Add(new Olive()).Entity;
                toasts[1] = context.Add(new Toast()).Entity;

                Assert.Equal(2, olives[1].Id);
                Assert.Equal(2, toasts[1].Id);

                context.SaveChanges();
            }

            Assert.Equal(1, olives[0].Id);
            Assert.Equal(1, toasts[0].Id);
            Assert.Equal(2, olives[1].Id);
            Assert.Equal(2, toasts[1].Id);
        }
Esempio n. 2
0
        private static void CreateDB()
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json")
                                    .Build();

            var options = new DbContextOptionsBuilder <PetsContext>()
                          .UseSqlServer(config.GetConnectionString("PetsDB"))
                          .Options;

            using var db = new PetsContext(options);

            db.Database.EnsureDeleted();
            db.Database.EnsureCreated();

            var owner = CreateData();

            db.Owners.Add(owner);

            db.SaveChanges();
        }
Esempio n. 3
0
        public ActionResult List(string searchString, string all, string MoveGender = null)
        {
            PetsContext petsConx = new PetsContext();
            var         pets     = from m in petsConx.Pets
                                   select m;

            if (!String.IsNullOrEmpty(searchString))
            {
                pets = pets.Where(s => s.Name.Contains(searchString));
            }

            //ViewBag.SelectedGender = gender;

            if (MoveGender != null && MoveGender != "Выбрать пол")
            {
                pets = pets.Where(s => s.Gender == (MoveGender == "Женский" ? true: false));
            }

            List <SelectListItem> genderItems = new List <SelectListItem>();

            genderItems.Add(new SelectListItem()
            {
                Text = "Выбрать пол", Selected = (MoveGender) == null ? true : false
            });
            genderItems.Add(new SelectListItem()
            {
                Text = "Мужской", Value = "Мужской", Selected = (MoveGender) == "Мужской" ? true : false
            });
            genderItems.Add(new SelectListItem()
            {
                Text = "Женский", Value = "Женский", Selected = (MoveGender) == "Женский" ? true : false
            });
            ViewBag.MoveGender = genderItems;

            return(View(pets));
        }
Esempio n. 4
0
        private static void ShowDBData()
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json")
                                    .Build();

            var options = new DbContextOptionsBuilder <PetsContext>()
                          .UseSqlServer(config.GetConnectionString("PetsDB"))
                          .Options;

            using var db = new PetsContext(options);

            Console.WriteLine("From Owner:");
            Console.WriteLine(db.Owners.Include(o => o.Pets).First());

            Console.WriteLine("All Pets:");

            foreach (var p in db.Pets)
            {
                Console.WriteLine(p);
            }

            Console.WriteLine("\nAll Cats:");

            foreach (var c in db.Cats)
            {
                Console.WriteLine(c);
            }

            Console.WriteLine("\nAll Dogs:");

            foreach (var d in db.Dogs)
            {
                Console.WriteLine(d);
            }
        }
Esempio n. 5
0
 public PetRepository(PetsContext context)
 {
     db = context;
 }
Esempio n. 6
0
    public void Each_property_gets_its_own_generator()
    {
        var macs   = new Mac[4];
        var toasts = new Toast[4];

        using (var context = new PetsContext("Dance"))
        {
            macs[0]   = context.Add(new Mac()).Entity;
            toasts[0] = context.Add(new Toast()).Entity;

            Assert.Equal(1, macs[0].Id);
            Assert.Equal(1, toasts[0].Id);

            macs[1]   = context.Add(new Mac()).Entity;
            toasts[1] = context.Add(new Toast()).Entity;

            Assert.Equal(2, macs[1].Id);
            Assert.Equal(2, toasts[1].Id);

            context.SaveChanges();

            Assert.Equal(1, macs[0].Id);
            Assert.Equal(1, toasts[0].Id);
            Assert.Equal(2, macs[1].Id);
            Assert.Equal(2, toasts[1].Id);

            macs[2]   = context.Add(new Mac()).Entity;
            toasts[2] = context.Add(new Toast()).Entity;

            Assert.Equal(3, macs[2].Id);
            Assert.Equal(3, toasts[2].Id);

            context.SaveChanges();
        }

        using (var context = new PetsContext("Dance"))
        {
            macs[3]   = context.Add(new Mac()).Entity;
            toasts[3] = context.Add(new Toast()).Entity;

            Assert.Equal(4, macs[3].Id);
            Assert.Equal(4, toasts[3].Id);

            context.SaveChanges();
        }

        Assert.Equal(1, macs[0].Id);
        Assert.Equal(1, toasts[0].Id);
        Assert.Equal(2, macs[1].Id);
        Assert.Equal(2, toasts[1].Id);
        Assert.Equal(3, macs[2].Id);
        Assert.Equal(3, toasts[2].Id);
        Assert.Equal(4, macs[3].Id);
        Assert.Equal(4, toasts[3].Id);

        using (var context = new PetsContext("Dance"))
        {
            macs   = context.Macs.OrderBy(e => e.Id).ToArray();
            toasts = context.CookedBreads.OrderBy(e => e.Id).ToArray();
        }

        Assert.Equal(1, macs[0].Id);
        Assert.Equal(1, toasts[0].Id);
        Assert.Equal(2, macs[1].Id);
        Assert.Equal(2, toasts[1].Id);
        Assert.Equal(3, macs[2].Id);
        Assert.Equal(3, toasts[2].Id);
        Assert.Equal(4, macs[3].Id);
        Assert.Equal(4, toasts[3].Id);
    }
Esempio n. 7
0
        private void AddPet(object sender, RoutedEventArgs e)
        {
            String name = Name.Text;

            if (Age.Text == "")
            {
                MessageBox.Show("Fill all required fields!");
                return;
            }
            int       age         = Int32.Parse(Age.Text);
            String    breed       = Breed.Text;
            String    description = Description.Text;
            EntAnimal animal      = new EntAnimal();

            if (name == "")
            {
                MessageBox.Show("Fill all required fields!");
                return;
            }
            if (imageData == null)
            {
                MessageBox.Show("Fill all required fields!");
                return;
            }

            animal.name  = name;
            animal.image = imageData;
            animal.age   = age;
            int size_id = 0;

            if (size == "Small")
            {
                size_id = 1;
            }
            else if (size == "Medium")
            {
                size_id = 2;
            }
            else
            {
                size_id = 3;
            }
            animal.sizeId = size_id;
            int type_id = 0;

            if (type == "Cat")
            {
                type_id = 2;
            }
            else
            {
                type_id = 1;
            }
            animal.typeId = type_id;
            if (breed == "")
            {
                MessageBox.Show("Fill all required fields!");
                return;
            }
            animal.breed = breed;
            if (description == "")
            {
                MessageBox.Show("Fill all required fields!");
                return;
            }
            animal.description = description;
            animal.sex         = sex;
            PetsContext context = new PetsContext();

            context.Animals.Add(animal);
            context.SaveChanges();
            petsImproved.MainWindow.AppWindow.getData();
            this.Close();
        }
Esempio n. 8
0
        public ActionResult Info()
        {
            PetsContext pets = new PetsContext();

            return(View(pets.Pets));
        }
 public HomeController(ILogger <HomeController> logger, PetsContext petsContext, IWebHostEnvironment env)
 {
     _logger      = logger;
     _petsContext = petsContext;
     _env         = env;
 }
Esempio n. 10
0
 public ProductsController(PetsContext context)
 {
     _context = context;
 }
Esempio n. 11
0
 public AnimalRepository(PetsContext context)
 {
     _context = context;
 }
Esempio n. 12
0
 public HomeController(PetsContext db)
 {
     _db = db;
 }
Esempio n. 13
0
 public OwnersRepository(ILoggerFactory loggerFactory, PetsContext petsContext)
 {
     _logger      = loggerFactory.CreateLogger <OwnersRepository>();
     _petsContext = petsContext;
 }
Esempio n. 14
0
 public PetsController(PetsContext db, IHostingEnvironment environment)
 {
     _db = db;
     hostingEnvironment = environment;
 }
Esempio n. 15
0
 public OwnersController(PetsContext context)
 {
     _context = context;
 }
 public OwnerRepository(PetsContext context)
 {
     db = context;
 }
Esempio n. 17
0
 public PetsController(ILogger <PetsController> logger, PetsContext petsContext, IMapper mapper)
 {
     _logger          = logger;
     this.petsContext = petsContext;
     this.mapper      = mapper;
 }
 public UnitOfWork(PetsContext context)
 {
     db = context;
     OwnerRepository = new OwnerRepository(context);
     PetRepository   = new PetRepository(context);
 }
 public BanhoPetsController(PetsContext context)
 {
     _context = context;
 }
Esempio n. 20
0
 public UserRepository(PetsContext context)
 {
     _context = context;
 }