Ejemplo n.º 1
0
        public ActionResult UpsertLocale(Article item)
        {
            if (ModelState.IsValid)
            {
                String error = null;
                if (item.ArticleID == 0)
                {
                    // create
                    error = ArticleDbContext.getInstance().tryCreateNewLocaleArticle(item);
                }
                else
                {
                    // edit
                    error = ArticleDbContext.getInstance().tryEditArticle(item);
                }

                if (error != null)
                {
                    ModelState.AddModelError("", error);
                }
                else
                {
                    ViewBag.Message = "Edit '" + item.Name + "' successfully";
                    return(View(item));
                }
            }
            return(View(item));
        }
Ejemplo n.º 2
0
        public ActionResult DetailsProperties(int baseArticleID = 0, int version = 0, String lang = null)
        {
            // find existing locale article for base article ID and version and lang
            Article item = ArticleDbContext.getInstance().findArticleByVersionAndLang(baseArticleID, version, lang);

            if (item == null)
            {
                // if locale not exists, create blank form, while inheriting latest base article's version
                var baseArticle = ArticleDbContext.getInstance().findLatestArticleByBaseArticleID(baseArticleID, null);
                if (baseArticle == null)
                {
                    return(HttpNotFound());
                }

                var article = new Article();
                article.BaseArticleID = baseArticle.BaseArticleID;
                article.Lang          = lang;
                article.Version       = baseArticle.Version;
                item = article;
            }
            else
            {
                // if locale exists, treat as edit form
            }
            return(View(item));
        }
Ejemplo n.º 3
0
 public ActionResult CreateNewVersion(Article article)
 {
     if (ModelState.IsValid)
     {
         article.Lang    = null;
         article.Version = 0;
         var error = ArticleDbContext.getInstance().tryCreateNewArticle(article);
         if (error == null)
         {
             ModelState.Clear();
             var a = ArticleDbContext.getInstance().findLatestArticleByBaseArticle(article);
             TempData["Message"] = "New Version of '" + a.Name + "' with version: " + a.Version + " successfully created.";
             return(RedirectToAction("DetailsLocale", new { baseArticleID = a.BaseArticleID, version = a.Version, lang = a.Lang }));
         }
         else
         {
             ModelState.AddModelError("", error);
             return(View());
         }
     }
     else
     {
         return(View());
     }
 }
Ejemplo n.º 4
0
        public ActionResult EditProperties(int baseArticleID = 0, int version = 0, String lang = null)
        {
            Article item = ArticleDbContext.getInstance().findArticleByVersionAndLang(baseArticleID, version, lang);

            if (item == null)
            {
                // if locale not exists, create blank form, while inheriting latest base article's version
                var baseArticle = ArticleDbContext.getInstance().findLatestArticleByBaseArticleID(baseArticleID, null);
                if (baseArticle == null)
                {
                    return(HttpNotFound());
                }

                var article = new Article();
                article.BaseArticleID = baseArticle.BaseArticleID;
                article.Lang          = lang;
                article.Version       = baseArticle.Version;
                item = article;
            }
            else
            {
                // if locale exists, treat as edit form
            }
            ViewBag.categoryID = getCategoriesForSelect(item.categoryID);
            return(View(item));
        }
Ejemplo n.º 5
0
        public ActionResult ListArticleVersions(int baseArticleID = 0)
        {
            var article = new Article();

            article.BaseArticleID = baseArticleID;
            var items = ArticleDbContext.getInstance().findAllArticlesByBaseArticle(article);

            return(View(items));
        }
Ejemplo n.º 6
0
        public ActionResult List()
        {
            var items = ArticleDbContext.getInstance().findArticlesGroupByBaseVersion();

            if (TempData["Message"] != null)
            {
                ViewBag.Message = TempData["Message"];
            }
            return(View(items));
        }
Ejemplo n.º 7
0
        public ActionResult DeleteSingle(int id = 0)
        {
            var item = ArticleDbContext.getInstance().findArticleByID(id);

            if (item == null)
            {
                return(HttpNotFound());
            }
            return(View(item));
        }
Ejemplo n.º 8
0
        public ActionResult PublishArticle(Article article)
        {
            if (ModelState.IsValid)
            {
                var datePublishStart = article.datePublishStart;
                var datePublishEnd   = article.datePublishEnd;

                var item = ArticleDbContext.getInstance().findArticleByVersionAndLang(article.BaseArticleID, article.Version, "en");
                if (item == null)
                {
                    return(HttpNotFound());
                }

                if (datePublishStart != null &&
                    datePublishEnd != null)
                {
                    var start = datePublishStart.GetValueOrDefault();
                    var end   = datePublishEnd.GetValueOrDefault();

                    if (start.CompareTo(end) > 0)
                    {
                        TempData["ErrorMessage"] = "Publish end date must be greater than publish start date";
                        return(RedirectToAction("DetailsLocale", new { baseArticleID = item.BaseArticleID, version = item.Version, lang = "en" }));
                    }
                }

                item.datePublishStart = datePublishStart;
                item.datePublishEnd   = datePublishEnd;
                var error = ArticlePublishedDbContext.getInstance().tryPublishArticle(item, true);
                if (error != null)
                {
                    TempData["ErrorMessage"] = error;
                    return(RedirectToAction("DetailsLocale", new { baseArticleID = item.BaseArticleID, version = item.Version, lang = "en" }));
                }
                else
                {
                    TempData["Message"] = "'" + item.Name + "' Published";
                    return(RedirectToAction("DetailsLocale", new { baseArticleID = item.BaseArticleID, version = item.Version, lang = "en" }));
                }
            }
            else
            {
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        TempData["ErrorMessage"] = error.ErrorMessage;
                    }
                }
                var item = ArticleDbContext.getInstance().findArticleByVersionAndLang(article.BaseArticleID, article.Version, "en");
                return(RedirectToAction("DetailsLocale", new { baseArticleID = item.BaseArticleID, version = item.Version, lang = "en" }));
            }
        }
Ejemplo n.º 9
0
        public ActionResult ListArticleVersions(int baseArticleID = 0)
        {
            var article = new Article();

            article.BaseArticleID = baseArticleID;
            var items = ArticleDbContext.getInstance().findAllArticlesByBaseArticle(article);

            if (TempData["Message"] != null)
            {
                ViewBag.Message = TempData["Message"];
            }
            return(View(items));
        }
Ejemplo n.º 10
0
        public ActionResult ApproveArticle(int baseArticleID = 0, int version = 0, String lang = null)
        {
            // find existing locale article for base article ID and version and lang
            Article item = ArticleDbContext.getInstance().findArticleByVersionAndLang(baseArticleID, version, lang);

            if (item == null)
            {
                return(HttpNotFound());
            }
            else
            {
                // if locale exists, treat as edit form
            }
            return(View(item));
        }
Ejemplo n.º 11
0
 public ActionResult ApproveArticle(Article item)
 {
     if (ModelState.IsValid)
     {
         var error = ArticleDbContext.getInstance().tryRequestApproval(item, true);
         if (error != null)
         {
             ModelState.AddModelError("", error);
         }
         else
         {
             TempData["Message"] = "'" + item.Name + "' Approved";
             return(RedirectToAction("DetailsLocale", new { baseArticleID = item.BaseArticleID, version = item.Version, lang = item.Lang }));
         }
     }
     return(View(item));
 }
Ejemplo n.º 12
0
 public ActionResult Create(Article article)
 {
     if (ModelState.IsValid)
     {
         article.BaseArticleID = 0;
         article.Version       = 0;
         ArticleDbContext.getInstance().tryCreateNewArticle(article);
         ModelState.Clear();
         ViewBag.Message = article.Name + " successfully created.";
         return(RedirectToAction("DetailsLocale", new { baseArticleID = article.BaseArticleID, version = article.Version, lang = article.Lang }));
     }
     else
     {
         ViewBag.categoryID = getCategoriesForSelect();
         return(View());
     }
 }
Ejemplo n.º 13
0
        public ActionResult DeleteConfirmed(int id = 0)
        {
            var item = ArticleDbContext.getInstance().findArticleByID(id);

            if (item == null)
            {
                return(HttpNotFound());
            }
            var name  = item.Name;
            var error = ArticleDbContext.getInstance().tryDeleteArticle(item, true);

            if (error != null)
            {
                ModelState.AddModelError("", error);
                return(View(item));
            }
            TempData["Message"] = "'" + name + "' Deleted";
            return(RedirectToAction("List"));
        }
Ejemplo n.º 14
0
 public ActionResult EditProperties(Article item)
 {
     if (ModelState.IsValid)
     {
         var error = ArticleDbContext.getInstance().tryEditArticleProperties(item, true);
         if (error != null)
         {
             ModelState.AddModelError("", error);
         }
         else
         {
             ViewBag.categoryID = getCategoriesForSelect(item.categoryID);
             ViewBag.Message    = "Edit '" + item.Name + "' successfully";
             return(View(item));
         }
     }
     ViewBag.categoryID = getCategoriesForSelect(item.categoryID);
     return(View(item));
 }
Ejemplo n.º 15
0
        public ActionResult CreateWithViewModelForm(ArticleCreateForm form)
        {
            if (ModelState.IsValid)
            {
                // create empty article with base lang
                Article article = form.makeBaseArticle();
                article.BaseArticleID = 0;
                article.Version       = 0;
                var error = ArticleDbContext.getInstance().tryCreateNewArticle(article);

                if (error != null)
                {
                    ModelState.AddModelError("", error);
                    ViewBag.categoryID = getCategoriesForSelect();
                    return(View());
                }

                var baseArticleID = article.BaseArticleID;
                var version       = article.Version;

                // create locale articles

                var article_zh = form.makeLocaleArticle("zh");
                article_zh.BaseArticleID = baseArticleID;
                article_zh.Version       = version;
                ArticleDbContext.getInstance().tryCreateNewLocaleArticle(article_zh);

                var article_cn = form.makeLocaleArticle("cn");
                article_cn.BaseArticleID = baseArticleID;
                article_cn.Version       = version;
                ArticleDbContext.getInstance().tryCreateNewLocaleArticle(article_cn);

                ModelState.Clear();
                TempData["Message"] = "'" + article.Name + "' successfully created.";
                return(RedirectToAction("DetailsLocale", new { baseArticleID = article.BaseArticleID, version = article.Version, lang = article.Lang }));
            }
            else
            {
                ViewBag.categoryID = getCategoriesForSelect();
                return(View());
            }
        }
Ejemplo n.º 16
0
        public ActionResult UnpublishArticle(int baseArticleID = 0, int version = 0)
        {
            var item = ArticleDbContext.getInstance().findArticleByVersionAndLang(baseArticleID, version, "en");

            if (item == null)
            {
                return(HttpNotFound());
            }
            var error = ArticlePublishedDbContext.getInstance().tryUnpublishArticle(item, true);

            if (error != null)
            {
                ModelState.AddModelError("", error);
                return(RedirectToAction("DetailsLocale", new { baseArticleID = item.BaseArticleID, version = item.Version, lang = "en" }));
            }
            else
            {
                TempData["Message"] = "'" + item.Name + "' Unpublished";
                return(RedirectToAction("DetailsLocale", new { baseArticleID = item.BaseArticleID, version = item.Version, lang = "en" }));
            }
        }
Ejemplo n.º 17
0
        public ActionResult DetailsLocale(int baseArticleID = 0, int version = 0, String lang = null)
        {
            // find existing locale article for base article ID and version and lang
            Article item = ArticleDbContext.getInstance().findArticleByVersionAndLang(baseArticleID, version, lang);

            if (item == null)
            {
                return(HttpNotFound());
            }
            else
            {
                // if locale exists, treat as edit form
            }
            if (TempData["ErrorMessage"] != null)
            {
                ViewBag.ErrorMessage = TempData["ErrorMessage"];
            }
            if (TempData["Message"] != null)
            {
                ViewBag.Message = TempData["Message"];
            }
            return(View(item));
        }
Ejemplo n.º 18
0
        public ActionResult List()
        {
            var items = ArticleDbContext.getInstance().findArticlesRequestingApproval();

            return(View(items));
        }
Ejemplo n.º 19
0
        public ActionResult ArticleList()
        {
            var list = ArticleDbContext.getInstance().findArticlesGroupByBaseVersion();

            return(PartialView(list));
        }
Ejemplo n.º 20
0
        public ActionResult CreateNewVersion(int baseArticleID = 0)
        {
            var article = ArticleDbContext.getInstance().findLatestArticleByBaseArticleID(baseArticleID);

            return(View(article));
        }
Ejemplo n.º 21
0
        public ActionResult ListArticlesApproved()
        {
            var items = ArticleDbContext.getInstance().findArticlesGroupByBaseVersionApproved();

            return(View(items));
        }