public void Delete(int friendId) { var context = new Entities(); var friendToDelete = context.Friends.FirstOrDefault(f => f.Id == friendId); context.Friends.Remove(friendToDelete); context.SaveChanges(); }
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(); }
public void Save() { using (var context = new Entities()) { context.Friends.Attach(friendEntity); friendEntity.EmailAddress = this.EmailAddress; context.SaveChanges(); } }
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); } }
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(); } }