public String Message(ForeMessageViewPage MessageAdd, string id, string UserID) { Message MessageInfo = new Message(); var UserInfo = db.UsersInfo.Where(a => a.UserName == UserID).FirstOrDefault(); var MessageInfo1 = db.Message.Where(a => a.UserID == UserInfo.UserID).ToList(); var MessageInfo2 = MessageInfo1.Where(a => a.TradeID == id).ToList(); if (MessageInfo2.Count > 0) { return("已留言,请勿重复留言"); } if (MessageAdd.MessageInfo == null) { return("请填写留言内容"); } string name = "^[a-zA-Z0-9\u4e00-\u9fa5]{1,}$";//字母数字汉字 Regex rxname = new Regex(name); if (!rxname.IsMatch(MessageAdd.MessageInfo)) { return("请输入正确格式"); } MessageInfo.MessageID = DateTime.Now.ToString("yyyyMMddHHmmss"); MessageInfo.UserID = UserInfo.UserID; MessageInfo.TradeID = id; MessageInfo.MessageInfo = MessageAdd.MessageInfo; MessageInfo.MessageTime = DateTime.Now; db.Message.Add(MessageInfo); db.SaveChanges(); return("留言成功"); }
public ActionResult Message(ForeMessageViewPage MessageAdd, string id) { IForeMessage IF = new ForeMessageMethod(); string UserID = "0"; try { UserID = System.Web.HttpContext.Current.Session["UserName"].ToString(); } catch { return(Json("操作时间过长请重新登录")); } return(Json(IF.Message(MessageAdd, id, UserID))); }