public void DeleteFriend(int friendId) { var context = new Entities(); var friendToDelete = context.Friends.FirstOrDefault(f => f.Id == friendId); context.Friends.Remove(friendToDelete); context.SaveChanges(); }
public void SendNotification(string currentUserEmail, string currentUserName, string friendEmail, Entities context) { string emailBody = ""; var userService = new UserService(); bool isFriendMember = userService.IsEmailRegistered(friendEmail); if (isFriendMember) { // do they already list the current user as one of their friends? var friendUserId = userService.GetUsersByEmail(friendEmail).UserId; bool currentUserAlreadyFriend = context.Friends.Any(f => f.UserId == friendUserId && f.EmailAddress == currentUserEmail); if (currentUserAlreadyFriend) { emailBody = String.Format(@"Good News! Your friend {0} just added you as a friend!", currentUserEmail); } else { emailBody = String.Format(@"{0} added you as a friend on PluralSightBook! Click here to add them as your friend: http://localhost:56693/AddFriend2?email={1}", currentUserName, currentUserEmail); } } else { emailBody = String.Format(@"{0} added you as a friend on PluralSightBook! Click here to register your own account and then add them as your friend: http://localhost:56693/QuickAddFriend.aspx?email={1}", currentUserName, currentUserEmail); } // send email Debug.Print("Sending Email: " + emailBody); }
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 AddFriend(Guid currentUserId, string currentUserEmail, string currentUserName, string friendEmail) { // TODO: Move this code to DAL var context = new Entities(); var newFriend = context.Friends.Create(); newFriend.UserId = currentUserId; newFriend.EmailAddress = friendEmail; context.Friends.Add(newFriend); context.SaveChanges(); var notificationService = new NotificationService(); notificationService.SendNotification(currentUserEmail, currentUserName, friendEmail, context); }
public Membership GetUsersByEmail(string email) { var context = new Entities(); return context.Memberships.FirstOrDefault(m => m.Email == email); }
public bool IsEmailRegistered(string email) { var context = new Entities(); return context.Memberships.Any(m => m.Email == email); }