Esempio n. 1
0
        public string SavePageMetadata(string urlKey, string navigationtab, string tags, string description, string head)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(urlKey))
            {
                try
                {
                    bool exists = ArticleStore.Instance.Exists(urlKey);

                    if (exists)
                    {

                        StaticArticle article = new StaticArticle();
                        article.UrlKey = urlKey;
                        article.Read(PublishingStage.Draft);
                        article.RemoveTags();

                        ((INavigationTag)article).Name = navigationtab ?? string.Empty;;

                        if (!string.IsNullOrEmpty(tags))
                        {
                            article.AddTags(tags);
                        }

                        article.Head = head ?? string.Empty;
                        article.Description = description ?? string.Empty;
                        article.Update();

                        output.Success = true;
                    }
                }
                catch (MessageException me)
                {
                    logger.Log(LogLevel.Error, "Unable to save article metadata. MessageException - {0}", me);
                    output.AddOutput(Constants.Json.Error, me.Message);
                }
                catch (Exception ex)
                {
                    logger.Log(LogLevel.Error, "Unable to save article metadata. Exception - {0}", ex);
                    output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Articles.Edit.Create.Error"));
                }
            }

            return output.GetJson();
        }
Esempio n. 2
0
        public string SavePage(string urlKey, string title, string body)
        {
            //make sure the user has access
            RatnaUser user = base.ValidatedUser();
            if (user == null)
            {
                return SendAccessDenied();
            }

            ServiceOutput output = new ServiceOutput();
            output.Success = false;

            if (!string.IsNullOrEmpty(urlKey))
            {
                //make sure the url is relative and valid.
                if (!Uri.IsWellFormedUriString(urlKey, UriKind.Relative))
                {
                    // failed because URL is not valid.
                    output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Articles.Edit.Url.Validate.Error"));
                }
                else
                {
                    try
                    {
                        bool exists = ArticleStore.Instance.Exists(urlKey);

                        StaticArticle article = new StaticArticle();
                        article.UrlKey = urlKey;

                        // if the article already exists, read the article
                        // to sync with latest version
                        if (exists)
                        {
                            article.Read(PublishingStage.Draft);
                        }

                        article.Title = title;
                        article.Body = body;

                        if (!exists)
                        {
                            article.Owner = user;
                            article.Create();
                        }
                        else
                        {
                            article.Update();
                        }

                        output.Success = true;
                    }
                    catch (MessageException me)
                    {
                        logger.Log(LogLevel.Error, "Unable to save page. MessageException - {0}", me);
                        output.AddOutput(Constants.Json.Error, me.Message);
                    }
                    catch (Exception ex)
                    {
                        logger.Log(LogLevel.Error, "Unable to save page. Exception - {0}", ex);
                        output.AddOutput(Constants.Json.Error, ResourceManager.GetLiteral("Admin.Articles.Edit.Create.Error"));
                    }
                }
            }

            return output.GetJson();
        }