Example #1
0
        public static bool AddFriendshipRequest(int fromUserUserId, string toUserUserName)
        {
            using (UowData db = new UowData())
            {
                User fromUser = UsersData.GetUserByUserId(fromUserUserId);
                User toUser = UsersData.GetUserByUserName(toUserUserName);

                if (fromUser == null || toUser == null)
                {
                    return false;
                }

                Friendship friendship = db.Friendships.All().Where(f => f.IsActive &&
                    (f.FromUserUserId == fromUser.UserId && f.ToUserUserId == toUser.UserId) ||
                    (f.FromUserUserId == toUser.UserId && f.ToUserUserId == fromUser.UserId)).FirstOrDefault();

                FriendshipRequest friendshipRequest = db.FriendshipRequests.All().Where(fr => fr.IsActive &&
                    (fr.FromUserUserId == fromUser.UserId && fr.ToUserUserId == toUser.UserId) ||
                    (fr.FromUserUserId == toUser.UserId && fr.ToUserUserId == fromUser.UserId)).FirstOrDefault();

                if (friendship == null && friendshipRequest == null)
                {
                    FriendshipRequest newFriendshipRequest = new FriendshipRequest(fromUser, toUser);

                    db.FriendshipRequests.Add(newFriendshipRequest);
                    db.SaveChanges();

                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
Example #2
0
 public Friendship(FriendshipRequest friendshipRequst)
 {
     this.FromUserUserId = friendshipRequst.FromUserUserId;
     this.FromUserUserName = friendshipRequst.FromUserUserName;
     this.ToUserUserId = friendshipRequst.ToUserUserId;
     this.ToUserUserName = friendshipRequst.ToUserUserName;
     this.Since = DateTime.Now;
     this.Till = null;
     this.BrokenFromUserId = null;
     this.BrokenFromUserUserName = null;
     this.IsActive = true;
 }
Example #3
0
 public FriendshipRequestViewModel(FriendshipRequest friendshipRequest)
 {
     this.FriendshipRequestId = friendshipRequest.FriendshipRequestId;
     this.FromUserUserId = friendshipRequest.FromUserUserId;
     this.FromUserUserName = friendshipRequest.FromUserUserName;
     this.ToUserUserId = friendshipRequest.ToUserUserId;
     this.ToUserUserName = friendshipRequest.ToUserUserName;
     this.IsApproved = friendshipRequest.IsApproved;
     this.Since = friendshipRequest.Since;
     this.Till = friendshipRequest.Till;
     this.CanceledFromUserUserId = friendshipRequest.CanceledFromUserUserId;
     this.CanceledFromUserUserName = friendshipRequest.CanceledFromUserUserName;
     this.IsActive = friendshipRequest.IsActive;
 }
Example #4
0
        public static bool AddFriendship(FriendshipRequest friendshipRequst)
        {
            using (UowData db = new UowData())
            {
                IQueryable<Friendship> friendships =
                    from f in db.Friendships.All()
                    where ((f.FromUserUserId == friendshipRequst.FromUserUserId && f.ToUserUserId == friendshipRequst.ToUserUserId) ||
                        (f.ToUserUserId == friendshipRequst.FromUserUserId && f.FromUserUserId == friendshipRequst.ToUserUserId)) &&
                        f.IsActive
                    select f;

                if (friendships.Count() == 0)
                {
                    Friendship newFriendship = new Friendship(friendshipRequst);

                    db.Friendships.Add(newFriendship);

                    db.SaveChanges();

                    return true;
                }
                else
                {
                    return false;
                }
            }
        }