Esempio n. 1
0
 /// <summary>
 /// Method to add the currentPerson information to the database.
 /// </summary>
 /// <param name="newPerson"></param>
 /// <returns></returns>
 public void addPerson(Person newPerson)
 {
     //Adding person to DB.
     using (var db = new PersonDBContext())
     {
         db.People.Add(newPerson);
         db.SaveChanges();
     }
 }
Esempio n. 2
0
        /// <summary>
        /// This method returns a list of people in the DB that have a matching first or last name.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public List <Person> personQuery(string name)
        {
            //List of people with the name.
            List <Person> peopleList = new List <Person>();

            //DO QUEREY
            using (var context = new PersonDBContext())
            {
                // Query for all blogs with names starting with B
                var query = from b in context.People
                            where b.FirstName.Trim().ToUpper() == name.Trim().ToUpper() ||
                            b.LastName.Trim().ToUpper() == name.Trim().ToUpper()
                            select b;

                foreach (var item in query)
                {
                    peopleList.Add(item);
                }
            }

            return(peopleList);
        }