コード例 #1
0
 public void Delete(int friendId)
 {
     var context = new Entities();
     var friendToDelete = context.Friends.FirstOrDefault(f => f.Id == friendId);
     context.Friends.Remove(friendToDelete);
     context.SaveChanges();
 }
コード例 #2
0
 public void Create(Guid userId, string emailAddress)
 {
     var context = new Entities();
     var newFriend = context.Friends.Create();
     newFriend.UserId = userId;
     newFriend.EmailAddress = emailAddress;
     context.Friends.Add(newFriend);
     context.SaveChanges();
 }
コード例 #3
0
 public void Save()
 {
     using (var context = new Entities())
     {
         context.Friends.Attach(friendEntity);
         friendEntity.EmailAddress = this.EmailAddress;
         context.SaveChanges();
     }
 }
コード例 #4
0
 public static ActiveRecordFriend CreateNew(string emailAddress, Guid userId)
 {
     using (var context = new Entities())
     {
         var friend = context.Friends.Create();
         friend.EmailAddress = emailAddress;
         friend.UserId = userId;
         context.Friends.Add(friend);
         context.SaveChanges();
         return new ActiveRecordFriend(friend.Id);
     }
 }
コード例 #5
0
        public void AddRecord()
        {
            Guid testUserId;
            using (var context = new Entities())
            {
                testUserId = context.Memberships.First().UserId;
            }

            var friendRepository = new EfFriendRepository();
            var testEmail = Guid.NewGuid().ToString();

            friendRepository.Create(testUserId, testEmail);

            using (var context = new Entities())
            {
                bool friendExists = context.Friends.Any(f => f.UserId == testUserId && f.EmailAddress == testEmail);
                Assert.IsTrue(friendExists);

                context.Friends.Remove(context.Friends.FirstOrDefault(f => f.UserId == testUserId && f.EmailAddress == testEmail));
                context.SaveChanges();
            }
        }