Esempio n. 1
0
        /// <summary>
        /// Update this friend, request the latest data from Steam's servers
        /// </summary>
        public void Refresh()
        {
            Name = Client.native.friends.GetFriendPersonaName(Id);

            relationship = Client.native.friends.GetFriendRelationship(Id);
            personaState = Client.native.friends.GetFriendPersonaState(Id);

            CurrentAppId    = 0;
            ServerIp        = 0;
            ServerGamePort  = 0;
            ServerQueryPort = 0;
            ServerLobbyId   = 0;

            var gameInfo = new SteamNative.FriendGameInfo_t();

            if (Client.native.friends.GetFriendGamePlayed(Id, ref gameInfo) && gameInfo.GameID > 0)
            {
                CurrentAppId    = gameInfo.GameID;
                ServerIp        = gameInfo.GameIP;
                ServerGamePort  = gameInfo.GamePort;
                ServerQueryPort = gameInfo.QueryPort;
                ServerLobbyId   = gameInfo.SteamIDLobby;
            }

            Client.native.friends.RequestFriendRichPresence(Id);
        }
Esempio n. 2
0
        internal User WithRelationship(FriendRelationship relationship)
        {
            var before = (User)MemberwiseClone();

            before._relationship = relationship;
            return(before);
        }
Esempio n. 3
0
        public void AddUserToFriendList_ShouldReturnAFriendUserNoExceptionThrown()
        {
            //Arrange
            FriendRelationship friendUser = null;

            //Act
            MessengerManager messengerManager = new MessengerManager();
            bool             isFriend;

            using (DatabaseContext db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);
                isFriend = msService.IsFriend(testAuthUserId, testContactUserId);
                if (isFriend == true)
                {
                    messengerManager.RemoveUserFromFriendList(testAuthUserId, testContactUserId);
                }
                db.SaveChanges();
            }

            friendUser = messengerManager.AddUserFriendList(testAuthUserId, testContactUsername);

            //Assert
            Assert.NotNull(friendUser);
        }
 public FriendRelationshipViewModel(FriendRelationship ship)
 {
     Id       = ship.Id;
     Owner    = new UserViewModel(ship.Owner);
     User     = new UserViewModel(ship.User);
     Status   = (int)ship.Status;
     CreateAt = ship.CreateAt;
 }
        /// <summary>
        /// Method to add a user to friend list
        /// </summary>
        /// <param name="addingUser"></param>
        /// <param name="addedUser"></param>
        public FriendRelationship AddContactFriendList(int authUserId, int targetUserId)
        {
            var fr = new FriendRelationship
            {
                FriendId = targetUserId,

                UserId = authUserId
            };

            return(_DbContext.FriendRelationships.Add(fr));
        }
Esempio n. 6
0
        public FriendRequestDTO UpdateRequestStatus(FriendToAddDTO friend)
        {
            FriendRelationship friendRelationship = friendRepository.GetFriendRelationshipByUsers(friend.FriendId, friend.UserId);

            friendRelationship.IsAccepted = friend.IsAccepted;

            friendRepository.UpdateStatusRequest(friendRelationship);
            unitOfWork.Commit();

            return(mapper.Map <FriendRequestDTO>(friendRelationship));
        }
Esempio n. 7
0
        private void AddQuizzmateRelationshipToCurrentUser(User child)
        {
            var user = GetCurrentUser();

            var friendRelationship = new FriendRelationship
            {
                User1Id = user.Id,
                User2Id = child.Id
            };

            _uow.FriendRelationships.Add(friendRelationship);
        }
Esempio n. 8
0
        public void DeleteFriend(FriendToAddDTO friend)
        {
            FriendRelationship friendRelationship = friendRepository.GetFriendRelationshipByUsers(friend.FriendId, friend.UserId);

            if (friendRelationship == null)
            {
                friendRelationship = friendRepository.GetFriendRelationshipByUsers(friend.UserId, friend.FriendId);
            }

            friendRepository.Delete(friendRelationship);
            unitOfWork.Commit();
        }
Esempio n. 9
0
        public bool Delete(object id)
        {
            FriendRelationship entity = uow.Set <FriendRelationship>().Find(id);

            if (entity == null)
            {
                return(false);
            }
            uow.Set <FriendRelationship>().Remove(entity);
            uow.Commit();
            return(true);
        }
Esempio n. 10
0
        public bool Add(FriendRelationshipViewModel model)
        {
            model.Id = Guid.NewGuid().ToString();
            FriendRelationship entity = new FriendRelationship();

            uow.Set <FriendRelationship>().Add(entity);
            entity.Id     = model.Id;
            entity.User   = model.User == null ? null : uow.Set <ApplicationUser>().Find(model.User.Id);
            entity.Owner  = model.Owner == null ? null : uow.Set <ApplicationUser>().Find(model.Owner.Id);
            entity.Status = (FriendRelationshipStatusEnum)model.Status;
            uow.Commit();
            return(true);
        }
        /// <summary>
        /// Method to check if an user is a friend
        /// </summary>
        /// <param name="authUserid"></param>
        /// <param name="targetUserId"></param>
        /// <returns></returns>
        public bool IsFriend(int authUserid, int targetUserId)
        {
            FriendRelationship fr = _DbContext.FriendRelationships.FirstOrDefault(f =>
                                                                                  (f.FriendId == targetUserId && f.UserOfRelationship.Id == authUserid) ||
                                                                                  (f.FriendId == authUserid && f.UserOfRelationship.Id == targetUserId)
                                                                                  );

            if (fr == null)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 12
0
        public FriendRequestAddedDTO AddFriend(FriendRelationship friendRelationship)
        {
            if (friendRepository.FriendshipExists(friendRelationship.UserId, friendRelationship.FriendUserId))
            {
                friendRepository.Add(friendRelationship);
                unitOfWork.Commit();

                return(mapper.Map <FriendRequestAddedDTO>(friendRelationship));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 13
0
        public (bool status, string message) Request(Guid userSender, Guid userReciever)
        {
            try
            {
                bool   _status  = true;
                string _message = "Success";

                _friendRequestRepository.BeginTransaction();

                if (_userApiService.UserExist(userSender) == true && _userApiService.UserExist(userReciever) == true)
                {
                    var request = new FriendRequest
                    {
                        Id           = Guid.NewGuid(),
                        UserSender   = userSender,
                        UserReciever = userReciever,
                        Status       = _activityStatusRepository.Get(x => x.Name.Equals(Global.Status.Request)).FirstOrDefault().Id
                    };

                    _friendRequestRepository.Insert(request);

                    var relationship = new FriendRelationship
                    {
                        Id = Guid.NewGuid(),
                        FriendRequestId = request.Id,
                        Status          = _activityStatusRepository.Get(x => x.Name.Equals(Global.Status.Pending)).FirstOrDefault().Id
                    };

                    _friendRelationshipRepository.Insert(relationship);

                    _friendRequestRepository.Save();
                }
                else
                {
                    _status  = false;
                    _message = "User Sender or Reciever not exist";
                }

                _friendRequestRepository.CommitTransaction();

                return(_status, _message);
            }
            catch (Exception ex)
            {
                _friendRequestRepository.RollbackTransaction();
                throw ex;
            }
        }
Esempio n. 14
0
        public IActionResult AddFriend(int id, FriendRelationship friendRelationship)
        {
            try
            {
                friendRelationship.UserId = id;
                FriendRequestAddedDTO friendRequest = friendService.AddFriend(friendRelationship);

                if (friendRequest == null)
                {
                    return(NotFound("La amistad entre los usuarios ya existe."));
                }

                return(Ok(friendRequest));
            }
            catch (DbUpdateException)
            {
                return(NotFound());
            }
        }
        private void ProcesssAccepted(RelationshipNotificationModel model)
        {
            var friendRequest = _uow.FriendRequests.GetById((int)model.FriendRequestId);
            int requestFromId = friendRequest.RequestFromId;
            int requestToId   = friendRequest.RequestToId;

            friendRequest.IsAccepted = true;
            friendRequest.IsDeleted  = true;
            _uow.FriendRequests.Update(friendRequest);

            var friendRelationship = new FriendRelationship
            {
                User1Id = friendRequest.RequestFromId,
                User2Id = friendRequest.RequestToId
            };

            _uow.FriendRelationships.Add(friendRelationship);
            _svcContainer.NotificationSvc.DepQuizzmateNotificationSvc.AddDepQuizzmateRequestAcceptNotification(friendRequest, false);
            _svcContainer.NotificationSvc.DepQuizzmateNotificationSvc.AddDepQuizzmateSendRequestAcceptNotification(friendRequest, false);
            _svcContainer.NotificationSvc.QuizzmateNotificationSvc.AddQuizzmateRequestAcceptNofication(friendRequest, false);
        }
Esempio n. 16
0
        public static void AddFriend(string friend1, string friend2)
        {
            // Check both are users (create if not)
            var u1 = Users().SingleOrDefault(u => u.UserName == friend1);

            if (u1 == null)
            {
                u1 = new User(friend1, friend1, 0, "");
                Users().Add(u1);
            }
            var u2 = Users().SingleOrDefault(u => u.UserName == friend2);

            if (u2 == null)
            {
                u2 = new User(friend2, friend2, 0, "");
                Users().Add(u2);
            }

            var friend = new FriendRelationship(friend1, friend2);

            FriendRelationships().Add(friend);
        }
Esempio n. 17
0
        public void RemoveUserFromFriendList_ShouldReturnFriendRelationship()
        {
            //Arrange
            FriendRelationship fs = null;

            //Act
            MessengerManager messengerManager = new MessengerManager();

            messengerManager.RemoveUserFromFriendList(testAuthUserId, testContactUserId);
            messengerManager.AddUserFriendList(testAuthUserId, testContactUsername);

            using (DatabaseContext db = new DatabaseContext())
            {
                var foundRelationship = db.FriendRelationships.Where(f => f.UserId == testAuthUserId && f.FriendId == testContactUserId).FirstOrDefault();
                fs = messengerManager.RemoveUserFromFriendList(foundRelationship.UserId, foundRelationship.FriendId);
            }



            //Assert
            Assert.NotNull(fs);
        }
        public void AddContactToFriendList_ShouldReturnFriendRelationship()
        {
            //Arrange
            FriendRelationship fr = null;

            //Act
            using (var db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);
                if (msService.IsFriend(testAuthUserId, testContactUserId) == true)
                {
                    msService.RemoveUserFromFriendList(testAuthUserId, testContactUserId);
                    db.SaveChanges();
                }

                fr = msService.AddContactFriendList(testAuthUserId, testContactUserId);

                db.SaveChanges();
            }

            //Assert
            Assert.NotNull(fr);
        }
        public void RemoveContactFromFriendList_FindDeletedFriendShouldReturnNull()
        {
            //Arrange
            FriendRelationship DeletedFriend = null;

            //Act
            using (var db = new DatabaseContext())
            {
                MessengerServices msService = new MessengerServices(db);

                if (msService.IsFriend(testAuthUserId, testContactUserId) == false)
                {
                    msService.AddContactFriendList(testAuthUserId, testContactUserId);
                    db.SaveChanges();
                }


                DeletedFriend = msService.RemoveUserFromFriendList(testAuthUserId, testContactUserId);
                db.SaveChanges();
            }

            //Assert
            Assert.NotNull(DeletedFriend);
        }
        public TransactionObject CreateAccount(CreateAccountFormData newAccountInfo)
        {
            TransactionObject response = new TransactionObject();

            if (userManager.IsUserExists(newAccountInfo.Username))
            {
                try
                {
                    Period period = prdManager.GetPeriod(newAccountInfo.Year, newAccountInfo.Term);

                    User    newUser    = new User();
                    Student newStudent = new Student();

                    newUser.Username     = newAccountInfo.Username;
                    newUser.CreationDate = DateTime.Now;
                    newUser.Password     = SecurityFolder.Security.GetEncryptedPassword(newAccountInfo.Password);//şifre hashlendi
                    newUser.ProfilePhoto = newAccountInfo.ProfilePhoto;
                    newUser.Email        = newAccountInfo.Email;

                    newStudent.Name     = newAccountInfo.Name;
                    newStudent.Surname  = newAccountInfo.Surname;
                    newStudent.Birthday = new DateTime(1996, 1, 1);
                    newStudent.Period   = period;

                    period.Students.Add(newStudent);

                    newUser.Student = newStudent;
                    newStudent.User = newUser;

                    userManager.AddUser(newUser);
                    stdManager.AddStudent(newStudent);


                    FriendRelationship fr = new FriendRelationship();
                    newUser.FriendRelationship = fr;

                    frManager.AddFriendRelationship(fr);


                    var saveResponse = uow.Save();

                    if (saveResponse.IsSuccess)
                    {
                        response.IsSuccess = true;
                    }
                    else
                    {
                        response.IsSuccess   = false;
                        response.Explanation = saveResponse.Explanation;
                    }
                }
                catch (Exception ex)
                {
                    response.IsSuccess   = false;
                    response.Explanation = base.GetExceptionMessage(ex);
                }
            }
            else
            {
                response.IsSuccess   = false;
                response.Explanation = "This username is exists! Please try valid username...";
            }
            return(response);
        }
Esempio n. 21
0
 internal User(SteamNetworkClient client, SteamId id, FriendRelationship relationship) : base(client)
 {
     _steamId      = id;
     _relationship = relationship;
 }
        public IHttpActionResult AddFriendContactList(string addedUsername)
        {
            //The authentication part start from here
            //Create security context from the token
            SecurityContext securityContext = SecurityContextBuilder.CreateSecurityContext(
                Request.Headers
                );

            if (securityContext == null)
            {
                return(Unauthorized());;
            }

            //Validate the token
            SessionManager sm = new SessionManager();

            if (!sm.ValidateSession(securityContext.Token))
            {
                return(Unauthorized());;
            }

            //Create authorization manager from security context to check claims
            AuthorizationManager authorizationManager = new AuthorizationManager(
                securityContext
                );
            // TODO get this from table in database.
            List <string> requiredClaims = new List <string>()
            {
                "CanSendMessage"
            };

            if (!authorizationManager.CheckClaims(requiredClaims))
            {
                return(Unauthorized());;
            }
            else
            {
                UserManager um = new UserManager();

                // Get authUserId from auth username
                _authUserId = um.FindByUserName(securityContext.UserName).Id;
                FriendRelationship friendRelationship = null;
                try
                {
                    // Try to add friend
                    friendRelationship = _messengerManager.AddUserFriendList(_authUserId, addedUsername);
                }

                catch (Exception ex)
                {
                    if (ex is MessageReceiverNotFoundException)
                    {
                        return(Content(HttpStatusCode.NotFound, "User with the username does not exist to be added"));
                    }

                    else if (ex is DuplicatedFriendException)
                    {
                        return(Content(HttpStatusCode.Conflict, "User with the username is already in friend list "));
                    }

                    else if (ex is DbUpdateException)
                    {
                        return(Content(HttpStatusCode.InternalServerError, "There is a error when saving friend relationship to database"));
                    }
                }

                // Create FriendRelationship DTO to return to the front end to render the friendlist
                var friendRelationshipDTO = new FriendRelationshipDTO
                {
                    FriendId       = friendRelationship.FriendId,
                    FriendUsername = um.FindUserById(friendRelationship.FriendId).UserName
                };

                return(Ok(new { friend = friendRelationshipDTO } /*new { SITtoken = updatedToken }*/));
            }

            //string updatedToken = sm.RefreshSession(securityContext.Token);
        }
 public void AddFriendRelationship(FriendRelationship fr)
 {
     friendRequestRepository.Add(fr);
 }
 internal UnknownUser(SteamId id, FriendRelationship relationship)
 {
     Id           = id;
     Relationship = relationship;
 }
Esempio n. 25
0
 internal static User Create(SteamNetworkClient client, FriendRelationship relationship, CMsgClientPersonaState.Friend state, ClientPersonaStateFlag flag)
 {
     return(new User(client, state.friendid, relationship).WithState(state, flag));
 }