Example #1
0
        public virtual ActionResult ChangeLanguage(long articleId, String culture)
        {
            var article = articleService.Find(articleId);

            if (article == null || !permissionService.IsAllowed((Int32)ArticleOperations.View, this.CorePrincipal(), typeof(Article), article.Id, IsArticleOwner(article), PermissionOperationLevel.Object))
            {
                throw new HttpException((int)HttpStatusCode.NotFound, HttpContext.Translate("Messages.NotFound", ResourceHelper.GetControllerScope(this)));
            }

            bool allowManage = permissionService.IsAllowed((Int32)ArticleOperations.Manage, this.CorePrincipal(),
                                                           typeof(Article), article.Id, IsArticleOwner(article),
                                                           PermissionOperationLevel.Object);

            ArticleViewModel model = new ArticleViewModel {
                AllowManage = allowManage
            }.MapFrom(article);

            model.SelectedCulture = culture;

            //get locale
            var           localeService = ServiceLocator.Current.GetInstance <IArticleLocaleService>();
            ArticleLocale locale        = localeService.GetLocale(articleId, culture);

            if (locale != null)
            {
                model.MapLocaleFrom(locale);
            }

            return(PartialView("ArticleDetails", model));
        }
        public ArticleViewModel MapLocaleFrom(ArticleLocale locale)
        {
            Title           = locale.Title;
            Summary         = locale.Summary;
            Content         = locale.Description;
            SelectedCulture = locale.Culture;

            return(this);
        }
 public ArticleLocale MapLocaleTo(ArticleLocale locale)
 {
     locale.Title       = Title;
     locale.Description = Content;
     locale.Summary     = Summary;
     if (SelectedCulture != null)
     {
         locale.Culture = SelectedCulture;
     }
     return(locale);
 }
Example #4
0
        public virtual ActionResult Save(ArticleViewModel model)
        {
            ArticleHelper.ValidateArticle(model, ModelState);
            if (ModelState.IsValid)
            {
                var article = articleService.Find(model.Id);

                if (article == null || !permissionService.IsAllowed((Int32)ArticleOperations.Manage, this.CorePrincipal(), typeof(Article), article.Id, IsArticleOwner(article), PermissionOperationLevel.Object))
                {
                    throw new HttpException((int)HttpStatusCode.NotFound, HttpContext.Translate("Messages.NotFound", ResourceHelper.GetControllerScope(this)));
                }

                if (articleService.Save(model.MapTo(article)))
                {
                    //save locale
                    var           localeService = ServiceLocator.Current.GetInstance <IArticleLocaleService>();
                    ArticleLocale locale        = localeService.GetLocale(article.Id, model.SelectedCulture);
                    locale = model.MapLocaleTo(locale ?? new ArticleLocale {
                        Article = article
                    });

                    localeService.Save(locale);

                    Success(HttpContext.Translate("Messages.Success", String.Empty));
                    return(RedirectToAction(WebContentMVC.Article.Edit(model.Id)));
                }
            }
            else
            {
                Error(HttpContext.Translate("Messages.ValidationError", String.Empty));
            }

            model.AllowManage = true;

            return(View("Edit", model));
        }