public void test_1()
        {
            try
            {
                using (var context = new PeopleDbContext())
                {
                    context.People.RemoveRange(context.People);
                    context.Friendships.RemoveRange(context.Friendships);
                    context.SaveChanges();

                    var person1 = Person.Create(Guid.NewGuid());
                    var person2 = Person.Create(Guid.NewGuid());

                    context.People.Add(person1);
                    context.People.Add(person2);
                    context.Friendships.Add(Friendship.Create(person1.Id, person2.Id));
                    context.SaveChanges();

                    var result = context.Friendships.ToList();
                    var people = context.People.ToList();
                }
            }
            catch (Exception ex)
            {
                var error = ex.InnerException?.Message;
                throw;
            }
        }
Пример #2
0
        private void Save(Dictionary <int, HashSet <int> > parsedData, string dataSetName)
        {
            using (var repository = NewRepositoryFactory())
            {
                var dataSet = DataSet.Create(dataSetName);

                //create all unique friends
                var friends = new List <Friend>();
                foreach (var friend in parsedData)
                {
                    friends.Add(Friend.Create(friend.Key, dataSet.Id));
                }

                //create friendships for each user(friend)
                var friendships = new List <Friendship>();
                foreach (var friend in friends)
                {
                    var mutualFriends = friends.Where(f => parsedData[friend.SocialNetworkId].Contains(f.SocialNetworkId)).ToList();
                    var friendship    = Friendship.Create(friend.Id, dataSet.Id, mutualFriends);

                    friendships.Add(friendship);
                }

                repository.DataSets.Add(dataSet);
                repository.Friendships.Add(friendships);

                repository.Commit();
            }
        }
Пример #3
0
        private Friendship AddFriendship(Guid dataSetId, List <Friend> friends)
        {
            var friendship = Friendship.Create(Guid.NewGuid(), dataSetId, friends);

            FriendshipRepository.Friendships.Add(friendship);

            return(friendship);
        }