Beispiel #1
0
        private string loadArticle(string articleId, string parentDirId
                                   , ref articlesViewModel viewModel)
        {
            string ret = "";
            // load directories
            tblArticle tbart  = new tblArticle();
            article    parent = null;

            viewModel.subjects = new List <article>();
            article art = null;

            if (!string.IsNullOrWhiteSpace(articleId))
            {
                art = tbart.GetArticleById(articleId);
                if (art != null)
                {
                    viewModel.articleTitle       = art.articleTitle;
                    viewModel.articleType        = art.articleType;
                    viewModel.articleHtmlContent = art.articleHtmlContent;
                    if (string.IsNullOrWhiteSpace(parentDirId))
                    {
                        parentDirId = art.belongToArticleDirId.ToString();
                    }
                }
            }
            if (art == null)
            {
                viewModel.articleTitle       = "";
                viewModel.articleType        = "";
                viewModel.articleHtmlContent = "";
            }
            if (!string.IsNullOrWhiteSpace(parentDirId))
            {
                parent = tbart.GetArticleById(parentDirId);
            }
            if (parent == null)
            {
                viewModel.parentDirId    = "";
                viewModel.parentDirTitle = "";
            }
            else
            {
                viewModel.parentDirId       = parent.articleId.ToString();
                viewModel.parentDirTitle    = parent.articleTitle;
                parent.belongToArticleDirId = parent.articleId;
                viewModel.subjects.Add(parent);
            }
            viewModel.directories = tbart.directoriesByParentArticleId(parentDirId);
            // load subjects
            viewModel.subjects.AddRange(tbart.subjectsByParentArticleId(parentDirId));
            // the article of the current directory, should be listed at the top of the subject list
            // and view its content when click on it
            return(ret);
        }
Beispiel #2
0
        private string loadArticle(string articleId, string parentDirId
                                   , ref articlesViewModel viewModel)
        {
            string ret = "";
            // load directories
            tblArticle tbart  = new tblArticle();
            Article    parent = null;

            if (!string.IsNullOrWhiteSpace(articleId))
            {
                Article art = tbart.GetArticleById(articleId);
                viewModel.articleTitle       = art.ArticleTitle;
                viewModel.articleHtmlContent = art.ArticleHtmlContent;
                parentDirId = art.BelongToArticleDirId.ToString();
            }
            else
            {
                viewModel.articleTitle = "";
            }
            if (!string.IsNullOrWhiteSpace(parentDirId))
            {
                parent = tbart.GetArticleById(parentDirId);
            }
            if (parent == null)
            {
                viewModel.parentDirId    = "";
                viewModel.parentDirTitle = "";
            }
            else
            {
                viewModel.parentDirId    = parent.ArticleId.ToString();
                viewModel.parentDirTitle = parent.ArticleTitle;
            }
            viewModel.directories = tbart.directoriesByParentArticleId(parentDirId);
            // load subjects
            viewModel.subjects = tbart.subjectsByParentArticleId(parentDirId);
            return(ret);
        }
Beispiel #3
0
        public IActionResult Articles(articlesViewModel viewModel)
        {
            IActionResult ret;
            var           selectedArticle = Request.Form["selectedArticle"];
            string        err             = loadArticle(viewModel.articleId, viewModel.parentDirId, ref viewModel);

            viewModel.errorMsg = err;
            articleEditViewModel aevm;
            tblArticle           ta;
            Article art = null;

            switch (viewModel.cmd)
            {
            case "create":
                //if (viewModel.editingArticle==null ||
                //    viewModel.editingArticle.BelongToArticleDirId==null)
                //{
                //    //todo !!... show error message
                //    ret = View(viewModel);
                //    break;
                //}
                //string BelongToArticleDirId = viewModel.parentDirId;
                aevm = new articleEditViewModel();
                if (!string.IsNullOrWhiteSpace(viewModel.parentDirId))
                {
                    aevm.BelongToArticleDirId = Guid.Parse(viewModel.parentDirId);
                    ta  = new tblArticle();
                    art = ta.GetArticleById(viewModel.parentDirId);
                    aevm.parentDirTitle = art.ArticleTitle;
                }
                aevm.changeMode = ARTICLE_CHANGE_MODE.CREATE;
                TempData["articleEditViewModel"] = jsonUtl.encodeJson(aevm);
                //viewModel.editingArticle = new Article();
                //if (!string.IsNullOrWhiteSpace(BelongToArticleDirId))
                //    viewModel.editingArticle.BelongToArticleDirId = Guid.Parse(BelongToArticleDirId);
                ret = RedirectToAction("EditArticle");
                break;

            case "edit":
                //if (viewModel.editingArticle == null ||
                //    viewModel.editingArticle.BelongToArticleDirId == null)
                //{
                //    //todo !!... show error message
                //    ret = View(viewModel);
                //    break;
                //}
                ta   = new tblArticle();
                art  = ta.GetArticleById(viewModel.articleId);
                aevm = jsonUtl.decodeJson <articleEditViewModel>(jsonUtl.encodeJson(art));
                //aevm = new articleEditViewModel();
                if (art == null || art.BelongToArticleDirId == null)
                {
                    aevm.parentDirTitle = EMPTY_PARENT_TITLE;
                }
                else
                {
                    Article artParent = ta.GetArticleById(art.BelongToArticleDirId.ToString());
                    aevm.parentDirTitle = artParent.ArticleTitle;
                }
                // undone !!... there is a huge big issue here, if there is image base64, then edit will crash, then crash the whole web project
                //aevm.ArticleContent = null;
                //aevm.ArticleHtmlContent = null;
                aevm.changeMode = ARTICLE_CHANGE_MODE.EDIT;
                string json = jsonUtl.encodeJson(aevm);
                TempData["articleEditViewModel"] = json;
                ret = RedirectToAction("EditArticle");
                break;

            case "replyTo":
                aevm = new articleEditViewModel();
                aevm.BelongToArticleDirId        = new Guid(viewModel.articleId);
                aevm.parentDirTitle              = viewModel.articleTitle;
                aevm.changeMode                  = ARTICLE_CHANGE_MODE.REPLY_TO;
                TempData["articleEditViewModel"] = jsonUtl.encodeJson(aevm);
                ret = RedirectToAction("EditArticle");
                break;

            case "delete":
                //todo !!.. delete confirm
                ViewBag.confirmDelete = "1";
                ret = View(viewModel);
                break;

            case "realDelete":
                //todo !!.. to real delete
                ret = View(viewModel);
                break;

            default:
                ret = View(viewModel);
                break;
            }
            TempData["articlesViewModel"] = jsonUtl.encodeJson(viewModel);
            return(ret);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public ActionResult Articles(articlesViewModel viewModel)
        {
            ActionResult ar;
            var          selectedDirectory = Request.Form["selectedDirectory"];
            var          selectedArticle   = Request.Form["selectedArticle"];

            if (!string.IsNullOrWhiteSpace(selectedDirectory))
            {
                string[] dirs = selectedDirectory.Split(',');
                viewModel.selectedDirId = new List <string>(dirs);
            }
            if (!string.IsNullOrWhiteSpace(selectedArticle))
            {
                string[] arts = selectedArticle.Split(',');
                viewModel.selectedArticleId = new List <string>(arts);
            }
            var confirmDelete = TempData["confirmDelete"];
            var tmpVM         = TempData["articlesViewModel"];
            articlesViewModel tmpViewModel = null;

            if (tmpVM != null)
            {
                tmpViewModel = (articlesViewModel)tmpVM;
                if (confirmDelete != null && (int)confirmDelete == 1)
                {
                    viewModel.selectedDirId     = tmpViewModel.selectedDirId;
                    viewModel.selectedArticleId = tmpViewModel.selectedArticleId;
                }
            }
            string err = loadArticle(viewModel.articleId, viewModel.parentDirId, ref viewModel);

            viewModel.errorMsg = err;
            articleEditViewModel aevm;
            tblArticle           ta;
            article art;

            switch (viewModel.cmd)
            {
            case "create":
                aevm = new articleEditViewModel();
                if (!string.IsNullOrWhiteSpace(viewModel.parentDirId))
                {
                    aevm.editModel.belongToArticleDirId = Guid.Parse(viewModel.parentDirId);
                    ta  = new tblArticle();
                    art = ta.GetArticleById(viewModel.parentDirId);
                    aevm.parentDirTitle = art.articleTitle;
                }
                aevm.changeMode = ARTICLE_CHANGE_MODE.CREATE;
                aevm.pageStatus = (int)modelsfwk.PAGE_STATUS.ADD;
                TempData["articleEditViewModel"] = aevm;
                ar = RedirectToAction("EditArticle");
                return(ar);

            case "edit":
                ta  = new tblArticle();
                art = ta.GetArticleById(viewModel.articleId);
                //aevm = jsonUtl.decodeJson<articleEditViewModel>(jsonUtl.encodeJson(art));
                aevm           = new articleEditViewModel();
                aevm.editModel = art;
                if (art == null || art.belongToArticleDirId == null)
                {
                    aevm.parentDirTitle = EMPTY_PARENT_TITLE;
                }
                else
                {
                    article artParent = ta.GetArticleById(art.belongToArticleDirId.ToString());
                    aevm.parentDirTitle = artParent.articleTitle;
                }
                aevm.changeMode = ARTICLE_CHANGE_MODE.EDIT;
                aevm.pageStatus = (int)modelsfwk.PAGE_STATUS.EDIT;
                TempData["articleEditViewModel"] = aevm;
                ar = RedirectToAction("EditArticle");
                return(ar);

            case "replyTo":
                aevm = new articleEditViewModel();
                aevm.editModel.belongToArticleDirId = new Guid(viewModel.articleId);
                aevm.parentDirTitle = viewModel.articleTitle;
                aevm.changeMode     = ARTICLE_CHANGE_MODE.REPLY_TO;
                aevm.pageStatus     = (int)modelsfwk.PAGE_STATUS.ADD;
                TempData["articleEditViewModel"] = aevm;
                ar = RedirectToAction("EditArticle");
                return(ar);

            case "parentDir":
                ar = RedirectToAction("Articles", new { articleId = viewModel.parentDirId });
                return(ar);

            case "delete":
                // delete confirm
                if (viewModel.selectedDirId.Count > 0 || viewModel.selectedArticleId.Count > 0)
                {
                    ViewBag.confirmDelete     = "1";
                    TempData["confirmDelete"] = 1;
                }
                ar = View(viewModel);
                break;

            case "realDelete":
                // to real delete
                //SASDdbBase db = new SASDdbBase();
                string               err1        = "";
                tblArticle           tart        = new tblArticle();
                DbContextTransaction transaction = tart.BeginTransaction();
                try
                {
                    foreach (string articleId in viewModel.selectedDirId)
                    {
                        err1 = tart.DeleteArticleOrDir(articleId);
                        if (err1.Length > 0)
                        {
                            throw new Exception(err1);
                        }
                    }
                    foreach (string articleId in viewModel.selectedArticleId)
                    {
                        err1 = tart.DeleteArticleOrDir(articleId);
                        if (err1.Length > 0)
                        {
                            throw new Exception(err1);
                        }
                    }
                    tart.SaveChanges();
                    transaction.Commit();
                    viewModel.successMsg = "selected directory(s) or article(s) successfully deleted";
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    viewModel.errorMsg  += ex.Message;
                    viewModel.successMsg = "";
                }
                err = loadArticle(viewModel.articleId, viewModel.parentDirId, ref viewModel);
                viewModel.errorMsg += err;
                // at last no matter what result, clear selection
                viewModel.selectedDirId.Clear();
                viewModel.selectedArticleId.Clear();
                ar = View(viewModel);
                break;

            default:
                ar = View(viewModel);
                break;
            }
            TempData["articlesViewModel"] = viewModel;
            return(ar);
        }