Пример #1
0
        public UserConnectionVo GetConnectionDetails(Guid originalUserId, Guid connectedUserId)
        {
            List <UserConnection> connections = userConnectionRepository.Get(x => x.UserId == originalUserId && x.TargetUserId == connectedUserId || x.UserId == connectedUserId && x.TargetUserId == originalUserId).ToList();


            bool fromUser = connections.Any(x => x.UserId == originalUserId);
            bool toUser   = connections.Any(x => x.TargetUserId == originalUserId);

            bool typeMentor = connections.Any(x => x.ConnectionType == UserConnectionType.Mentor);
            bool typePupil  = connections.Any(x => x.ConnectionType == UserConnectionType.Pupil);

            if (!connections.Any())
            {
                return(null);
            }

            UserConnectionVo model = new UserConnectionVo
            {
                Accepted       = connections.Any(x => x.ApprovalDate.HasValue),
                Direction      = fromUser && toUser ? UserConnectionDirection.BothWays : (fromUser ? UserConnectionDirection.FromUser : UserConnectionDirection.ToUser),
                ConnectionType = typeMentor ? UserConnectionType.Mentor : (typePupil ? UserConnectionType.Pupil : UserConnectionType.WorkedTogether)
            };

            return(model);
        }
Пример #2
0
        public ProfileViewModel GetByUserId(Guid currentUserId, Guid userId, ProfileType type, bool forEdit)
        {
            ProfileViewModel vm = new ProfileViewModel();

            IEnumerable <UserProfile> profiles = profileDomainService.GetByUserId(userId);

            UserProfile model = profiles.FirstOrDefault(x => x.Type == type);

            if (profiles.Any() && model != null)
            {
                vm = mapper.Map(model, vm);
            }
            else
            {
                return(null);
            }

            SetImages(vm, model.HasCoverImage);

            vm.Counters.Games    = gameDomainService.Count(x => x.UserId == vm.UserId);
            vm.Counters.Posts    = userContentDomainService.Count(x => x.UserId == vm.UserId);
            vm.Counters.Comments = userContentDomainService.CountComments(x => x.UserId == vm.UserId);

            vm.Counters.Followers = model.Followers.SafeCount();
            vm.Counters.Following = profileDomainService.CountFollows(userId);
            int connectionsToUser   = profileDomainService.CountConnections(x => x.TargetUserId == vm.UserId && x.ApprovalDate.HasValue);
            int connectionsFromUser = profileDomainService.CountConnections(x => x.UserId == vm.UserId && x.ApprovalDate.HasValue);

            vm.Counters.Connections = connectionsToUser + connectionsFromUser;

            if (vm.UserId != currentUserId)
            {
                vm.CurrentUserFollowing = model.Followers.SafeAny(x => x.UserId == currentUserId);

                UserConnectionVo connectionDetails = profileDomainService.GetConnectionDetails(currentUserId, vm.UserId);

                vm.ConnectionControl.CurrentUserConnected      = connectionDetails != null && connectionDetails.Accepted;
                vm.ConnectionControl.CurrentUserWantsToConnect = connectionDetails != null && connectionDetails.Direction == UserConnectionDirection.ToUser && !connectionDetails.Accepted;
                vm.ConnectionControl.ConnectionIsPending       = connectionDetails != null && !connectionDetails.Accepted;
                vm.ConnectionControl.ConnectionType            = connectionDetails != null ? connectionDetails.ConnectionType : new UserConnectionType?();
            }

            if (forEdit)
            {
                FormatExternalLinksForEdit(ref vm);
            }

            FormatExternalLinks(vm);

            return(vm);
        }