public ActionResult DeleteArticle(BlogArticleQueryViewModel viewModel) { ViewBag.ViewModel = viewModel; if (viewModel.KeyID != null) { viewModel.DocID = viewModel.DecryptKeyValue(); } var item = models.GetTable <BlogArticle>().Where(a => a.DocID == viewModel.DocID).FirstOrDefault(); if (item == null) { return(Json(new { result = false, message = "資料錯誤" })); } models.ExecuteCommand("delete Document where DocID = {0}", item.DocID); String blogRoot = Server.MapPath("~/MainActivity/Blog"); String blogPath = Path.Combine(blogRoot, item.BlogID); if (Directory.Exists(blogPath)) { Directory.Delete(blogPath, true); } return(Json(new { result = true })); }
public ActionResult BlogArticleList(BlogArticleQueryViewModel viewModel) { ViewBag.ViewModel = viewModel; var items = models.GetTable <BlogArticle>() .Where(b => b.BlogTag.Any(c => c.CategoryID == viewModel.CategoryID)); return(View(items)); }
public ActionResult CommitArticleContent(BlogArticleQueryViewModel viewModel) { ViewBag.ViewModel = viewModel; viewModel.KeyID = viewModel.KeyID.GetEfficientString(); if (viewModel.KeyID != null) { viewModel.DocID = viewModel.DecryptKeyValue(); } var item = models.GetTable <BlogArticle>().Where(a => a.DocID == viewModel.DocID).FirstOrDefault(); if (item == null) { return(Json(new { result = false, message = "請先建立文章資料" })); } String blogRoot = Server.MapPath("~/MainActivity/Blog"); String blogPath = Path.Combine(blogRoot, item.BlogID); blogPath.CheckStoredPath(); if (Request.Files.Count == 0) { return(Json(new { result = false, message = "請上傳文章內容" })); } var file = Request.Files[0]; try { using (ZipArchive zip = new ZipArchive(file.InputStream)) { foreach (var entry in zip.Entries) { var destName = Path.Combine(blogPath, entry.FullName); if (String.IsNullOrEmpty(entry.Name)) { destName.CheckStoredPath(); } else { entry.ExtractToFile(destName, true); } } //zip.ExtractToDirectory(blogPath); } return(Json(new { result = true, item.DocID, item.BlogID })); } catch (Exception ex) { Logger.Error(ex); return(Json(new { result = false, message = $"上傳失敗:{ex.Message}" })); } }
public ActionResult BlogSingle(BlogArticleQueryViewModel viewModel) { ViewBag.ViewModel = viewModel; if (viewModel.KeyID != null) { viewModel.DocID = viewModel.DecryptKeyValue(); } if (!viewModel.DocID.HasValue) { if (Request.QueryString.HasValue) { int fbclid = Request.QueryString.Value.IndexOf("&fbclid"); ViewBag.ViewModel = viewModel = JsonConvert.DeserializeObject <BlogArticleQueryViewModel>( fbclid > 0 ? Request.QueryString.Value[1..fbclid].UrlDecodeBase64String().DecryptKey()
public ActionResult BlogSingle(BlogArticleQueryViewModel viewModel) { ViewBag.ViewModel = viewModel; if (viewModel.KeyID != null) { viewModel.DocID = viewModel.DecryptKeyValue(); } if (Request.QueryString.Keys.Count > 0 && Request.QueryString.Keys[0] == null) { ViewBag.ViewModel = viewModel = JsonConvert.DeserializeObject <BlogArticleQueryViewModel>(Request.QueryString[0].DecryptKey()); } var item = models.GetTable <BlogArticle>().Where(b => b.DocID == viewModel.DocID).FirstOrDefault(); if (item == null) { return(View("Index")); } return(View(item)); }
public ActionResult CommitArticle(BlogArticleQueryViewModel viewModel) { ViewBag.ViewModel = viewModel; if (viewModel.KeyID != null) { viewModel.DocID = viewModel.DecryptKeyValue(); } viewModel.Title = viewModel.Title.GetEfficientString(); if (viewModel.Title == null) { ModelState.AddModelError("Title", "請輸入撰稿標題"); } if (!viewModel.AuthorID.HasValue) { ModelState.AddModelError("AuthorName", "請選擇撰稿人員"); } String blogID = null; if (!viewModel.DocDate.HasValue) { ModelState.AddModelError("DocDate", "請選擇發佈時間"); } else { blogID = $"{viewModel.DocDate:yyyyMMdd}"; var duplicated = viewModel.DocID.HasValue ? models.GetTable <BlogArticle>().Any(b => b.DocID != viewModel.DocID && b.BlogID == blogID) : models.GetTable <BlogArticle>().Any(b => b.BlogID == blogID); if (duplicated) { ModelState.AddModelError("DocDate", "該時間已有其它文章發佈"); } } if (viewModel.TagID == null || !viewModel.TagID.Any(i => i.HasValue)) { ModelState.AddModelError("Category", "請選擇文章類別"); } else { viewModel.TagID = viewModel.TagID.Where(i => i.HasValue).ToArray(); } String blogRoot = Server.MapPath("~/MainActivity/Blog"); String blogPath = Path.Combine(blogRoot, blogID); if (Directory.Exists(blogPath)) { ModelState.AddModelError("DocDate", "該時間指定的資料夾路徑已存在"); } if (!ModelState.IsValid) { ViewBag.ModelState = ModelState; return(View(ConsoleHomeController.InputErrorView)); } var item = models.GetTable <BlogArticle>().Where(a => a.DocID == viewModel.DocID).FirstOrDefault(); String sourceBlogID = null; if (item == null) { item = new BlogArticle { Document = new Document { DocDate = DateTime.Now, DocType = (int)Naming.DocumentTypeDefinition.Knowledge }, }; models.GetTable <BlogArticle>().InsertOnSubmit(item); } else { sourceBlogID = item.BlogID; } item.AuthorID = viewModel.AuthorID; item.Title = viewModel.Title; item.Subtitle = viewModel.Subtitle.GetEfficientString(); item.Document.DocDate = viewModel.DocDate.Value; item.BlogID = blogID; models.SubmitChanges(); models.ExecuteCommand("delete BlogTag where DocID = {0}", item.DocID); foreach (var categoryID in viewModel.TagID) { models.ExecuteCommand("insert BlogTag (DocID,CategoryID) values ({0},{1})", item.DocID, categoryID); } //blogPath.CheckStoredPath(); if (sourceBlogID != null && sourceBlogID != blogID) { String sourcePath = Path.Combine(blogRoot, sourceBlogID); if (Directory.Exists(sourcePath)) { Directory.Move(sourcePath, blogPath); } } return(Json(new { result = true, item.DocID, item.BlogID })); }