예제 #1
0
 public static IEnumerable<Person> GetAllPeople()
 {
     using (var db = new CloutContext())
     {
         return (from person in db.Person select person).ToList();
     }
 }
예제 #2
0
 public static Person GetPerson(string name)
 {
     using (var db = new CloutContext())
     {
         return db.Person.SingleOrDefault(p => p.Name == name);
     }
 }
예제 #3
0
 public static void AddOrUpdateLink(Person follower, Person leader)
 {
     using (var db = new CloutContext())
     {
         db.Following.AddOrUpdate(new Following { PersonId = follower.Id, FollowingId = leader.Id });
         db.SaveChanges();
     }
 }
예제 #4
0
 public static IEnumerable<Person> GetFollowers(Person leader)
 {
     using (var db = new CloutContext())
     {
         return (from follower in db.Following
                 join person in db.Person on follower.PersonId equals person.Id
                 where follower.FollowingId == leader.Id
                 select person).ToList();
     }
 }
예제 #5
0
        public static Person GetOrAddPerson(string name)
        {
            using (var db = new CloutContext())
            {
                var person = db.Person.SingleOrDefault(p => p.Name == name);
                if (person == null)
                {
                    db.Person.Add(new Person { Name = name });
                    db.SaveChanges();
                }

                return person ?? db.Person.SingleOrDefault(p => p.Name == name);
            }
        }