/// <summary> /// 根据ID删除数据 /// </summary> /// <param name="t">HuobiProject.Models</param> /// <returns> /// Success:T /// Failed:F /// </returns> bool ICURD <TCommentLike> .Delete(TCommentLike t) { TCommentLike tml = m_iCommentLike.Retrieve(t); m_db.TCommentLike.Remove(tml); return(m_db.SaveChanges() > 0); }
/// <summary> /// 根据ID更新数据 /// </summary> /// <param name="t">HuobiProject.Models</param> /// <returns> /// True:成功 /// False:失败 /// </returns> bool ICURD <TCommentLike> .Update(TCommentLike t) { TCommentLike tml = m_iCommentLike.Retrieve(t); tml.Like = t.Like; return(m_db.SaveChanges() > 0); }
/// <summary> /// 增加数据 /// </summary> /// <param name="t">HuobiProject.Models</param> /// <returns> /// True:成功 /// False:失败 /// </returns> bool ICURD <TCommentLike> .Create(TCommentLike t) { Random rand = new Random((int)Tools.Ticks()); string id = Tools.Ticks() + "" + rand.Next(1000, 10000); t.CommentLikeId = id; t.CreateTime = DateTime.Now; m_db.TCommentLike.Add(t); return(m_db.SaveChanges() > 0); }
public ActionResult <Result> Like([FromRoute] string commentId) { //获取用户信息 string user_id = Token.GetUserId(HttpContext.Request.Headers["Authorization"].ToString().Substring(7)); TUser user = userServer.Retrieve(new TUser() { UserId = user_id }); TCommentLike tml = commentLikeServer.RetrieveByUserAndComment(user.UserId, commentId); if (tml == null) { return(new Result(200, "成功", null)); } return(new Result(200, "成功", tml.Like)); }
public ActionResult <Result> Like([FromRoute] string commentId, [FromRoute] short islike) { //获取用户信息 string user_id = Token.GetUserId(HttpContext.Request.Headers["Authorization"].ToString().Substring(7)); TUser user = userServer.Retrieve(new TUser() { UserId = user_id }); TComment cmt = commentServer.Retrieve(new TComment { CommentId = commentId }); TCommentLike tml = commentLikeServer.RetrieveByUserAndComment(user.UserId, commentId); if (cmt.UserId == user.UserId) { throw new ResultException($"不能{(islike == 0 ? "踩" : "赞")}自己的评论"); } if (tml == null)//点赞 { commentLikeServer.Create(new TCommentLike { UserId = user.UserId, CommentId = commentId, Like = islike }); } else if (tml.Like == 1 && islike == 0)//赞改为踩 { tml.Like = 0; commentLikeServer.Update(tml); } else if (tml.Like == 0 && islike == 1)//踩改为赞 { tml.Like = 1; commentLikeServer.Update(tml); } else//取消赞/踩 { commentLikeServer.Delete(tml); } return(new Result(200, "成功")); }
/// <summary> /// 根据ID获取数据 /// </summary> /// <param name="t">HuobiProject.Models</param> /// <returns> /// Success:T /// Failed:NULL /// </returns> TCommentLike ICURD <TCommentLike> .Retrieve(TCommentLike t) { return(m_db.TCommentLike.Find(t.CommentLikeId)); }