Beispiel #1
0
        public IHttpActionResult BuyForum()
        {
            int ForumID = Convert.ToInt32(requestHelper.GetRequsetForm("ForumID", ""));
            int UID     = Convert.ToInt32(requestHelper.GetRequsetForm("UID", ""));

            WebApi_BLL.T_Forum_Buy bll   = new WebApi_BLL.T_Forum_Buy();
            WebApi_BLL.T_Forums    tfbll = new WebApi_BLL.T_Forums();
            WebApi_BLL.T_User      tubll = new WebApi_BLL.T_User();

            WebApi_Model.T_User   u = tubll.GetModel(UID);
            WebApi_Model.T_Forums f = tfbll.GetModel(ForumID);



            if (u == null || f == null)
            {
                return(Ok(ReturnJsonResult.GetJsonResult(-1, "Error", JsonConvert.SerializeObject("用户或贴子不存在"))));
            }

            List <WebApi_Model.T_Forum_Buy> list = bll.GetModelList("UID=" + UID + " and ForumID =" + ForumID);

            if (list.Count > 0)
            {
                return(Ok(ReturnJsonResult.GetJsonResult(1, "OK", JsonConvert.SerializeObject(list[0]))));
            }

            if (u.TuiMao < f.TuiMao || f.TuiMao <= 0)
            {
                return(Ok(ReturnJsonResult.GetJsonResult(-1, "Error", JsonConvert.SerializeObject("无法购买"))));
            }
            else
            {
                u.TuiMao = u.TuiMao - f.TuiMao;
                tubll.Update(u); //扣除腿毛

                #region ==== 作者 + 腿毛 ====
                WebApi_Model.T_User zzmodel = tubll.GetModel((int)f.UID);
                zzmodel.TuiMao += f.TuiMao;
                tubll.Update(zzmodel);
                #endregion

                WebApi_Model.T_Forum_Buy model = new WebApi_Model.T_Forum_Buy();
                model.BuyDate = DateTime.Now;
                model.UID     = UID;
                model.ForumID = ForumID;
                int key = bll.Add(model);
                model.BuyID = key;
                return(Ok(ReturnJsonResult.GetJsonResult(1, "OK", JsonConvert.SerializeObject(model))));
            }
        }
Beispiel #2
0
        public IHttpActionResult ViewForum(int ForumID, int UID)
        {
            WebApi_BLL.T_Forums bll = new WebApi_BLL.T_Forums();
            //WebApi_BLL.T_User_BaseInfo tubll = new WebApi_BLL.T_User_BaseInfo();
            WebApi_BLL.T_Forum_Photo   tfpbll = new WebApi_BLL.T_Forum_Photo();
            WebApi_BLL.T_Forum_Comment tfcbll = new WebApi_BLL.T_Forum_Comment();
            WebApi_BLL.T_Forum_Buy     tfbbll = new WebApi_BLL.T_Forum_Buy();
            WebApi_BLL.T_User_BaseInfo tubll  = new WebApi_BLL.T_User_BaseInfo();

            WebApi_Model.T_Forums forumModle = bll.GetModel(ForumID);

            forumModle.UserBaseInfo = tubll.GetModel((int)forumModle.UID);
            //WebApi_Model.T_User_BaseInfo userModel = tubll.GetModel(UID);
            //forumModle.User = userModel;
            forumModle.Views += 1; //查看数+1
            bll.Update(forumModle);
            forumModle.Forum_Photo   = tfpbll.GetModelList("ForumID =" + ForumID);
            forumModle.Forum_Comment = tfcbll.GetModelList("ForumID = " + ForumID);
            forumModle.Forum_Buy     = tfbbll.GetModelList("ForumID=" + ForumID + " and UID = " + UID);

            return(Ok(ReturnJsonResult.GetJsonResult(1, "OK", JsonConvert.SerializeObject(forumModle))));
        }