private void addReply() { int mailid = GetFormValue("mailid", 0); int SendType = GetFormValue("sendtype", 0); string content = HttpUtility.UrlDecode(GetFormValue("content", "")); string auth = GetFormValue("auth", ""); string title = HttpUtility.UrlDecode(GetFormValue("title", "")); int userId = 0; if (!string.IsNullOrEmpty(auth)) { userId = UserLogic.GetUserIdByAuthToken(auth); if (userId == 0) { json = JsonHelper.JsonSerializer(new ResultModel(ApiStatusCode.令牌失效)); return; } var user = UserLogic.GetModel(userId); MailModel model = new MailModel(); model.AuthorId = -1; model.AuthorName = user.NickName; model.Title = title; model.BodyContent = content; model.CoverUrl = user.UserHeadImg; model.SendType = SendType; model.ReplyPid = mailid; model.ReplyUserId = userId; model.PhoneModel = HttpUtility.UrlDecode(GetFormValue("pm", "")); if (ArticleLogic.AddMailInfo(model) > 0) { //将该消息接收人的已阅读状态改为未读 LogLogic.UpdateMailNotReadStatus(userId, mailid); json = JsonHelper.JsonSerializer(new ResultModel(ApiStatusCode.OK)); } } else { json = JsonHelper.JsonSerializer(new ResultModel(ApiStatusCode.令牌失效)); } }
public ActionResult create(string title, string content, string ids) { try { var user = GetUserData(); //ArticleModel model = new ArticleModel(); //model.ArticleBody = content; //model.ArticleIntro = title; //model.ArticleTitle = title; //model.ArticleCover = ""; //model.ArticleStatus = 1; //model.AuthorId = user.UserId; //model.AuthorIdentity = user.UserIdentity == 0 ? 4 : 3; //model.AuthorName = user.RealName; //model.EnablePublish = 1; //model.EnableTop = 0; //model.PublishTime = DateTime.Now; //model.TopTime = DateTime.Now; //model.UpdateTime = DateTime.Now; ////如果当前创建资讯的用户身份为盟友,则发送目标为盟主的ID ////如果当前创建资讯的用户身份为盟主时,则发送目标为 2(盟友) //model.SendTargetId = user.UserIdentity == 1 ? 2 : user.BelongOne; string[] TargetIds = null; //如果是盟主身份,则需要判断发送目标 if (user.UserIdentity == 1) { if (string.IsNullOrEmpty(ids)) { return(Json(new ResultModel(ApiStatusCode.缺少发送目标))); } TargetIds = ids.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (TargetIds.Length <= 0) { return(Json(new ResultModel(ApiStatusCode.缺少发送目标))); } } MailModel model = new MailModel(); model.AuthorId = user.UserId; model.AuthorName = user.NickName; model.Title = title; model.BodyContent = content; model.CoverUrl = user.UserHeadImg; model.SendType = ids == "-1" ? 2 : user.UserIdentity == 1 ? 0 : 1; model.ReplyPid = 0; model.ReplyUserId = 0; int articleId = ArticleLogic.AddMailInfo(model); ApiStatusCode apiCode = ApiStatusCode.OK; if (articleId > 0) { ReadLogModel logModel = new ReadLogModel() { ArticleId = articleId, ClientIp = "", cookie = "", IsRead = 0, ReadTime = DateTime.Now }; if (user.UserIdentity == 1) { foreach (var TargetId in TargetIds) { logModel.UserId = Convert.ToInt32(TargetId); //LogLogic.AddReadLog(logModel); LogLogic.AddMailReadLog(logModel); } } else { logModel.UserId = user.BelongOne; LogLogic.AddMailReadLog(logModel); } //将自己也添加进去,这样自己就可以看到自己发布的信息 logModel.UserId = user.UserId; logModel.IsRead = 1; LogLogic.AddMailReadLog(logModel); } else { apiCode = ApiStatusCode.发送失败; } return(Json(new ResultModel(apiCode))); } catch (Exception ex) { LogHelper.Log(string.Format("create:message:{0},StackTrace:{1}", ex.Message, ex.StackTrace), LogHelperTag.ERROR); return(Json(new ResultModel(ApiStatusCode.SERVICEERROR))); } }