Esempio n. 1
0
        public OperationResultVo <int> Count(Guid currentUserId)
        {
            try
            {
                int count = gameDomainService.Count();

                return(new OperationResultVo <int>(count));
            }
            catch (Exception ex)
            {
                return(new OperationResultVo <int>(ex.Message));
            }
        }
Esempio n. 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);
        }