예제 #1
0
 public Person Add(Person p)
 {
     using (var context = new PersonDbContext())
     {
         context.Persons.Add(p);
         context.SaveChanges();
         return(p);
     }
 }
예제 #2
0
 public bool Delete(int id)
 {
     using (var context = new PersonDbContext())
     {
         var person = context.Persons.Where(p => p.Id == id).FirstOrDefault();
         if (person == null)
         {
             return(false);
         }
         context.Persons.Remove(person);
         context.SaveChanges();
         return(true);
     }
 }
예제 #3
0
        public Person Update(int id, Person update)
        {
            using (var context = new PersonDbContext())
            {
                var person = context.Persons.Where(p => p.Id == id).FirstOrDefault();
                if (person == null)
                {
                    return(null);
                }
                person.Age  = update.Age;
                person.Name = update.Name;

                context.SaveChanges();
                return(person);
            }
        }