public ActionResult Delete(int id) { var post = NoticeService.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(HostingEnvironment.WebRootPath + path); } catch { } } } bool b = NoticeService.DeleteByIdSaved(id); return(ResultData(null, b, b ? "删除成功" : "删除失败")); }
public ActionResult Index(int page = 1, int size = 10, int id = 0) { UserInfoOutputDto user = HttpContext.Session.Get <UserInfoOutputDto>(SessionKey.UserInfo); List <NoticeOutputDto> list; int total; if (user != null && user.IsAdmin) { if (id != 0) { Notice notice = NoticeService.GetById(id); ViewBag.Total = 1; return(View("Index_Admin", new List <NoticeOutputDto> { notice.MapTo <NoticeOutputDto>() })); } list = NoticeService.LoadPageEntities <DateTime, NoticeOutputDto>(page, size, out total, n => n.Status == Status.Display, n => n.ModifyDate, false).ToList(); ViewBag.Total = total; return(View("Index_Admin", list)); } list = NoticeService.LoadPageEntities <DateTime, NoticeOutputDto>(page, size, out total, n => n.Status == Status.Display, n => n.ModifyDate, false).ToList(); ViewBag.Total = total; return(View(list)); }
public ActionResult Details(int id) { Notice notice = NoticeService.GetById(id); if (notice != null) { return(View(notice)); } return(RedirectToAction("Index")); }
/// <summary> /// 公告详情 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Get(int id) { Notice notice = NoticeService.GetById(id); if (HttpContext.Session.Get("notice" + id) is null) { notice.ViewCount++; NoticeService.UpdateEntitySaved(notice); HttpContext.Session.Set("notice" + id, id.GetBytes()); } return(ResultData(notice.MapTo <NoticeOutputDto>())); }
public async Task <ActionResult> Edit(Notice notice) { Notice entity = NoticeService.GetById(notice.Id); entity.ModifyDate = DateTime.Now; entity.Title = notice.Title; entity.Content = await _imagebedClient.ReplaceImgSrc(notice.Content.ClearImgAttributes()); bool b = NoticeService.UpdateEntitySaved(entity); return(ResultData(null, b, b ? "修改成功" : "修改失败")); }
public async Task <ActionResult> Edit(Notice notice) { var entity = NoticeService.GetById(notice.Id) ?? throw new NotFoundException("公告已经被删除!"); entity.ModifyDate = DateTime.Now; entity.Title = notice.Title; entity.Content = await ImagebedClient.ReplaceImgSrc(notice.Content.ClearImgAttributes()); bool b = NoticeService.SaveChanges() > 0; return(ResultData(null, b, b ? "修改成功" : "修改失败")); }
public ActionResult Details(int id) { var notice = NoticeService.GetById(id) ?? throw new NotFoundException("页面未找到"); if (!HttpContext.Session.TryGetValue("notice" + id, out _)) { notice.ViewCount += 1; NoticeService.SaveChanges(); HttpContext.Session.Set("notice" + id, notice.Title); } return(View(notice)); }
public ActionResult Details(int id) { var notice = NoticeService.GetById(id) ?? throw new NotFoundException("页面未找到"); notice.ModifyDate = notice.ModifyDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone)); notice.PostDate = notice.PostDate.ToTimeZone(HttpContext.Session.Get <string>(SessionKey.TimeZone)); if (!HttpContext.Session.TryGetValue("notice" + id, out _)) { notice.ViewCount += 1; NoticeService.SaveChanges(); HttpContext.Session.Set("notice" + id, notice.Title); } return(View(notice)); }
/// <summary> /// 公告详情 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Get(int id) { if (HttpContext.Session.Get("notice" + id) != null) { return(ResultData(HttpContext.Session.Get <NoticeOutputDto>("notice" + id))); } var notice = NoticeService.GetById(id); notice.ViewCount += 1; NoticeService.SaveChanges(); var dto = notice.MapTo <NoticeOutputDto>(); HttpContext.Session.Set("notice" + id, dto); return(ResultData(dto)); }
public ActionResult Delete(int id) { var notice = NoticeService.GetById(id) ?? throw new NotFoundException("公告已经被删除!"); var srcs = notice.Content.MatchImgSrcs().Where(s => s.StartsWith("/")); foreach (var path in srcs) { try { System.IO.File.Delete(HostEnvironment.WebRootPath + path); } catch { } } bool b = NoticeService.DeleteByIdSaved(id); return(ResultData(null, b, b ? "删除成功" : "删除失败")); }
public ActionResult Index(int page = 1, int size = 10, int id = 0) { var list = NoticeService.GetPages <DateTime, NoticeOutputDto>(page, size, out var total, n => n.Status == Status.Display, n => n.ModifyDate, false).ToList(); ViewBag.Total = total; if (!CurrentUser.IsAdmin) { return(View(list)); } if (id == 0) { return(View("Index_Admin", list)); } var notice = NoticeService.GetById(id); ViewBag.Total = 1; return(View("Index_Admin", new List <NoticeOutputDto> { notice.MapTo <NoticeOutputDto>() })); }
public ActionResult Details(int id) { var notice = NoticeService.GetById(id) ?? throw new NotFoundException("页面未找到"); return(View(notice)); }