public IHttpActionResult PostNewFourm(dynamic model) { try { WebApi_BLL.T_Forums bll = new WebApi_BLL.T_Forums(); WebApi_Model.T_Forums forum = (WebApi_Model.T_Forums)Newtonsoft.Json.JsonConvert.DeserializeObject(model, typeof(WebApi_Model.T_Forums)); if (forum.TuiMao != 0 && forum.Forum_Photo.Count == 0) { return(Ok(ReturnJsonResult.GetJsonResult(1, "OK", JsonConvert.SerializeObject("图集为空")))); } forum.Status = 0; forum.Flag = 0; forum.PostTime = DateTime.Now; forum.Views = 0; forum.Likes = 0; forum.CommentCount = 0; int key = bll.Add(forum); forum.ForumID = key; return(Ok(ReturnJsonResult.GetJsonResult(1, "OK", JsonConvert.SerializeObject(forum)))); } catch (Exception ex) { return(Ok(ReturnJsonResult.GetJsonResult(1, "OK", JsonConvert.SerializeObject(ex.Message)))); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebApi_Model.T_Forums GetModel(int ForumID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ForumID,UID,Title,FromIP,FromDevice,CategoryID,Content,ContentHeight,PostTime,Status,CoverPhoto,TuiMao,Flag,ProductID,Star,Views,Likes,CommentCount from T_Forums "); strSql.Append(" where ForumID=@ForumID"); SqlParameter[] parameters = { new SqlParameter("@ForumID", SqlDbType.Int, 4) }; parameters[0].Value = ForumID; WebApi_Model.T_Forums model = new WebApi_Model.T_Forums(); DataSet ds = DBHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
public IHttpActionResult LikeForum() { int ForumID = Convert.ToInt32(requestHelper.GetRequsetForm("ForumID", "")); WebApi_BLL.T_Forums bll = new WebApi_BLL.T_Forums(); WebApi_Model.T_Forums model = bll.GetModel(ForumID); model.Likes += 1; return(Ok(ReturnJsonResult.GetJsonResult(1, "OK", JsonConvert.SerializeObject(bll.Update(model))))); }
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)))); } }
public IHttpActionResult PostComment(dynamic model) { WebApi_Model.T_Forum_Comment comment = (WebApi_Model.T_Forum_Comment)Newtonsoft.Json.JsonConvert.DeserializeObject(model, typeof(WebApi_Model.T_Forum_Comment)); WebApi_BLL.T_Forum_Comment bll = new WebApi_BLL.T_Forum_Comment(); WebApi_BLL.T_Forums tfsbll = new WebApi_BLL.T_Forums(); comment.CommentDate = DateTime.Now; comment.Status = 0; bll.Add(comment); //更新评论数 WebApi_Model.T_Forums forum = new WebApi_Model.T_Forums(); forum = tfsbll.GetModel((int)comment.ForumID); forum.CommentCount += 1; tfsbll.Update(forum); #region update giftcount DBHelper.GetSingle("update T_Forum_Comment set giftcount = (select giftcount from V_Forum_Gift where ForumID = " + comment.ForumID + " and PostUID = " + comment.UID + ")"); #endregion return(Ok(ReturnJsonResult.GetJsonResult(1, "OK", JsonConvert.SerializeObject(comment)))); }
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)))); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebApi_Model.T_Forums model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_Forums set "); strSql.Append("UID=@UID,"); strSql.Append("Title=@Title,"); strSql.Append("FromIP=@FromIP,"); strSql.Append("FromDevice=@FromDevice,"); strSql.Append("CategoryID=@CategoryID,"); strSql.Append("Content=@Content,"); strSql.Append("ContentHeight=@ContentHeight,"); strSql.Append("PostTime=@PostTime,"); strSql.Append("Status=@Status,"); strSql.Append("CoverPhoto=@CoverPhoto,"); strSql.Append("TuiMao=@TuiMao,"); strSql.Append("Flag=@Flag,"); strSql.Append("ProductID=@ProductID,"); strSql.Append("Star=@Star,"); strSql.Append("Views=@Views,"); strSql.Append("Likes=@Likes,"); strSql.Append("CommentCount=@CommentCount"); strSql.Append(" where ForumID=@ForumID"); SqlParameter[] parameters = { new SqlParameter("@UID", SqlDbType.Int, 4), new SqlParameter("@Title", SqlDbType.NVarChar, 50), new SqlParameter("@FromIP", SqlDbType.NVarChar, 50), new SqlParameter("@FromDevice", SqlDbType.NVarChar, 50), new SqlParameter("@CategoryID", SqlDbType.Int, 4), new SqlParameter("@Content", SqlDbType.NVarChar, 4000), new SqlParameter("@ContentHeight", SqlDbType.Int, 4), new SqlParameter("@PostTime", SqlDbType.DateTime), new SqlParameter("@Status", SqlDbType.Int, 4), new SqlParameter("@CoverPhoto", SqlDbType.NVarChar, 50), new SqlParameter("@TuiMao", SqlDbType.Int, 4), new SqlParameter("@Flag", SqlDbType.Int, 4), new SqlParameter("@ProductID", SqlDbType.Int, 4), new SqlParameter("@Star", SqlDbType.Int, 4), new SqlParameter("@Views", SqlDbType.Int, 4), new SqlParameter("@Likes", SqlDbType.Int, 4), new SqlParameter("@CommentCount", SqlDbType.Int, 4), new SqlParameter("@ForumID", SqlDbType.Int, 4) }; parameters[0].Value = model.UID; parameters[1].Value = model.Title; parameters[2].Value = model.FromIP; parameters[3].Value = model.FromDevice; parameters[4].Value = model.CategoryID; parameters[5].Value = model.Content; parameters[6].Value = model.ContentHeight; parameters[7].Value = model.PostTime; parameters[8].Value = model.Status; parameters[9].Value = model.CoverPhoto; parameters[10].Value = model.TuiMao; parameters[11].Value = model.Flag; parameters[12].Value = model.ProductID; parameters[13].Value = model.Star; parameters[14].Value = model.Views; parameters[15].Value = model.Likes; parameters[16].Value = model.CommentCount; parameters[17].Value = model.ForumID; int rows = DBHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebApi_Model.T_Forums DataRowToModel(DataRow row) { WebApi_Model.T_Forums model = new WebApi_Model.T_Forums(); if (row != null) { if (row["ForumID"] != null && row["ForumID"].ToString() != "") { model.ForumID = int.Parse(row["ForumID"].ToString()); } if (row["UID"] != null && row["UID"].ToString() != "") { model.UID = int.Parse(row["UID"].ToString()); } if (row["Title"] != null) { model.Title = row["Title"].ToString(); } if (row["FromIP"] != null) { model.FromIP = row["FromIP"].ToString(); } if (row["FromDevice"] != null) { model.FromDevice = row["FromDevice"].ToString(); } if (row["CategoryID"] != null && row["CategoryID"].ToString() != "") { model.CategoryID = int.Parse(row["CategoryID"].ToString()); } if (row["Content"] != null) { model.Content = row["Content"].ToString(); } if (row["ContentHeight"] != null && row["ContentHeight"].ToString() != "") { model.ContentHeight = int.Parse(row["ContentHeight"].ToString()); } if (row["PostTime"] != null && row["PostTime"].ToString() != "") { model.PostTime = DateTime.Parse(row["PostTime"].ToString()); } if (row["Status"] != null && row["Status"].ToString() != "") { model.Status = int.Parse(row["Status"].ToString()); } if (row["CoverPhoto"] != null) { model.CoverPhoto = row["CoverPhoto"].ToString(); } if (row["TuiMao"] != null && row["TuiMao"].ToString() != "") { model.TuiMao = int.Parse(row["TuiMao"].ToString()); } if (row["Flag"] != null && row["Flag"].ToString() != "") { model.Flag = int.Parse(row["Flag"].ToString()); } if (row["ProductID"] != null && row["ProductID"].ToString() != "") { model.ProductID = int.Parse(row["ProductID"].ToString()); } if (row["Star"] != null && row["Star"].ToString() != "") { model.Star = int.Parse(row["Star"].ToString()); } if (row["Views"] != null && row["Views"].ToString() != "") { model.Views = int.Parse(row["Views"].ToString()); } if (row["Likes"] != null && row["Likes"].ToString() != "") { model.Likes = int.Parse(row["Likes"].ToString()); } if (row["CommentCount"] != null && row["CommentCount"].ToString() != "") { model.CommentCount = int.Parse(row["CommentCount"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(WebApi_Model.T_Forums model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_Forums("); strSql.Append("UID,Title,FromIP,FromDevice,CategoryID,Content,ContentHeight,PostTime,Status,CoverPhoto,TuiMao,Flag,ProductID,Star,Views,Likes,CommentCount)"); strSql.Append(" values ("); strSql.Append("@UID,@Title,@FromIP,@FromDevice,@CategoryID,@Content,@ContentHeight,@PostTime,@Status,@CoverPhoto,@TuiMao,@Flag,@ProductID,@Star,@Views,@Likes,@CommentCount)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UID", SqlDbType.Int, 4), new SqlParameter("@Title", SqlDbType.NVarChar, 50), new SqlParameter("@FromIP", SqlDbType.NVarChar, 50), new SqlParameter("@FromDevice", SqlDbType.NVarChar, 50), new SqlParameter("@CategoryID", SqlDbType.Int, 4), new SqlParameter("@Content", SqlDbType.NVarChar, 4000), new SqlParameter("@ContentHeight", SqlDbType.Int, 4), new SqlParameter("@PostTime", SqlDbType.DateTime), new SqlParameter("@Status", SqlDbType.Int, 4), new SqlParameter("@CoverPhoto", SqlDbType.NVarChar, 50), new SqlParameter("@TuiMao", SqlDbType.Int, 4), new SqlParameter("@Flag", SqlDbType.Int, 4), new SqlParameter("@ProductID", SqlDbType.Int, 4), new SqlParameter("@Star", SqlDbType.Int, 4), new SqlParameter("@Views", SqlDbType.Int, 4), new SqlParameter("@Likes", SqlDbType.Int, 4), new SqlParameter("@CommentCount", SqlDbType.Int, 4) }; parameters[0].Value = model.UID; parameters[1].Value = model.Title; parameters[2].Value = model.FromIP; parameters[3].Value = model.FromDevice; parameters[4].Value = model.CategoryID; parameters[5].Value = model.Content; parameters[6].Value = model.ContentHeight; parameters[7].Value = model.PostTime; parameters[8].Value = model.Status; parameters[9].Value = model.CoverPhoto; parameters[10].Value = model.TuiMao; parameters[11].Value = model.Flag; parameters[12].Value = model.ProductID; parameters[13].Value = model.Star; parameters[14].Value = model.Views; parameters[15].Value = model.Likes; parameters[16].Value = model.CommentCount; object obj = DBHelper.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { int key = Convert.ToInt32(obj); if (model.Forum_Photo.Count > 0) { T_Forum_Photo tfp = new T_Forum_Photo(); foreach (WebApi_Model.T_Forum_Photo m in model.Forum_Photo) { m.ForumID = key; tfp.Update(m); } } return(key); } }
public IHttpActionResult GetUpdateFourm(int ForumID) { WebApi_BLL.T_Forums bll = new WebApi_BLL.T_Forums(); WebApi_Model.T_Forums model = bll.GetModel(ForumID); return(Ok(ReturnJsonResult.GetJsonResult(1, "OK", JsonConvert.SerializeObject(model)))); }