Example #1
0
 public FriendshipViewModel(Friendship friendship)
 {
     this.FriendshipId = friendship.FriendshipId;
     this.FromUserUserId = friendship.FromUserUserId;
     this.FromUserUserName = friendship.FromUserUserName;
     this.ToUserUserId = friendship.ToUserUserId;
     this.ToUserUserName = friendship.ToUserUserName;
     this.Since = friendship.Since;
     this.Till = friendship.Till;
     this.BrokenFromUserId = friendship.BrokenFromUserId;
     this.BrokenFromUserUserName = friendship.BrokenFromUserUserName;
     this.IsActive = friendship.IsActive;
 }
Example #2
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;
                }
            }
        }