Beispiel #1
0
        public void AddCar(Car car)
        {
            var ctx = new PeopleCarsDbContext(_connectionString);

            ctx.Cars.Add(car);
            ctx.SaveChanges();
        }
Beispiel #2
0
        public void AddPerson(Person person)
        {
            var ctx = new PeopleCarsDbContext(_connectionString);

            ctx.People.Add(person);
            ctx.SaveChanges();
        }
Beispiel #3
0
        public List <Person> GetSearch(string searchText)
        {
            var context = new PeopleCarsDbContext(_connectionString);

            return(context.People
                   .Where(p => p.FirstName.ToLower().Contains(searchText.ToLower()) || p.LastName.ToLower().Contains(searchText.ToLower()))
                   .Include(p => p.Cars)
                   .ToList());
        }
Beispiel #4
0
 public void DeleteCars(int id)
 {
     using var context = new PeopleCarsDbContext(_connectionString);
     context.Database.ExecuteSqlInterpolated($"DELETE FROM Cars WHERE personId = {id}");
 }
Beispiel #5
0
        public List <Car> GetCarsForPerson(int id)
        {
            var ctx = new PeopleCarsDbContext(_connectionString);

            return(ctx.Cars.Where(c => c.PersonId == id).ToList());
        }
Beispiel #6
0
        public Person GetPersonById(int id)
        {
            var ctx = new PeopleCarsDbContext(_connectionString);

            return(ctx.People.FirstOrDefault(p => p.Id == id));
        }
Beispiel #7
0
        public List <Person> GetAll()
        {
            var context = new PeopleCarsDbContext(_connectionString);

            return(context.People.Include(p => p.Cars).ToList());
        }