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();
     }
 }
        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;
 }