Exemple #1
0
        public virtual SendFriendshipRequestOutput SendFriendshipRequest(SendFriendshipRequestInput input)
        {
            var friendUser = _taskeverUserRepository.FirstOrDefault(user => user.EmailAddress == input.EmailAddress);

            if (friendUser == null)
            {
                throw new UserFriendlyException("Can not find a user with email address: " + input.EmailAddress);
            }

            var currentUser = _taskeverUserRepository.Load(AbpUser.CurrentUserId.Value);

            //Check if they are already friends
            var friendship = _friendshipRepository.GetOrNull(currentUser.Id, friendUser.Id);

            if (friendship != null)
            {
                if (friendship.CanBeAcceptedBy(currentUser))
                {
                    friendship.AcceptBy(currentUser);
                }

                return(new SendFriendshipRequestOutput {
                    Status = friendship.Status
                });
            }

            //Add new friendship request
            friendship = Friendship.CreateAsRequest(currentUser, friendUser);
            _friendshipRepository.Insert(friendship);

            SendRequestEmail(friendship);

            return(new SendFriendshipRequestOutput {
                Status = friendship.Status
            });
        }
        public UserDto GetActiveUserOrNull(string emailAddress, string password) //TODO: Make this GetUserOrNullInput and GetUserOrNullOutput
        {
            var userEntity = _userRepository.FirstOrDefault(user => user.EmailAddress == emailAddress && user.Password == password && user.IsEmailConfirmed);

            return(userEntity.MapTo <UserDto>());
        }