示例#1
0
        public ActionResult EditArticle()//string isDir)
        {
            articleEditViewModel viewModel;
            var tmpvar = TempData["articleEditViewModel"];

            if (tmpvar != null)
            {
                viewModel = (articleEditViewModel)tmpvar;
            }
            else
            {
                viewModel = new articleEditViewModel();
                viewModel.editModel.priority = 5;
            }
            //if (!string.IsNullOrWhiteSpace(isDir) && isDir == "1")
            //    viewModel.isDir = 1;
            //else
            //    viewModel.isDir = 0;
            //ViewBag.isDir = viewModel.isDir;
            if (viewModel.editModel.belongToArticleDirId == null)
            {
                viewModel.parentDirTitle = EMPTY_PARENT_TITLE;
            }
            // if editing, article/directory cannot be changed
            ViewBag.articleTypeOption     = SAdropdownOptions.articleTypeOption();
            ViewBag.articleStatusOption   = SAdropdownOptions.articleStatusOption();
            ViewBag.articlePriorityOption = SAdropdownOptions.articlePriorityOption();
            ViewBag.userList = PMdropdownOption.userList();
            TempData["articleEditViewModel"] = viewModel;
            return(View(viewModel));
        }
示例#2
0
        public ActionResult AddUpdateProject()
        {
            projectEditViewModel viewModel;
            var tmpVM = TempData["projectEditViewModel"];

            if (tmpVM == null)
            {
                viewModel = new projectEditViewModel();
            }
            else
            {
                viewModel = (projectEditViewModel)tmpVM;
            }
            ViewBag.userList = PMdropdownOption.userList();
            return(View(viewModel));
        }
示例#3
0
        public ActionResult AddUpdateProject(projectEditViewModel viewModel)
        {
            ActionResult ar;

            ViewBag.userList = PMdropdownOption.userList();
            string err;

            viewModel.clearMsg();
            switch (viewModel.cmd)
            {
            case "save":
                err = checkForm(viewModel);
                if (err.Length > 0)
                {
                    viewModel.errorMsg = err;
                    ar = View(viewModel);
                    break;
                }
                tblProject tp = new tblProject();
                if (viewModel.pageStatus == (int)PAGE_STATUS.ADD)
                {
                    viewModel.editModel.projectId  = Guid.NewGuid();
                    viewModel.editModel.createtime = DateTime.Now;
                    viewModel.editModel.projectArticleId
                        = Guid.NewGuid();
                    using (var trans = tp.BeginTransaction())
                    {
                        err += tp.Add(viewModel.editModel);
                        err += tp.SaveChanges();
                        err += addProjectArticle(viewModel, tp.GetDbContext());
                        if (err.Length > 0)
                        {
                            trans.Rollback();
                        }
                        else
                        {
                            trans.Commit();
                        }
                        // new project add an article at the root as a directory, article type project
                    }
                    if (err.Length == 0)
                    {
                        viewModel.successMsg = "new project saved";
                        viewModel.pageStatus = (int)PAGE_STATUS.ADDSAVED;
                    }
                    else
                    {
                        viewModel.errorMsg = err;
                    }
                }
                else if (viewModel.pageStatus == (int)PAGE_STATUS.EDIT)
                {
                    err += tp.Update(viewModel.editModel);
                    err += tp.SaveChanges();
                    if (err.Length == 0)
                    {
                        viewModel.successMsg = "project updated";
                        viewModel.pageStatus = (int)PAGE_STATUS.SAVED;
                    }
                    else
                    {
                        viewModel.errorMsg = err;
                    }
                }
                else
                {
                    viewModel.errorMsg = "wrong page status " + viewModel.pageStatus;
                }
                ar = View(viewModel);
                break;

            case "addNew":
                projectEditViewModel tmpVMa = new projectEditViewModel();
                tmpVMa.pageStatus = (int)PAGE_STATUS.ADD;
                TempData["projectEditViewModel"] = tmpVMa;
                ar = RedirectToAction("AddUpdateProject");
                return(ar);

            case "query":
                ar = RedirectToAction("Index");
                return(ar);

            default:
                ar = View(viewModel);
                break;
            }
            return(ar);
        }
示例#4
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);
        }