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; } }
/// <summary> /// 判断路径是否可用 /// </summary> /// <param name="path">路径</param> /// <returns></returns> public JsonResult IsPathAvailable(string path) { if (string.IsNullOrEmpty(path)) { return(Json(true)); } try { if (!path.EndsWith(".html")) { path = path + ".html"; } var existStatus = _bLLNotice.Exist(n => n.NoticePath.ToLower().Equals(path.ToLower())); if (existStatus) { return(Json(false)); } else { return(Json(true)); } } catch (Exception ex) { Logger.Error(ex); throw; } }