Exemple #1
0
        public async Task <ActionResult <StringResult> > Submit([FromBody] SubmitRequest request)
        {
            var site = await _siteRepository.GetAsync(request.SiteId);

            var url = string.Empty;

            if (request.SiteId > 0 && request.ChannelId > 0 && request.ContentId > 0)
            {
                var channelInfo = await _channelRepository.GetAsync(request.ChannelId);

                url = await _pathManager.GetContentUrlAsync(site, channelInfo, request.ContentId, request.IsLocal);
            }
            else if (request.SiteId > 0 && request.ChannelId > 0)
            {
                var channelInfo = await _channelRepository.GetAsync(request.ChannelId);

                url = await _pathManager.GetChannelUrlAsync(site, channelInfo, request.IsLocal);
            }
            else if (request.SiteId > 0 && request.FileTemplateId > 0)
            {
                url = await _pathManager.GetFileUrlAsync(site, request.FileTemplateId, request.IsLocal);
            }
            else if (request.SiteId > 0 && request.SpecialId > 0)
            {
                url = await _pathManager.GetSpecialUrlAsync(site, request.SpecialId, request.IsLocal);
            }
            else if (request.SiteId > 0)
            {
                var channelInfo = await _channelRepository.GetAsync(request.SiteId);

                url = await _pathManager.GetChannelUrlAsync(site, channelInfo, request.IsLocal);
            }

            //if (site.IsSeparatedWeb)
            //{
            //    if (siteId > 0 && channelId > 0 && contentId > 0)
            //    {
            //        url = PreviewApi.GetContentUrl(siteId, channelId, contentId);
            //    }
            //    else if (siteId > 0 && channelId > 0)
            //    {
            //        url = PreviewApi.GetChannelUrl(siteId, channelId);
            //    }
            //    else if (siteId > 0 && templateId > 0)
            //    {
            //        url = PreviewApi.GetFileUrl(siteId, templateId);
            //    }
            //    else if (siteId > 0)
            //    {
            //        url = PreviewApi.GetSiteUrl(siteId);
            //    }
            //}
            //else
            //{

            //}

            if (string.IsNullOrEmpty(url) || StringUtils.EqualsIgnoreCase(url, PageUtils.UnClickableUrl))
            {
                if (request.SiteId == 0)
                {
                    request.SiteId = await _siteRepository.GetIdByIsRootAsync();
                }
                if (request.SiteId != 0)
                {
                    site = await _siteRepository.GetAsync(request.SiteId);

                    url = site.IsSeparatedWeb
                        ? _pathManager.GetPreviewSiteUrl(request.SiteId)
                        : await _pathManager.GetWebUrlAsync(site);
                }
                else
                {
                    url = "/";
                }
            }

            return(new StringResult
            {
                Value = url
            });
        }
        public async Task <RedirectResult> Get([FromQuery] GetRequest request)
        {
            var site = await _siteRepository.GetAsync(request.SiteId);

            var redirectUrl = await _pathManager.GetIndexPageUrlAsync(site, false);

            var channelId = request.ChannelId;

            if (channelId == 0)
            {
                channelId = request.SiteId;
            }

            if (request.SpecialId != 0)
            {
                await _createManager.ExecuteAsync(request.SiteId, CreateType.Special, 0, 0, 0, request.SpecialId);
            }
            else if (request.FileTemplateId != 0)
            {
                await _createManager.ExecuteAsync(request.SiteId, CreateType.File, 0, 0, request.FileTemplateId, 0);
            }
            else if (request.ContentId != 0)
            {
                await _createManager.ExecuteAsync(request.SiteId, CreateType.Content, channelId, request.ContentId, 0, 0);
            }
            else if (channelId != 0)
            {
                await _createManager.ExecuteAsync(request.SiteId, CreateType.Channel, channelId, 0, 0, 0);
            }
            else if (request.SiteId != 0)
            {
                await _createManager.ExecuteAsync(request.SiteId, CreateType.Channel, request.SiteId, 0, 0, 0);
            }

            if (request.IsRedirect)
            {
                var channelInfo = await _channelRepository.GetAsync(channelId);

                if (request.SpecialId != 0)
                {
                    redirectUrl = await _pathManager.GetFileUrlAsync(site, request.SpecialId, false);
                }
                else if (request.FileTemplateId != 0)
                {
                    redirectUrl = await _pathManager.GetFileUrlAsync(site, request.FileTemplateId, false);
                }
                else if (request.ContentId != 0)
                {
                    var contentInfo = await _contentRepository.GetAsync(site, channelInfo, request.ContentId);

                    redirectUrl = await _pathManager.GetContentUrlAsync(site, contentInfo, false);
                }
                else if (channelId != 0)
                {
                    redirectUrl = await _pathManager.GetChannelUrlAsync(site, channelInfo, false);
                }
                else if (request.SiteId != 0)
                {
                    redirectUrl = await _pathManager.GetIndexPageUrlAsync(site, false);
                }

                if (!string.IsNullOrEmpty(redirectUrl))
                {
                    var parameters = new NameValueCollection();
                    if (!string.IsNullOrEmpty(request.ReturnUrl) && request.ReturnUrl.StartsWith("?"))
                    {
                        parameters = TranslateUtils.ToNameValueCollection(request.ReturnUrl.Substring(1));
                    }

                    parameters["__r"] = StringUtils.GetRandomInt(1, 10000).ToString();

                    redirectUrl = PageUtils.AddQueryString(redirectUrl, parameters);
                }
            }

            return(Redirect(redirectUrl));
        }