// POST api/<controller> public HttpResponseMessage Post([FromBody] shareModel model) { try { int UserId = 0; var identity = (ClaimsIdentity)User.Identity; var claims = identity.Claims.Select(x => new { type = x.Type, value = x.Value }); if (claims != null) { var UserIdStr = claims.Where(a => a.type == "UserId").Select(a => a.value).SingleOrDefault(); var userIdv = UserIdStr != null?UserIdStr.ToString() : "0"; UserId = Convert.ToInt32(userIdv); } model.UserId = UserId; SharesModel returnmodel = IService.PostShares(model); return(Request.CreateResponse(HttpStatusCode.OK, returnmodel)); } catch (Exception ex) { ResponseObject response = new ResponseObject(); response.ExceptionMsg = ex.InnerException != null?ex.InnerException.ToString() : ex.Message; response.ResponseMsg = "Could not Post the share"; response.ErrorCode = HttpStatusCode.InternalServerError.ToString(); return(Request.CreateResponse(HttpStatusCode.InternalServerError, response)); } }
/// <summary> /// 获取我爱分享网详情 /// </summary> /// <param name="articleID"></param> /// <returns></returns> public shareModel GetshareDetail(Guid articleID) { string strSql = string.Format("SELECT *,(SELECT CustomerName FROM dbo.Customer c WHERE c.CustomerID=a.CustomerID) as CustomerName,(SELECT count(1) FROM [ArticleLike] l WHERE l.ArticleID=a.ArticleID) as LikeCount,(SELECT count(1) FROM [ArticleComment] c WHERE c.ArticleID=a.ArticleID) as CommentCount, (SELECT Sex FROM dbo.Customer c WHERE c.CustomerID=a.CustomerID) as CustomerSex,(SELECT PhotoUrl FROM dbo.Customer c WHERE c.CustomerID=a.CustomerID) as PhotoUrl FROM dbo.ShortArticle a where a.ArticleID='{0}' ORDER BY CreateDate DESC", articleID); SqlDataReader sqlDataReader = DBHelper.GetDataReader(strSql.ToString()); shareModel model = sqlDataReader.ReaderToModel <shareModel>(); sqlDataReader.Close(); return(model); }
/// <summary> /// 发布我爱分享网 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool CreateArea(shareModel model, string _Type) { int rows = 0; try { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ShortArticle("); strSql.Append("ArticleID,ArticleContent,CustomerID,ArticleType,GetCount,DataState,CreateDate,Title)"); strSql.Append(" values ("); strSql.Append("@ArticleID,@ArticleContent,@CustomerID,@ArticleType,@GetCount,@DataState,@CreateDate,@Title)"); SqlParameter[] parameters = { new SqlParameter("@ArticleID", SqlDbType.UniqueIdentifier, 16), new SqlParameter("@ArticleContent", SqlDbType.VarChar, -1), new SqlParameter("@CustomerID", SqlDbType.UniqueIdentifier, 16), new SqlParameter("@ArticleType", SqlDbType.VarChar, -1), new SqlParameter("@GetCount", SqlDbType.Int, 4), new SqlParameter("@DataState", SqlDbType.Int, 4), new SqlParameter("@CreateDate", SqlDbType.DateTime), new SqlParameter("@Title", SqlDbType.VarChar, -1) }; parameters[0].Value = Guid.NewGuid(); parameters[1].Value = model.ArticleContent; parameters[2].Value = model.CustomerID; parameters[3].Value = _Type; //文字类型默认0 parameters[4].Value = 0; //初始浏览次数0 parameters[5].Value = 0; //默认状态0 parameters[6].Value = DateTime.Now; parameters[7].Value = model.Title; rows = DBHelper.ExecuteCommand(strSql.ToString(), parameters); } catch (Exception a) { Tool.WritrErro(a); } if (rows > 0) { return(true); } else { return(false); } }
protected void btnRelease_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(HidContent.Value.Trim())) { Tool.Alert("发布内容不可为空!"); return; } if (string.IsNullOrEmpty(lblName.Text.Trim())) { Tool.Alert("请选择发布栏目!"); return; } if (string.IsNullOrEmpty(txtTitle.Text.Trim())) { Tool.Alert("请选择发布标题!"); return; } CustomerModel customer = Session["UserInfo"] as CustomerModel; shareModel model = new shareModel(); //创建文字对象 model.CustomerID = customer.CustomerID; //文字发布人设置为当前登录用户 model.ArticleContent = HidContent.Value.Trim(); model.ArticleType = lblName.Text.Trim(); model.Title = txtTitle.Text.Trim(); bool bl = service.CreateArea(model, lblName.Text); //提交至数据库 if (bl) { //var CloseWebPage = "<script language='javascript' type='text/javascript'> CloseWebPage()</script>"; //Page.ClientScript.RegisterStartupScript(ClientScript.GetType(), "CloseWebPage", CloseWebPage); Tool.Alert("发布成功"); txtTitle.Text = null; } else { Tool.Alert("发布失败,请重试"); } } catch (Exception r) { Tool.WritrErro(r); Tool.Alert("发布失败,错误讯息【" + r.Message + "】"); } }
/// <summary> /// 发布我爱分享网 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Createshare(shareModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ShortArticle("); strSql.Append("ArticleID,ArticleContent,CustomerID,ArticleType,GetCount,DataState,CreateDate)"); strSql.Append(" values ("); strSql.Append("@ArticleID,@ArticleContent,@CustomerID,@ArticleType,@GetCount,@DataState,@CreateDate)"); SqlParameter[] parameters = { new SqlParameter("@ArticleID", SqlDbType.UniqueIdentifier, 16), new SqlParameter("@ArticleContent", SqlDbType.VarChar, -1), new SqlParameter("@CustomerID", SqlDbType.UniqueIdentifier, 16), new SqlParameter("@ArticleType", SqlDbType.VarChar, -1), new SqlParameter("@GetCount", SqlDbType.Int, 4), new SqlParameter("@DataState", SqlDbType.Int, 4), new SqlParameter("@CreateDate", SqlDbType.DateTime) }; parameters[0].Value = Guid.NewGuid(); parameters[1].Value = model.ArticleContent; parameters[2].Value = model.CustomerID; parameters[3].Value = "微博"; //文字类型默认 parameters[4].Value = 0; //初始浏览次数0 parameters[5].Value = 0; //默认状态0 parameters[6].Value = DateTime.Now; int rows = DBHelper.ExecuteCommand(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
protected void btnPost_Click(object sender, EventArgs e) { try { //从会话里面获取到用户详细信息 CustomerModel customer = Session["UserInfo"] as CustomerModel; shareModel model = new shareModel(); //创建文字对象 model.CustomerID = customer.CustomerID; //文字发布人设置为当前登录用户 model.ArticleContent = txtContent.Text; //将用户输入文本框的内容赋值给内容字段 bool bl = service.Createshare(model); //提交至数据库 if (bl) { Response.Write("<script>alert('发布成功');window.location='Index.aspx';</script>"); } else { Response.Write("<script>alert('发布不成功 请重试');window.location='Index.aspx';</script>"); } } catch (Exception q) { Tool.WritrErro(q); } }