protected string addProjectVersionArticle(projectVersionEditViewModel viewModel, SASDdbContext db) { string ret; tblArticle ta = new tblArticle(db); tblProject tp = new tblProject(); string projectName = tp.nameById(viewModel.editModel.projectId.ToString()); article prjArticle = ta.GetByProjectId(viewModel.editModel.projectId.ToString()); article pva = new article(); pva.articleId = (Guid)viewModel.editModel.versionArticleId; pva.createtime = DateTime.Now; pva.articleTitle = $"project {projectName} version " + $"{viewModel.editModel.version}"; pva.articleHtmlContent = string.Format(@" <h1>{0} version {1}</h1> <p>{2}</p> ", projectName, viewModel.editModel.version, viewModel.editModel.versionDescription); pva.articleContent = string.Format("{0} {1} {2}" , projectName, viewModel.editModel.version , viewModel.editModel.versionDescription); pva.isDir = true; pva.belongToArticleDirId = prjArticle.articleId; pva.articleType = ARTICLE_TYPE.Project.ToString(); pva.articleStatus = ARTICLE_STATUS.New.ToString(); pva.priority = 1; pva.projectId = viewModel.editModel.projectId; ret = ta.Add(pva); ret += ta.SaveChanges(); return(ret); }
protected string addProjectArticle(projectEditViewModel viewModel , SASDdbContext db) { string ret; tblArticle ta = new tblArticle(db); article pa = new article(); pa.articleId = (Guid)viewModel.editModel.projectArticleId;// Guid.NewGuid(); pa.createtime = DateTime.Now; pa.articleTitle = viewModel.editModel.projectName; pa.articleHtmlContent = string.Format(@" <h1>{0}</h1> <p>{1}</p> ", viewModel.editModel.projectName, viewModel.editModel.projectDescription); pa.articleContent = string.Format("{0} {1}" , viewModel.editModel.projectName , viewModel.editModel.projectDescription); pa.isDir = true; pa.articleType = ARTICLE_TYPE.Project.ToString(); pa.articleStatus = ARTICLE_STATUS.New.ToString(); pa.priority = 1; pa.projectId = viewModel.editModel.projectId; ret = ta.Add(pa); ret += ta.SaveChanges(); return(ret); }
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); }
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); }
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); }