Beispiel #1
0
 public Person FindById(int id)
 {
     using (var context = new BirthdayListContext())
     {
         return(context.People.Where(p => p.Id == id).FirstOrDefault());
     }
 }
Beispiel #2
0
 public List <Person> List()
 {
     using (var context = new BirthdayListContext())
     {
         return(context.People.ToList());
     }
 }
Beispiel #3
0
 public void Update(Person person)
 {
     using (var context = new BirthdayListContext())
     {
         context.Entry(person).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Beispiel #4
0
 public void Add(Person person)
 {
     using (var context = new BirthdayListContext())
     {
         context.People.Add(person);
         context.SaveChanges();
     }
 }
Beispiel #5
0
 public List <Person> FindBirthdayToday()
 {
     using (var context = new BirthdayListContext())
     {
         DateTime now = DateTime.Now;
         return(context.People.Where(
                    p => p.Birthdate.Day == now.Day && p.Birthdate.Month == now.Month
                    ).ToList());
     }
 }
Beispiel #6
0
 public void Remove(int id)
 {
     using (var context = new BirthdayListContext())
     {
         var person = new Person {
             Id = id
         };
         context.Entry(person).State = EntityState.Deleted;
         context.SaveChanges();
     }
 }