コード例 #1
0
        private bool Save()
        {
            var result = false;

            if (UrlRewriter.IsUrlInUse(RequestedUrlField.Text.Trim(), BvinField.Value, HccApp.CurrentRequestContext,
                                       HccApp))
            {
                MessageBox1.ShowWarning("Another item already uses this URL. Please choose another one");
                return(false);
            }

            Commerce.Content.CustomUrl c;
            c = HccApp.ContentServices.CustomUrls.Find(BvinField.Value);
            if (c == null)
            {
                c = new Commerce.Content.CustomUrl();
            }
            if (c != null)
            {
                c.RequestedUrl        = RequestedUrlField.Text.Trim();
                c.RedirectToUrl       = RedirectToUrlField.Text.Trim();
                c.IsPermanentRedirect = chkPermanent.Checked;

                if (BvinField.Value == string.Empty)
                {
                    result = HccApp.ContentServices.CustomUrls.Create(c);
                }
                else
                {
                    result = HccApp.ContentServices.CustomUrls.Update(c);
                }

                if (result)
                {
                    // Update bvin field so that next save will call updated instead of create
                    BvinField.Value = c.Bvin;
                }
            }

            LoadPreview();
            return(result);
        }
コード例 #2
0
        public void Register301(string requestedUrl, string redirectUrl, string objectId, CustomUrlType customUrlType,
                                HccRequestContext context, HotcakesApplication app)
        {
            var AlreadyInUse = UrlRewriter.IsUrlInUse(requestedUrl, string.Empty, context, app);

            if (AlreadyInUse)
            {
                return;
            }
            var customUrl = new CustomUrl
            {
                IsPermanentRedirect = true,
                RedirectToUrl       = redirectUrl,
                RequestedUrl        = requestedUrl,
                StoreId             = app.CurrentRequestContext.CurrentStore.Id,
                SystemData          = objectId,
                SystemDataType      = customUrlType
            };

            Create(customUrl);
            UpdateAllUrlsForObject(objectId, redirectUrl);
        }