public ActionResult Delete(int id) { var post = MiscBll.GetById(id); if (post is null) { return(ResultData(null, false, "杂项页已经被删除!")); } var mc = post.Content.MatchImgTags(); foreach (Match m in mc) { string path = m.Groups[3].Value; if (path.StartsWith("/")) { path = Path.Combine(Server.MapPath("/"), path); try { System.IO.File.Delete(path); } catch (IOException) { } } } bool b = MiscBll.DeleteByIdSaved(id); return(ResultData(null, b, b ? "删除成功" : "删除失败")); }
public ActionResult Delete(int id) { var post = MiscBll.GetById(id); if (post is null) { return(ResultData(null, false, "杂项页已经被删除!")); } var srcs = post.Content.MatchImgSrcs(); foreach (var path in srcs) { if (path.StartsWith("/")) { try { System.IO.File.Delete(Path.Combine(Server.MapPath("/"), path)); } catch (IOException) { } } } bool b = MiscBll.DeleteByIdSaved(id); return(ResultData(null, b, b ? "删除成功" : "删除失败")); }
public ActionResult Index(int id) { Misc misc = MiscBll.GetById(id); if (misc is null) { return(RedirectToAction("Index", "Error")); } return(View(misc)); }
public ActionResult Write(Misc model) { model.Content = CommonHelper.ReplaceImgSrc(Regex.Replace(model.Content?.Trim(), @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>")).Replace("/thumb150/", "/large/"); var e = MiscBll.AddEntitySaved(model); if (e != null) { return(ResultData(null, message: "发布成功")); } return(ResultData(null, false, "发布失败")); }
public ActionResult Edit(Misc misc) { var entity = MiscBll.GetById(misc.Id); entity.ModifyDate = DateTime.Now; entity.Title = misc.Title; entity.Content = CommonHelper.ReplaceImgSrc(Regex.Replace(misc.Content, @"<img\s+[^>]*\s*src\s*=\s*['""]?(\S+\.\w{3,4})['""]?[^/>]*/>", "<img src=\"$1\"/>")).Replace("/thumb150/", "/large/"); bool b = MiscBll.UpdateEntitySaved(entity); return(ResultData(null, b, b ? "修改成功" : "修改失败")); }
public ActionResult GetPageData(int page = 1, int size = 10) { var list = MiscBll.LoadPageEntitiesNoTracking(page, size, out int total, n => true, n => n.ModifyDate, false).Select(m => new { m.Id, m.Title, m.ModifyDate, m.PostDate }).ToList(); var pageCount = Math.Ceiling(total * 1.0 / size).ToInt32(); return(PageResult(list, pageCount, total)); }
public ActionResult Get(int id) { var notice = MiscBll.GetById(id); return(ResultData(notice.MapTo <MiscOutputDto>())); }