Exemple #1
0
        public IActionResult EditArticle(articleEditViewModel viewModel)
        {
            IActionResult ret;
            string        err;
            //todo !!... edit article
            // articles, ckeditor, paste base64 image
            object obj = Request.Form;

            switch (viewModel.cmd)
            {
            case "save":
                err = checkForm(viewModel);
                if (err.Length > 0)
                {
                    viewModel.errorMsg = err;
                    ret = View(viewModel);
                    break;
                }
                //Article article2add = new Article();
                //article2add.ArticleId = Guid.NewGuid();
                //article2add.ArticleTitle =
                //    viewModel.ArticleTitle;
                //article2add.ArticleHtmlContent =
                //    viewModel.ArticleHtmlContent;
                string pureText;
                err = htmlHelper.removeHtmlTags(
                    viewModel.ArticleHtmlContent, out pureText);
                if (err.Length > 0)
                {
                    viewModel.errorMsg = err;
                    ret = View(viewModel);
                    break;
                }
                viewModel.ArticleContent = pureText;
                //article2add.IsDir = viewModel.IsDir ;
                tblArticle tArticle = new tblArticle();
                if (viewModel.changeMode == ARTICLE_CHANGE_MODE.CREATE)
                {
                    viewModel.ArticleId = Guid.NewGuid();
                    err  = tArticle.Add(viewModel);
                    err += tArticle.SaveChanges();
                }
                else if (viewModel.changeMode == ARTICLE_CHANGE_MODE.EDIT)
                {
                    err  = tArticle.Update(viewModel);
                    err += tArticle.SaveChanges();
                }
                else if (viewModel.changeMode == ARTICLE_CHANGE_MODE.REPLY_TO)
                {
                    // transaction, 1. create replied article 2. change original article to be directory type
                    SASDdbBase db = new SASDdbBase();
                    using (var transaction = db.BeginTransaction())
                    {
                        viewModel.ArticleId = Guid.NewGuid();
                        err  = tArticle.Add(viewModel);
                        err += tArticle.SaveChanges();
                        tblArticle tart    = new tblArticle();
                        Article    replied = tart.GetArticleById(viewModel.BelongToArticleDirId.ToString());
                        replied.IsDir = true;
                        tart.Update(replied);
                        tart.SaveChanges();
                        transaction.Commit();
                    }
                }
                if (err.Length > 0)
                {
                    viewModel.errorMsg = err;
                }
                else
                {
                    viewModel.successMsg = "new article successfully added";
                }
                //undone !!... notification failed
                //todo !!...proceed to save article/directory
                //ViewBag.Message = "article/directory saved";
                ret = View(viewModel);
                break;

            default:
                ret = View(viewModel);
                break;
            }
            TempData["articleEditViewModel"] = jsonUtl.encodeJson(viewModel);
            return(ret);
        }
Exemple #2
0
        public ActionResult EditArticle(articleEditViewModel viewModel)
        {
            ActionResult ret;

            ViewBag.articleTypeOption     = SAdropdownOptions.articleTypeOption();
            ViewBag.articleStatusOption   = SAdropdownOptions.articleStatusOption();
            ViewBag.articlePriorityOption = SAdropdownOptions.articlePriorityOption();
            ViewBag.userList = PMdropdownOption.userList();
            string err;

            // articles, ckeditor, paste base64 image
            switch (viewModel.cmd)
            {
            case "save":
                err = checkForm(viewModel);
                if (err.Length > 0)
                {
                    viewModel.errorMsg = err;
                    ret = View(viewModel);
                    break;
                }
                //article article2add = new article();
                //article2add.ArticleId = Guid.NewGuid();
                //article2add.ArticleTitle =
                //    viewModel.ArticleTitle;
                //article2add.ArticleHtmlContent =
                //    viewModel.ArticleHtmlContent;
                string pureText;
                err = htmlHelper.removeHtmlTags(
                    viewModel.editModel.articleHtmlContent, out pureText);
                if (err.Length > 0)
                {
                    viewModel.errorMsg = err;
                    ret = View(viewModel);
                    break;
                }
                viewModel.editModel.articleContent = pureText;
                //article2add.IsDir = viewModel.IsDir ;
                tblArticle tArticle = new tblArticle();
                if (viewModel.changeMode == ARTICLE_CHANGE_MODE.CREATE)
                {
                    viewModel.editModel.articleId  = Guid.NewGuid();
                    viewModel.editModel.createtime = DateTime.Now;
                    //article art = new article();
                    //art.articleId = viewModel.articleId;
                    //art.createtime = DateTime.Now;
                    //art.articleTitle = viewModel.articleTitle;
                    //art.articleHtmlContent = viewModel.articleHtmlContent;
                    //art.articleContent = viewModel.articleContent;
                    //art.isDir = viewModel.isDir;
                    //art.belongToArticleDirId = viewModel.belongToArticleDirId;

                    err  = tArticle.Add(viewModel.editModel);   // as article);
                    err += tArticle.SaveChanges();
                    if (err.Length > 0)
                    {
                        viewModel.errorMsg = "error: " + err;
                    }
                    else
                    {
                        viewModel.successMsg = "new article successfully added";
                        viewModel.pageStatus = (int)modelsfwk.PAGE_STATUS.ADDSAVED;
                    }
                }
                else if (viewModel.changeMode == ARTICLE_CHANGE_MODE.EDIT)
                {
                    err  = tArticle.Update(viewModel.editModel);
                    err += tArticle.SaveChanges();
                    if (err.Length > 0)
                    {
                        viewModel.errorMsg = "error: " + err;
                    }
                    else
                    {
                        viewModel.successMsg = "article successfully updated";
                        viewModel.pageStatus = (int)modelsfwk.PAGE_STATUS.SAVED;
                    }
                }
                else if (viewModel.changeMode == ARTICLE_CHANGE_MODE.REPLY_TO)
                {
                    // transaction, 1. create replied article 2. change original article to be directory type
                    string     err1 = "";
                    SASDdbBase db   = new SASDdbBase();
                    using (var transaction = db.BeginTransaction())
                    {
                        viewModel.editModel.articleId  = Guid.NewGuid();
                        viewModel.editModel.createtime = DateTime.Now;
                        err1  = tArticle.Add(viewModel.editModel);   // as article);
                        err1 += tArticle.SaveChanges();
                        tblArticle tart    = new tblArticle();
                        article    replied = tart.GetArticleById(viewModel.editModel.belongToArticleDirId.ToString());
                        replied.isDir = true;
                        err1         += tart.Update(replied);
                        err1         += tart.SaveChanges();
                        if (err1.Length == 0)
                        {
                            transaction.Commit();
                        }
                        else
                        {
                            err += err1;
                        }
                    }
                    if (err.Length > 0)
                    {
                        viewModel.errorMsg = "error: " + err;
                    }
                    else
                    {
                        viewModel.successMsg = "new article successfully added";
                        viewModel.pageStatus = (int)modelsfwk.PAGE_STATUS.ADDSAVED;
                    }
                }
                // notification failed, so, should use pure hidden field rather than html helped
                //ViewBag.Message = "article/directory saved";
                ret = View(viewModel);
                break;

            default:
                ret = View(viewModel);
                break;
            }
            TempData["articleEditViewModel"] = viewModel;
            return(ret);
        }