コード例 #1
0
ファイル: MainController.cs プロジェクト: yuzs/SugarSite
        public JsonResult AskSubmit(short fid, string title, string content, string vercode, int rate = 0, int id = 0)
        {
            ResultModel <string> model = new ResultModel <string>();

            _service.Command <MainOutsourcing>((db, o) =>
            {
                Check.Exception(fid == 0 || title.IsNullOrEmpty() || content.IsNullOrEmpty() || vercode.IsNullOrEmpty(), "参数不合法!");
                Check.Exception(title.Length < 5 && content.Length < 20 || content.Length > 1000000, "参数不合法!");
                Check.Exception(base.GetForumsList != null && base.GetForumsList.Any(it => it.Fid == fid).IsFalse(), "参数不合法!");
                var sm          = SessionManager <string> .GetInstance();
                var severCode   = sm[PubConst.SessionVerifyCode];
                model.IsSuccess = false;
                if (vercode != severCode)
                {
                    model.ResultInfo = "验证码错误!";
                }
                else if (IsLogin.IsFalse())
                {
                    model.ResultInfo = "对不起您还没有登录!";
                }
                else
                {
                    try
                    {
                        db.BeginTran();
                        var isAdd = id == 0;
                        if (isAdd)
                        {
                            //插贴子标题
                            BBS_Topics t = o.GetTopics(fid, title, rate, _userInfo);
                            var tid      = db.Insert(t).ObjToInt();
                            t.Tid        = tid;
                            //插贴子主体
                            BBS_Posts p = o.GetPosts(fid, content, _userInfo, t);
                            db.Insert(p);
                        }
                        else
                        {
                            var topics = db.Queryable <BBS_Topics>().InSingle(id);
                            Check.Exception(topics.Posterid != _userInfo.Id && _userInfo.RoleId == PubEnum.RoleType.User.TryToInt(), "您没有权限修改!");
                            db.Update <BBS_Topics>(new { Title = title, Rate = rate, Fid = fid }, it => it.Tid == id);
                            db.Update <BBS_Posts>(new { Title = title, Rate = rate, Fid = fid, Message = content }, it => it.Tid == id && it.Parentid == 0);
                        }
                        db.CommitTran();
                        model.IsSuccess = true;
                        base.RemoveForumsStatisticsCache();//清除统计缓存
                    }
                    catch (Exception ex)
                    {
                        model.ResultInfo = "发布失败!";
                        db.RollbackTran();
                        PubMethod.WirteExp(ex);
                    }
                }
            });
            return(Json(model));
        }
コード例 #2
0
 public BBS_Posts GetPosts(short fid, string content, UserInfo _userInfo, BBS_Topics top)
 {
     return(new BBS_Posts()
     {
         Fid = fid,
         Ip = RequestInfo.UserAddress,
         Posterid = _userInfo.Id,
         Poster = _userInfo.NickName,
         Message = content,
         Postdatetime = DateTime.Now,
         Title = top.Title,
         Tid = top.Tid,
         Lastedit = _userInfo.NickName
     });
 }