public ActionResult Create([FromForm] NoticeViewModel model) { if (!ModelState.IsValid) { return(View(model)); } try { //notice var n = new Notice() { NoticeId = Guid.NewGuid(), CheckStatus = true, //默认审核通过 NoticeContent = model.Content, NoticeTitle = model.Title, NoticeCustomPath = model.CustomPath, NoticePublisher = UserName, NoticePublishTime = DateTime.UtcNow, UpdateBy = UserName, UpdateTime = DateTime.UtcNow }; // if (!string.IsNullOrEmpty(n.NoticeCustomPath)) { if (n.NoticeCustomPath.EndsWith(".html")) { n.NoticeCustomPath = n.NoticeCustomPath.Substring(0, n.NoticeCustomPath.Length - 5); // trim end ".html" } } else { n.NoticeCustomPath = DateTime.UtcNow.ToString("yyyyMMddHHmmss"); } var existStatus = _bLLNotice.Exist(nx => nx.NoticeCustomPath.ToLower().Equals(n.NoticeCustomPath.ToLower())); if (existStatus) { n.NoticeCustomPath = DateTime.UtcNow.ToString("yyyyMMddHHmmss"); } n.NoticePath = $"{n.NoticeCustomPath}.html"; var c = _bLLNotice.Insert(n); if (c == 1) { OperLogHelper.AddOperLog($"{UserName}添加新公告,{n.NoticeTitle},ID:{n.NoticeId:N}", OperLogModule.Notice, UserName); return(RedirectToAction("Index")); } else { return(View(model)); } } catch (Exception ex) { Logger.Error(ex); throw; } }
// [ValidateInput(false)] public ActionResult Create(NoticeViewModel model) { if (!ModelState.IsValid) { return(View()); } try { //notice var n = new Notice() { NoticeId = Guid.NewGuid(), CheckStatus = true, //默认审核通过 NoticeContent = model.Content, NoticeTitle = model.Title, NoticeCustomPath = model.CustomPath, NoticePublisher = Username, NoticePublishTime = DateTime.Now, UpdateBy = Username, UpdateTime = DateTime.Now }; // if (!string.IsNullOrEmpty(n.NoticeCustomPath)) { if (n.NoticeCustomPath.EndsWith(".html")) { n.NoticePath = n.NoticeCustomPath; } else { n.NoticePath = n.NoticeCustomPath + ".html"; } } else { n.NoticePath = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html"; } var c = _bLLNotice.Insert(n); if (c == 1) { OperLogHelper.AddOperLog($"{Username}添加新公告,{n.NoticeTitle},ID:{n.NoticeId:N}", OperLogModule.Notice, Username); return(RedirectToAction("Index")); } else { return(View()); } } catch (Exception ex) { Logger.Error(ex); throw; } }