public HttpResponseMessage UpdateCustomUrl(SaveUrlDto dto)
        {
            var  urlPath = dto.Path.ValueOrEmpty().TrimStart('/');
            bool modified;
            //Clean Url
            var options = UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(PortalSettings.PortalId)));

            //now clean the path
            urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified);
            if (modified)
            {
                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new
                {
                    Success = false,
                    ErrorMessage = Localization.GetString("CustomUrlPathCleaned.Error", Localization.GlobalResourceFile),
                    SuggestedUrlPath = "/" + urlPath
                }));
            }

            //Validate for uniqueness
            urlPath = FriendlyUrlController.ValidateUrl(urlPath, -1, PortalSettings, out modified);
            if (modified)
            {
                return(Request.CreateResponse(HttpStatusCode.OK,
                                              new
                {
                    Success = false,
                    ErrorMessage = Localization.GetString("UrlPathNotUnique.Error", Localization.GlobalResourceFile),
                    SuggestedUrlPath = "/" + urlPath
                }));
            }

            var tab         = PortalSettings.ActiveTab;
            var cultureCode = LocaleController.Instance.GetLocales(PortalId)
                              .Where(l => l.Value.KeyID == dto.LocaleKey)
                              .Select(l => l.Value.Code)
                              .SingleOrDefault();

            if (dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture) == "200")
            {
                //We need to check if we are updating a current url or creating a new 200
                var tabUrl = tab.TabUrls.SingleOrDefault(t => t.SeqNum == dto.Id &&
                                                         t.HttpStatus == "200");
                if (tabUrl == null)
                {
                    //Just create Url
                    tabUrl = new TabUrlInfo
                    {
                        TabId            = tab.TabID,
                        SeqNum           = dto.Id,
                        PortalAliasId    = dto.SiteAliasKey,
                        PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage,
                        QueryString      = dto.QueryString.ValueOrEmpty(),
                        Url         = dto.Path.ValueOrEmpty(),
                        CultureCode = cultureCode,
                        HttpStatus  = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture),
                        IsSystem    = dto.IsSystem              // false
                    };
                    TabController.Instance.SaveTabUrl(tabUrl, PortalId, true);
                }
                else
                {
                    //Change the original 200 url to a redirect
                    tabUrl.HttpStatus = "301";
                    tabUrl.SeqNum     = dto.Id;
                    TabController.Instance.SaveTabUrl(tabUrl, PortalId, true);

                    //Add new custom url
                    tabUrl.Url        = dto.Path.ValueOrEmpty();
                    tabUrl.HttpStatus = "200";
                    tabUrl.SeqNum     = tab.TabUrls.Max(t => t.SeqNum) + 1;
                    TabController.Instance.SaveTabUrl(tabUrl, PortalId, true);
                }
            }
            else
            {
                //Just update the url
                var tabUrl = new TabUrlInfo
                {
                    TabId            = tab.TabID,
                    SeqNum           = dto.Id,
                    PortalAliasId    = dto.SiteAliasKey,
                    PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage,
                    QueryString      = dto.QueryString.ValueOrEmpty(),
                    Url         = dto.Path.ValueOrEmpty(),
                    CultureCode = cultureCode,
                    HttpStatus  = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture),
                    IsSystem    = dto.IsSystem                  // false
                };
                TabController.Instance.SaveTabUrl(tabUrl, PortalId, true);
            }


            var response = new
            {
                Success = true,
            };

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Ejemplo n.º 2
0
        public PageUrlResult UpdateCustomUrl(SaveUrlDto dto, TabInfo tab)
        {
            var  portalSettings = PortalController.Instance.GetCurrentPortalSettings();
            var  urlPath        = dto.Path.ValueOrEmpty().TrimStart('/');
            bool modified;
            //Clean Url
            var options =
                UrlRewriterUtils.ExtendOptionsForCustomURLs(
                    UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalSettings.PortalId)));

            //now clean the path
            urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified);
            if (modified)
            {
                return(new PageUrlResult
                {
                    Success = false,
                    ErrorMessage = Localization.GetString("CustomUrlPathCleaned.Error"),
                    SuggestedUrlPath = "/" + urlPath
                });
            }

            //Validate for uniqueness
            urlPath = FriendlyUrlController.ValidateUrl(urlPath, tab.TabID, portalSettings, out modified);
            if (modified)
            {
                return(new PageUrlResult
                {
                    Success = false,
                    ErrorMessage = Localization.GetString("UrlPathNotUnique.Error"),
                    SuggestedUrlPath = "/" + urlPath
                });
            }

            var cultureCode = LocaleController.Instance.GetLocales(portalSettings.PortalId)
                              .Where(l => l.Value.KeyID == dto.LocaleKey)
                              .Select(l => l.Value.Code)
                              .SingleOrDefault() ?? portalSettings.DefaultLanguage;

            var statusCodeKey = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture);
            var tabUrl        = tab.TabUrls.SingleOrDefault(t => t.SeqNum == dto.Id && t.HttpStatus == statusCodeKey);

            if (statusCodeKey == "200")
            {
                //We need to check if we are updating a current url or creating a new 200
                if (tabUrl == null)
                {
                    //Just create Url
                    tabUrl = new TabUrlInfo
                    {
                        TabId            = tab.TabID,
                        SeqNum           = dto.Id,
                        PortalAliasId    = dto.SiteAliasKey,
                        PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage,
                        QueryString      = dto.QueryString.ValueOrEmpty(),
                        Url         = dto.Path.ValueOrEmpty(),
                        CultureCode = cultureCode,
                        HttpStatus  = "200",
                        IsSystem    = dto.IsSystem // false
                    };
                    TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                }
                else
                {
                    if (!tabUrl.Url.Equals("/" + urlPath, StringComparison.InvariantCultureIgnoreCase))
                    {
                        //Change the original 200 url to a redirect
                        tabUrl.HttpStatus = "301";
                        tabUrl.SeqNum     = dto.Id;
                        TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);

                        //Add new custom url
                        tabUrl.Url              = dto.Path.ValueOrEmpty();
                        tabUrl.HttpStatus       = "200";
                        tabUrl.SeqNum           = tab.TabUrls.Max(t => t.SeqNum) + 1;
                        tabUrl.CultureCode      = cultureCode;
                        tabUrl.PortalAliasId    = dto.SiteAliasKey;
                        tabUrl.PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage;
                        tabUrl.QueryString      = dto.QueryString.ValueOrEmpty();
                        TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                    }
                    else
                    {
                        //Update the original 200 url
                        tabUrl.CultureCode      = cultureCode;
                        tabUrl.PortalAliasId    = dto.SiteAliasKey;
                        tabUrl.PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage;
                        tabUrl.QueryString      = dto.QueryString.ValueOrEmpty();
                        TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                    }
                }
            }
            else
            {
                //Update the original non 200 url
                if (tabUrl == null)
                {
                    tabUrl = new TabUrlInfo
                    {
                        TabId            = tab.TabID,
                        SeqNum           = dto.Id,
                        PortalAliasId    = dto.SiteAliasKey,
                        PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage,
                        QueryString      = dto.QueryString.ValueOrEmpty(),
                        Url         = dto.Path.ValueOrEmpty(),
                        CultureCode = cultureCode,
                        HttpStatus  = statusCodeKey,
                        IsSystem    = dto.IsSystem // false
                    };
                    TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                }
                else
                {
                    tabUrl.CultureCode      = cultureCode;
                    tabUrl.PortalAliasId    = dto.SiteAliasKey;
                    tabUrl.PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage;
                    tabUrl.Url         = dto.Path.ValueOrEmpty();
                    tabUrl.HttpStatus  = statusCodeKey;
                    tabUrl.QueryString = dto.QueryString.ValueOrEmpty();
                    TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);
                }
            }


            return(new PageUrlResult
            {
                Success = true
            });
        }
Ejemplo n.º 3
0
        public PageUrlResult CreateCustomUrl(SaveUrlDto dto, TabInfo tab)
        {
            var  portalSettings = PortalController.Instance.GetCurrentPortalSettings();
            var  urlPath        = dto.Path.ValueOrEmpty().TrimStart('/');
            bool modified;
            //Clean Url
            var options = UrlRewriterUtils.ExtendOptionsForCustomURLs(UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(portalSettings.PortalId)));

            urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified);
            if (modified)
            {
                return(new PageUrlResult {
                    Success = false,
                    ErrorMessage = Localization.GetString("CustomUrlPathCleaned.Error"),
                    SuggestedUrlPath = "/" + urlPath
                });
            }

            //Validate for uniqueness
            urlPath = FriendlyUrlController.ValidateUrl(urlPath, -1, portalSettings, out modified);
            if (modified)
            {
                return(new PageUrlResult {
                    Success = false,
                    ErrorMessage = Localization.GetString("UrlPathNotUnique.Error"),
                    SuggestedUrlPath = "/" + urlPath
                });
            }

            if (tab.TabUrls.Any(u => u.Url.ToLowerInvariant() == dto.Path.ValueOrEmpty().ToLowerInvariant() &&
                                (u.PortalAliasId == dto.SiteAliasKey || u.PortalAliasId == -1)))
            {
                return(new PageUrlResult {
                    Success = false,
                    ErrorMessage = Localization.GetString("DuplicateUrl.Error")
                });
            }

            var seqNum        = (tab.TabUrls.Count > 0) ? tab.TabUrls.Max(t => t.SeqNum) + 1 : 1;
            var portalLocales = LocaleController.Instance.GetLocales(portalSettings.PortalId);
            var cultureCode   = portalLocales.Where(l => l.Value.KeyID == dto.LocaleKey)
                                .Select(l => l.Value.Code)
                                .SingleOrDefault();

            var portalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage;

            if (portalAliasUsage == PortalAliasUsageType.Default)
            {
                var alias = PortalAliasController.Instance.GetPortalAliasesByPortalId(portalSettings.PortalId)
                            .SingleOrDefault(a => a.PortalAliasID == dto.SiteAliasKey);

                if (string.IsNullOrEmpty(cultureCode) || alias == null)
                {
                    return(new PageUrlResult
                    {
                        Success = false,
                        ErrorMessage = Localization.GetString("InvalidRequest.Error")
                    });
                }
            }
            else
            {
                var cultureAlias = PortalAliasController.Instance.GetPortalAliasesByPortalId(portalSettings.PortalId)
                                   .FirstOrDefault(a => a.CultureCode == cultureCode);

                if (portalLocales.Count > 1 && !portalSettings.ContentLocalizationEnabled && (string.IsNullOrEmpty(cultureCode) || cultureAlias == null))
                {
                    return(new PageUrlResult
                    {
                        Success = false,
                        ErrorMessage = Localization.GetString("InvalidRequest.Error")
                    });
                }
            }

            var tabUrl = new TabUrlInfo
            {
                TabId            = tab.TabID,
                SeqNum           = seqNum,
                PortalAliasId    = dto.SiteAliasKey,
                PortalAliasUsage = portalAliasUsage,
                QueryString      = dto.QueryString.ValueOrEmpty(),
                Url         = dto.Path.ValueOrEmpty(),
                CultureCode = cultureCode,
                HttpStatus  = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture),
                IsSystem    = false
            };

            TabController.Instance.SaveTabUrl(tabUrl, portalSettings.PortalId, true);

            return(new PageUrlResult
            {
                Success = true,
                Id = seqNum // returns Id of the created Url
            });
        }
Ejemplo n.º 4
0
        public HttpResponseMessage UpdateCustomUrl(SaveUrlDto dto)
        {
            var tab     = PortalSettings.ActiveTab;
            var urlPath = dto.Path.ValueOrEmpty().TrimStart('/');
            HttpResponseMessage response;

            if (string.IsNullOrEmpty(urlPath))
            {
                var tabUrl = new TabUrlInfo
                {
                    TabId  = tab.TabID,
                    SeqNum = dto.Id,
                };
                TestableTabController.Instance.DeleteTabUrl(tabUrl, PortalId, true);

                response = Request.CreateResponse(HttpStatusCode.OK, new { Success = true, });
            }
            else
            {
                bool modified;
                //Clean Url
                var options = UrlRewriterUtils.GetOptionsFromSettings(new FriendlyUrlSettings(PortalSettings.PortalId));
                //custom urls are special in that they can contain the / character to create path levels
                options.ReplaceChars = options.ReplaceChars.Replace("/", "");
                options.IllegalChars = options.IllegalChars.Replace("/", "");
                options.RegexMatch   = options.RegexMatch.Replace("[^", "[^/");
                //now clean the path
                urlPath = FriendlyUrlController.CleanNameForUrl(urlPath, options, out modified);
                if (modified)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK,
                                                  new
                    {
                        Success = false,
                        ErrorMessage = Localization.GetString("UrlPathCleaned.Error", Localization.GlobalResourceFile),
                        SuggestedUrlPath = "/" + urlPath
                    }));
                }

                //Validate for uniqueness
                urlPath = FriendlyUrlController.ValidateUrl(urlPath, -1, PortalSettings, out modified);
                if (modified)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK,
                                                  new
                    {
                        Success = false,
                        ErrorMessage = Localization.GetString("UrlPathNotUnique.Error", Localization.GlobalResourceFile),
                        SuggestedUrlPath = "/" + urlPath
                    }));
                }

                var cultureCode = LocaleController.Instance.GetLocales(PortalId)
                                  .Where(l => l.Value.KeyID == dto.LocaleKey)
                                  .Select(l => l.Value.Code)
                                  .SingleOrDefault();

                var tabUrl = new TabUrlInfo
                {
                    TabId            = tab.TabID,
                    SeqNum           = dto.Id,
                    PortalAliasId    = dto.SiteAliasKey,
                    PortalAliasUsage = (PortalAliasUsageType)dto.SiteAliasUsage,
                    QueryString      = dto.QueryString.ValueOrEmpty(),
                    Url         = dto.Path.ValueOrEmpty(),
                    CultureCode = cultureCode,
                    HttpStatus  = dto.StatusCodeKey.ToString(CultureInfo.InvariantCulture),
                    IsSystem    = dto.IsSystem // false
                };

                TestableTabController.Instance.SaveTabUrl(tabUrl, PortalId, true);

                response = Request.CreateResponse(HttpStatusCode.OK, new { Success = true, });
            }

            return(response);
        }