Example #1
0
        public ActionResult Add(string userId = "")
        {
            try
            {
                Guid friendId;
                if (!Guid.TryParse(userId, out friendId))
                {
                    throw new Exception("The specified user id is not valid.");
                }

                var user = UserHelper.getUserById(friendId.ToString());

                if (user == null)
                {
                    throw new Exception("The user you are trying to add as friend is not available.");
                }

                Guid userGuid = new Guid(UserHelper.getLoggedInUserId());
                if (!FriendshipHelper.ShowAddFriendLink(userGuid, friendId))
                {
                    throw new Exception("A friendship or friendship request already exists between you and " + UserHelper.GetDisplayName(friendId.ToString()));
                }
                Entities dbContext = new Entities();

                Friendship friendship = new Friendship();
                friendship.UserId = userGuid;
                friendship.FriendId = friendId;
                friendship.Status = 0;
                friendship.CreatedAt = DateTime.Now;
                dbContext.Friendships.AddObject(friendship);
                dbContext.SaveChanges();
                EmailHelper.SendEmail(friendship.Friend.Membership.Email, "Nuevo Friend Request from "+UserHelper.GetDisplayName(friendship.UserId.ToString()), UserHelper.GetDisplayName(friendship.UserId.ToString()) + "Has sent you a friend request on Nuevo. You may login and curate your friend requests.");
                return RedirectToAction("Index", "Profile", new { userId = friendId.ToString() });
            }catch(Exception ex)
            {
                return Content(ex.Message);
            }
        }
Example #2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Friendships EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToFriendships(Friendship friendship)
 {
     base.AddObject("Friendships", friendship);
 }
Example #3
0
 /// <summary>
 /// Create a new Friendship object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="friendId">Initial value of the FriendId property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 /// <param name="createdAt">Initial value of the CreatedAt property.</param>
 public static Friendship CreateFriendship(global::System.Int32 id, global::System.Guid userId, global::System.Guid friendId, global::System.Int32 status, global::System.DateTime createdAt)
 {
     Friendship friendship = new Friendship();
     friendship.Id = id;
     friendship.UserId = userId;
     friendship.FriendId = friendId;
     friendship.Status = status;
     friendship.CreatedAt = createdAt;
     return friendship;
 }