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 Core.Model.User GetUserByEmail(string email) { var context = new Entities(); return context.Memberships .Where(m => m.Email == email) .Select(m => new Core.Model.User()) .FirstOrDefault(); }
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 IEnumerable<Friend> ListFriendsOfUser(Guid userId) { var context = new Entities(); return context.Friends .Where(f => f.UserId == userId) .Select(f => new Friend() { Id = f.Id, EmailAddress = f.EmailAddress }); }
public void CanCreateNewFriend() { Guid testUserId; using (var context = new Entities()) { testUserId = context.Memberships.FirstOrDefault().UserId; } //var friend = ActiveRecordFriend.CreateNew("*****@*****.**", Guid.Empty); FK violation var friend = ActiveRecordFriend.CreateNew("*****@*****.**", testUserId); Assert.IsNotNull(friend); }
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 EmailDomainReturnedCorrectly() { Guid testUserId; using (var context = new Entities()) { testUserId = context.Memberships.FirstOrDefault().UserId; } var friend = ActiveRecordFriend.CreateNew("*****@*****.**", testUserId); var domain = friend.EmailDomain; Assert.AreEqual("foo.com", domain); }
public void CanCreateExistingFriend() { Guid testUserId; using (var context = new Entities()) { testUserId = context.Memberships.FirstOrDefault().UserId; } var friend = ActiveRecordFriend.CreateNew("*****@*****.**", testUserId); var secondFriend = new ActiveRecordFriend(friend.Id); Assert.IsNotNull(secondFriend); }
public IEnumerable<Core.Model.Friend> ListFriendsOfUser(Guid userId) { var context = new Entities(); return context.Friends .Where(f => f.UserId == userId) .ToList() .Select(f => Mapper.Map<Friends, PluralSightBook.Core.Model.Friend>(f)); //.Select(f => new PluralSightBook.Core.Model.Friend() //{ // Id = f.Id, // EmailAddress = f.EmailAddress //}); }
public ActiveRecordFriend(int id) { using (var context = new Entities()) { friendEntity = context.Friends.FirstOrDefault(f => f.Id == id); } if (friendEntity == null) { throw new ApplicationException("Specified friend does not exist: " + id); } this.Id = friendEntity.Id; this.EmailAddress = friendEntity.EmailAddress; }
public void CanSaveChangesToFriend() { Guid testUserId; using (var context = new Entities()) { testUserId = context.Memberships.FirstOrDefault().UserId; } var friend = ActiveRecordFriend.CreateNew("*****@*****.**", testUserId); var secondFriend = new ActiveRecordFriend(friend.Id); secondFriend.EmailAddress = "updated"; secondFriend.Save(); var thirdFriend = new ActiveRecordFriend(friend.Id); Assert.AreEqual(secondFriend.EmailAddress, thirdFriend.EmailAddress); }
public void AddRecordTx() { 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); } }
public bool IsUserWithEmailFriendOfUser(Guid userId, string emailAddressOfPotentialFriend) { var context = new Entities(); return context.Friends.Any(f => f.UserId == userId && f.EmailAddress == emailAddressOfPotentialFriend); }
public bool UserWithEmailExists(string email) { var context = new Entities(); return context.Memberships.Any(m => m.Email == email); }