Exemplo n.º 1
0
        public Hobby AddHobby(Hobby hobby)
        {
            HobbyDBContext dbContext = new HobbyDBContext();

            dbContext.Hobbies.Add(hobby);
            dbContext.SaveChanges();
            return(hobby);
        }
Exemplo n.º 2
0
        public List <Hobby> GetHobbiesForPerson(int personID)
        {
            HobbyDBContext dbContext = new HobbyDBContext();
            var            hobbies   = dbContext.Persons.Include("Hobbies").Where(p => p.PersonID == personID).Select(p => p.Hobbies).FirstOrDefault();

            ;
            return(hobbies.ToList());
        }
Exemplo n.º 3
0
        public Hobby GetHobby(int hobbyID)
        {
            HobbyDBContext dbContext = new HobbyDBContext();

            return(dbContext.Hobbies.Where(x => x.HobbyID == hobbyID).FirstOrDefault());
        }
Exemplo n.º 4
0
        public Person GetPerson(int personID)
        {
            HobbyDBContext dbContext = new HobbyDBContext();

            return(dbContext.Persons.Where(x => x.PersonID == personID).FirstOrDefault());
        }
Exemplo n.º 5
0
        public int GetCountOfPeopleInterestedInHobby(int hobbyID)
        {
            HobbyDBContext dbContext = new HobbyDBContext();

            return(dbContext.Hobbies.Include("Hobbies").Where(h => h.HobbyID == hobbyID).Select(h => h.People).FirstOrDefault().Count());
        }