Example #1
0
        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)));
            }
        }