コード例 #1
0
 public void AddPerson(Person person)
 {
     using (var context = new InternshipDbEntities())
     {
         context.People.Add(person);
         context.SaveChanges();
     }
 }
コード例 #2
0
        public Person GetPersonById(int personId)
        {
            Person person;

            using (var context = new InternshipDbEntities())
            {
                person = context.People.Where(x => x.Id == personId).SingleOrDefault();
            }

            return(person);
        }
コード例 #3
0
        public List <Person> GetPeople()
        {
            List <Person> people = new List <Person>();

            using (var context = new InternshipDbEntities())
            {
                people = context.People.ToList();
            }

            return(people);
        }
コード例 #4
0
 public void DeletePerson(int personId)
 {
     using (var context = new InternshipDbEntities())
     {
         var person = context.People.Where(x => x.Id == personId).SingleOrDefault();
         if (person != null)
         {
             context.People.Remove(person);
             context.SaveChanges();
         }
     }
 }
コード例 #5
0
        public void UpdatePerson(Person person)
        {
            using (var context = new InternshipDbEntities())
            {
                var personObj = context.People.Where(x => x.Id == person.Id).SingleOrDefault();

                if (personObj != null)
                {
                    personObj.Name = person.Name;
                    context.SaveChanges();
                }
            }
        }