コード例 #1
0
        public PetsRepository(SimpleAppContext context)
        {
            _context = context;

            if (_context.Pets.Count() == 0)
            {
                _context.Pets.AddRange(
                    new Pet
                {
                    Name    = "Opie",
                    Breed   = "Shih Tzu",
                    PetType = PetType.Dog
                },
                    new Pet
                {
                    Name    = "Reggie",
                    Breed   = "Beagle",
                    PetType = PetType.Dog
                },
                    new Pet
                {
                    Name    = "Diesel",
                    Breed   = "Bombay",
                    PetType = PetType.Cat
                },
                    new Pet
                {
                    Name    = "Lucy",
                    Breed   = "Maine Coon",
                    PetType = PetType.Cat
                });
                _context.SaveChanges();
            }
        }
コード例 #2
0
 public List <PersonDto> GetAllPersons()
 {
     using (var context = new SimpleAppContext())
     {
         return(context.Persons.ToList());
     }
 }
コード例 #3
0
        public void DeletePerson(int id)
        {
            using (var context = new SimpleAppContext()){
                var personToDelete = context.Persons.Find(id);

                if (personToDelete != null)
                {
                    context.Persons.Remove(personToDelete);
                }
            }
        }
コード例 #4
0
 public void AddNewPerson(string name, string nickName, string tel)
 {
     using (var context = new SimpleAppContext()){
         var newPerson = new PersonDto()
         {
             Name            = name,
             NickName        = nickName,
             TelephoneNumber = tel,
         };
         context.Persons.Add(newPerson);
         context.SaveChanges();
     }
 }
コード例 #5
0
        public ProductsRepository(SimpleAppContext context)
        {
            _context = context;

            if (_context.Products.Count() == 0)
            {
                _context.Products.AddRange(
                    new Product
                {
                    IsDiscontinued = true,
                    Name           = "Learning ASP.NET Core",
                    Description    = "A best-selling book covering the fundamentals of ASP.NET Core"
                },
                    new Product
                {
                    Name        = "Learning EF Core",
                    Description = "A best-selling book covering the fundamentals of Entity Framework Core"
                });
                _context.SaveChanges();
            }
        }
コード例 #6
0
 public EApplicationRepository(SimpleAppContext context)
 {
     _context = context;
 }