/// <summary>
        /// This function retrieves the contents uploaded by the user.
        /// </summary>
        /// <param name="userId">User identity.</param>
        /// <returns>Payload details.</returns>
        public async Task <PayloadDetails> GetUserContents(long userId)
        {
            PayloadDetails payloadDetails = null;

            Expression <Func <Content, bool> > condition = c => c.CreatedByID == userId &&
                                                           c.IsDeleted == false &&
                                                           Enumerable.FirstOrDefault(c.CommunityContents) != null &&
                                                           !(bool)Enumerable.FirstOrDefault(c.CommunityContents).Community.IsDeleted;

            Func <Content, object> orderBy = c => c.ModifiedDatetime;

            var contents = _contentRepository.GetItems(condition, orderBy, true);

            // Get Content Details object from Contents so that it has permission details
            var contentDetailsList = new List <ContentDetails>();

            foreach (Content content in contents)
            {
                var userRole = GetContentUserRole(content, userId);

                // For private contents, user's who have not assigned explicit permission will not have access.
                if (userRole != UserRole.None)
                {
                    var contentDetails = new ContentDetails(userRole.GetPermission());
                    contentDetails.SetValuesFrom(content);
                    contentDetailsList.Add(contentDetails);
                }
            }

            payloadDetails      = PayloadDetailsExtensions.InitializePayload();
            payloadDetails.Name = "My Contents";

            payloadDetails.SetValuesFrom(contentDetailsList);
            return(payloadDetails);
        }
        private async Task <Stream> GetTopCommunity(EntityHighlightFilter entityHighlightFilter)
        {
            var entityService = DependencyResolver.Current.GetService(typeof(IEntityService)) as IEntityService;
            var pageDetails   = new PageDetails(1);

            pageDetails.ItemsPerPage = 20;
            var communities = await entityService.GetCommunities(entityHighlightFilter, pageDetails);

            var payloadDetails = PayloadDetailsExtensions.InitializePayload();

            payloadDetails.SetValuesFrom(communities);

            RewritePayloadUrls(payloadDetails, false);
            return(GetOutputStream(payloadDetails));
        }
        /// <summary>
        /// Adds all tours and latest tours to the Payload for the community.
        /// </summary>
        /// <param name="payloadDetails">PayloadDetails object</param>
        private void AddTourFolders(PayloadDetails payloadDetails)
        {
            var baseUri  = ServiceBaseUri();
            var allTours = PayloadDetailsExtensions.InitializePayload();

            allTours.Name = "All Tours";
            allTours.Url  = string.Format(CultureInfo.InvariantCulture, "{0}/Community/{1}/Tours", baseUri, payloadDetails.Id);

            var latestTours = PayloadDetailsExtensions.InitializePayload();

            latestTours.Name = "Latest";
            latestTours.Url  = string.Format(CultureInfo.InvariantCulture, "{0}/Community/{1}/Latest", baseUri, payloadDetails.Id);

            // Insert tour folders at the start
            payloadDetails.Children.Insert(0, latestTours);
            payloadDetails.Children.Insert(0, allTours);
        }
        public FileStreamResult GetCategories()
        {
            var categories     = CategoryType.All.ToSelectList(CategoryType.All);
            var payloadDetails = PayloadDetailsExtensions.InitializePayload();

            payloadDetails.Name       = "Categories";
            payloadDetails.Permission = Permission.Reader;
            payloadDetails.SetValuesFrom(categories);

            var baseUri = BaseUri();

            foreach (var childCategory in payloadDetails.Children)
            {
                childCategory.Thumbnail = RewriteThumbnailUrl(childCategory.Thumbnail, childCategory.Id.ToEnum <string, CategoryType>(CategoryType.GeneralInterest).ToString().ToLowerInvariant() + "wwtthumbnail");
                childCategory.Url       = string.Format(CultureInfo.InvariantCulture, "{0}/Resource/Service/Browse/Category/{1}", baseUri, childCategory.Id);
            }
            var resultStream = GetOutputStream(payloadDetails);

            return(new FileStreamResult(resultStream, Response.ContentType));
        }
        public FileStreamResult GetBrowsePayload()
        {
            var baseUri        = BaseUri();
            var serviceUri     = ServiceBaseUri();
            var payloadDetails = PayloadDetailsExtensions.InitializePayload();

            payloadDetails.Name      = "Browse";
            payloadDetails.Thumbnail = RewriteThumbnailUrl(payloadDetails.Thumbnail, "defaultfolderwwtthumbnail");

            // Get Latest Content.
            var latestContent = PayloadDetailsExtensions.InitializePayload();

            latestContent.Name      = "Latest Content";
            latestContent.Url       = string.Format(CultureInfo.InvariantCulture, "{0}/Browse/LatestContent", serviceUri);
            latestContent.Thumbnail = RewriteThumbnailUrl(latestContent.Thumbnail, "defaultfolderwwtthumbnail");
            payloadDetails.Children.Add(latestContent);

            // Get Top Rated Content.
            var topRatedContent = PayloadDetailsExtensions.InitializePayload();

            topRatedContent.Name      = "Top Rated Content";
            topRatedContent.Url       = string.Format(CultureInfo.InvariantCulture, "{0}/Browse/TopRatedContent", serviceUri);
            topRatedContent.Thumbnail = RewriteThumbnailUrl(topRatedContent.Thumbnail, "defaultfolderwwtthumbnail");
            payloadDetails.Children.Add(topRatedContent);

            // Get Top Downloaded Content
            var topDownloadedContent = PayloadDetailsExtensions.InitializePayload();

            topDownloadedContent.Name      = "Most Downloaded Content";
            topDownloadedContent.Url       = string.Format(CultureInfo.InvariantCulture, "{0}/Browse/MostDownloadedContent", serviceUri);
            topDownloadedContent.Thumbnail = RewriteThumbnailUrl(topDownloadedContent.Thumbnail, "defaultfolderwwtthumbnail");
            payloadDetails.Children.Add(topDownloadedContent);

            // Get Latest Community.
            var latestCommunity = PayloadDetailsExtensions.InitializePayload();

            latestCommunity.Name      = "Latest Communities";
            latestCommunity.Url       = string.Format(CultureInfo.InvariantCulture, "{0}/Browse/LatestCommunity", serviceUri);
            latestCommunity.Thumbnail = RewriteThumbnailUrl(latestCommunity.Thumbnail, "defaultfolderwwtthumbnail");
            payloadDetails.Children.Add(latestCommunity);

            // Get Top Rated Community.
            var topRatedCommunity = PayloadDetailsExtensions.InitializePayload();

            topRatedCommunity.Name      = "Top Rated Communities";
            topRatedCommunity.Url       = string.Format(CultureInfo.InvariantCulture, "{0}/Browse/TopRatedCommunity", serviceUri);
            topRatedCommunity.Thumbnail = RewriteThumbnailUrl(topRatedCommunity.Thumbnail, "defaultfolderwwtthumbnail");
            payloadDetails.Children.Add(topRatedCommunity);

            // Get Categories.
            var categories = PayloadDetailsExtensions.InitializePayload();

            categories.Name      = "Categories";
            categories.Url       = string.Format(CultureInfo.InvariantCulture, "{0}/Browse/Categories", serviceUri);
            categories.Thumbnail = RewriteThumbnailUrl(categories.Thumbnail, "defaultfolderwwtthumbnail");
            payloadDetails.Children.Add(categories);

            var resultStream = GetOutputStream(payloadDetails);

            return(new FileStreamResult(resultStream, Response.ContentType));
        }
        public FileStreamResult GetProfilePayload()
        {
            var serviceBaseUri = ServiceBaseUri();
            // If we are not doing Re-writes of Url, we need to set the thumbnails explicitly at all places
            var payloadDetails = PayloadDetailsExtensions.InitializePayload();

            payloadDetails.Thumbnail = RewriteThumbnailUrl(payloadDetails.Thumbnail, "defaultfolderwwtthumbnail");
            payloadDetails.Name      = Resources.MyFolderLabel;

            //upgrade notice
            //var upgradeLink = new Place();
            //upgradeLink.Name = "Upgrade Notice";
            //upgradeLink.Url = "/upgrade/index?wwtfull=true";
            //upgradeLink.Permission = Permission.Reader;
            //upgradeLink.Thumbnail = RewriteThumbnailUrl(upgradeLink.Thumbnail, "upgradenotice");
            //payloadDetails.Links.Add(upgradeLink);

            // Get My communities node.
            var myCommunities = PayloadDetailsExtensions.InitializePayload();

            myCommunities.Name      = Resources.MyCommunitiesWWTLabel;
            myCommunities.Url       = string.Format(CultureInfo.InvariantCulture, "{0}/Communities", serviceBaseUri);
            myCommunities.Thumbnail = RewriteThumbnailUrl(myCommunities.Thumbnail, "defaultfolderwwtthumbnail");
            payloadDetails.Children.Add(myCommunities);

            // Get My contents node.
            var myContents = PayloadDetailsExtensions.InitializePayload();

            myContents.Name      = Resources.MyContentsWWTLabel;
            myContents.Url       = string.Format(CultureInfo.InvariantCulture, "{0}/Contents", serviceBaseUri);
            myContents.Thumbnail = RewriteThumbnailUrl(myContents.Thumbnail, "defaultfolderwwtthumbnail");
            payloadDetails.Children.Add(myContents);

            // Get Browse EO node.
            var browseDetails = PayloadDetailsExtensions.InitializePayload();

            browseDetails.Name      = Resources.BrowseWWTLabel;
            browseDetails.Url       = string.Format(CultureInfo.InvariantCulture, "{0}/Browse", serviceBaseUri);
            browseDetails.Thumbnail = RewriteThumbnailUrl(browseDetails.Thumbnail, "defaultfolderwwtthumbnail");
            payloadDetails.Children.Add(browseDetails);

            // TODO: Get Search EO node.
            var searchEoLink = new Place();

            searchEoLink.Name       = Resources.SearchWWTLabel;
            searchEoLink.Url        = string.Format(CultureInfo.InvariantCulture, "{0}/Community/index{1}", BaseUri(), "?wwtfull=true");
            searchEoLink.Permission = Permission.Reader;
            searchEoLink.Thumbnail  = RewriteThumbnailUrl(searchEoLink.Thumbnail, "searchwwtthumbnail");

            // This will make sure that the additional context menu options specific to folders are not shown in WWT.
            searchEoLink.MSRComponentId = -1;

            payloadDetails.Links.Add(searchEoLink);

            // TODO: Get Help node.
            var helpLink = new Place();

            helpLink.Name       = Resources.HelpWWTLabel;
            helpLink.Url        = string.Format(CultureInfo.InvariantCulture, "{0}/Support/index{1}", BaseUri(), "?wwtfull=true");
            helpLink.Permission = Permission.Reader;
            helpLink.Thumbnail  = RewriteThumbnailUrl(helpLink.Thumbnail, "helpwwtthumbnail");

            // This will make sure that the additional context menu options specific to folders are not shown in WWT.
            helpLink.MSRComponentId = -1;

            payloadDetails.Links.Add(helpLink);

            var payload = new FileStreamResult(GetOutputStream(payloadDetails), Response.ContentType);

            return(payload);
        }