public UmbracoArticleModel GetArticleContent(int articleId)
        {
            var contentService = Services.ContentService;
            var article        = contentService.GetById(articleId);

            JArray rawCategories = article.GetValue("category") != null ? (JArray)JsonConvert.DeserializeObject(article.GetValue("category").ToString()) : new JArray();
            JArray rawKeywords   = article.GetValue("metaKeywords") != null ? (JArray)JsonConvert.DeserializeObject(article.GetValue("metaKeywords").ToString()) : new JArray();
            JArray rawCountry    = article.GetValue("country") != null ? (JArray)JsonConvert.DeserializeObject(article.GetValue("country").ToString()) : new JArray();

            string[] taggedCategories = rawCategories.ToObject <string[]>();
            string[] taggedKeywords   = rawKeywords.ToObject <string[]>();
            string[] countries        = rawCountry.ToObject <string[]>();

            string keywords = utilities.ConcatenateStringArray(taggedKeywords);
            string country  = countries.Length > 0 ? countries[0] : "";

            UmbracoArticleModel model = new UmbracoArticleModel()
            {
                ArticleId                          = article.Id,
                ArticleName                        = article.Name,
                ArticleDate                        = article.GetValue("articleDate") != null ? (DateTime)article.GetValue("articleDate") : DateTime.Now.Date,
                AuthorName                         = article.GetValue("authorName") != null?article.GetValue("authorName").ToString() : "",
                                             Title = article.GetValue("title") != null?article.GetValue("title").ToString() : "",
                                                         MetaName = article.GetValue("metaName") != null?article.GetValue("metaName").ToString() : "",
                                                                        MetaDescription = article.GetValue("metaDescription") != null?article.GetValue("metaDescription").ToString() : "",
                                                                                              Country            = country,
                                                                                              MetaKeywords       = keywords,
                                                                                              SelectedCategories = taggedCategories,
                                                                                              Categories         = utilities.GetContentCategories(),
                                                                                              Countries          = _dataTypeValueService.GetItemsFromValueListDataType("Dropdown Countries", null)
            };

            return(model);
        }
        public ActionResult MemberArticleContent(int articleId)
        {
            var contentService = Services.ContentService;
            var article        = contentService.GetById(articleId);

            UmbracoArticleModel model = new UmbracoArticleModel();

            model.Description = new HtmlString(article.GetValue("description").ToString());
            model.ArticleId   = articleId;

            return(PartialView(GetTasksViewPath("_ArticleContent"), model));
        }
        public void UpdateArticleGridFields(IContent article, UmbracoArticleModel model)
        {
            loggedMember = GetLoggedMember();
            var memberUdi = Current.Services.MemberService.GetById(loggedMember.MemberId).GetUdi();

            article.Name = model.ArticleName;
            article.SetValue(Article.GetModelPropertyType(x => x.Title).Alias, model.Title);
            article.SetValue(Article.GetModelPropertyType(x => x.AuthorName).Alias, model.AuthorName);
            article.SetValue(Article.GetModelPropertyType(x => x.ArticleDate).Alias, model.ArticleDate);
            article.SetValue(Article.GetModelPropertyType(x => x.MetaName).Alias, model.MetaName);
            article.SetValue(Article.GetModelPropertyType(x => x.ArticleMember).Alias, memberUdi);
        }
        public void UpdateArticleDetails(IContent article, UmbracoArticleModel model)
        {
            List <string> keywords   = model.MetaKeywords.Split(',').ToList();
            List <string> categories = model.SelectedCategories.ToList();

            var country = JsonConvert.SerializeObject(new[] { model.Country });

            article.Name = model.ArticleName;
            article.SetValue(Article.GetModelPropertyType(x => x.Title).Alias, model.Title);
            article.SetValue(Article.GetModelPropertyType(x => x.AuthorName).Alias, model.AuthorName);
            article.SetValue(Article.GetModelPropertyType(x => x.ArticleDate).Alias, model.ArticleDate);
            article.SetValue(Article.GetModelPropertyType(x => x.MetaName).Alias, model.MetaName);
            article.SetValue(Article.GetModelPropertyType(x => x.MetaDescription).Alias, model.MetaDescription);
            article.SetValue(Article.GetModelPropertyType(x => x.Category).Alias, JsonConvert.SerializeObject(categories));
            article.SetValue(Article.GetModelPropertyType(x => x.MetaKeywords).Alias, JsonConvert.SerializeObject(keywords));
            article.SetValue(Article.GetModelPropertyType(x => x.Country).Alias, JsonConvert.SerializeObject(new[] { model.Country }));
        }
        public ActionResult ArticleContentSave(string htmlText, int articleId)
        {
            string msg = "The content of the article was successfully saved.";

            var contentService = Services.ContentService;
            var article        = contentService.GetById(articleId);

            UmbracoArticleModel model = new UmbracoArticleModel();

            string htmlValue = JsonConvert.DeserializeObject(htmlText).ToString();

            // Do this to get rid of the enclosing quotation marks ""
            model.Description = new HtmlString(htmlValue);

            article.SetValue(Article.GetModelPropertyType(x => x.Description).Alias, model.Description);
            contentService.SaveAndPublish(article);

            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
        public ActionResult SubmitArticleDetails(UmbracoArticleModel model)
        {
            var contentService = Services.ContentService;
            var article        = contentService.GetById(model.ArticleId);

            if (model != null && ModelState.IsValid)
            {
                UpdateArticleDetails(article, model);
                contentService.SaveAndPublish(article);
            }

            // required to set the sources again on post
            model.Countries  = _dataTypeValueService.GetItemsFromValueListDataType("Dropdown Countries", null);
            model.Categories = utilities.GetContentCategories();

            ViewData["successMessage"] = "Detail data were successfully saved at " + string.Format("{0:dd/MM/yyyy HH:mm:ss}", DateTime.Now);

            return(PartialView(GetTasksViewPath("_ArticleDetail"), model));
        }
        public ActionResult MemberArticleDetail(int articleId)
        {
            UmbracoArticleModel model = GetArticleContent(articleId);

            return(PartialView(GetTasksViewPath("_ArticleDetail"), model));
        }
        public ActionResult UmbracoArticle_Destroy([DataSourceRequest] DataSourceRequest request, UmbracoArticleModel model)
        {
            var contentService = Services.ContentService;
            var article        = contentService.GetById(model.ArticleId);

            contentService.Unpublish(article);
            contentService.Delete(article); // here content getting deleted
            contentService.EmptyRecycleBin(userId: -1);

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet));
        }
        public ActionResult UmbracoArticle_Update([DataSourceRequest] DataSourceRequest request, UmbracoArticleModel model)
        {
            var contentService = Services.ContentService;
            var article        = contentService.GetById(model.ArticleId);

            if (model != null && ModelState.IsValid)
            {
                UpdateArticleGridFields(article, model);
                contentService.SaveAndPublish(article);
            }
            return(Json(new[] { model }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet));
        }
Esempio n. 10
0
        public ActionResult UmbracoArticle_Create([DataSourceRequest] DataSourceRequest request, UmbracoArticleModel model)
        {
            IPublishedContent homePage     = Umbraco.ContentAtRoot().Where(f => f.IsDocumentType(HOMEPAGE_DOCTYPE_ALIAS)).FirstOrDefault();
            IPublishedContent articlesList = homePage.Descendants().Where(x => x.IsDocumentType(ARTICLELIST_DOCTYPE_ALIAS)).FirstOrDefault();
            var parentId = articlesList.Id;

            var contentService = Services.ContentService;

            if (model != null && ModelState.IsValid)
            {
                var article = contentService.Create(model.ArticleName, parentId, Article.ModelTypeAlias);

                UpdateArticleGridFields(article, model);
                contentService.SaveAndPublish(article);
                model.ArticleId = article.Id;
            }
            return(Json(new[] { model }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet));
        }