public ActionResult AddReplyGood([FromBody] ReplyInfo replyInfo) { try { if (replyInfo == null || replyInfo.ReplyId <= 0) { return(Ok(new { mark = "2", msg = "帖子信息为空!" })); } var headerStr = Request.Headers["Authorization"]; var jwtHelper = new JWTHelper(_configuration); var user = new UserInfo { UserId = jwtHelper.GetJWTUserData(headerStr) }; var replyGood = new ReplyGood { ReplyInfo = replyInfo, GoodsUser = user }; var pg = _replyGoodService.GetReplyGood(replyGood); if (pg != null && pg.GoodsId > 0) { return(Ok(new { mark = "2", msg = "已经点过了!" })); } var result = _replyGoodService.AddReplyGood(replyGood); if (result <= 0) { return(Ok(new { mark = "2", msg = "处理失败!" })); } else { return(Ok(new { mark = "1", result, msg = "成功!" })); } } catch (Exception ex) { Console.WriteLine(ex); throw ex; } }
/// <summary> /// 验证是否点过赞 /// </summary> /// <param name="postGood"></param> /// <returns></returns> public ReplyGood GetReplyGood(ReplyGood replyGood) { try { return(_dataContext.ReplyGoods .Where(x => x.ReplyInfo.ReplyId == replyGood.ReplyInfo.ReplyId && x.GoodsUser.UserId == replyGood.GoodsUser.UserId).FirstOrDefault()); } catch (Exception ex) { Console.WriteLine(ex); throw ex; } }
/// <summary> /// 取消赞 /// </summary> /// <param name="postGood"></param> /// <returns></returns> public int DeleteReplyGood(ReplyGood replyGood) { try { //_dataContext.Entry(postGood.PostInfo).State = EntityState.Unchanged; //_dataContext.Entry(postGood.GoodsUser).State = EntityState.Unchanged; _dataContext.Remove(replyGood); var result = _dataContext.SaveChanges(); return(result); } catch (Exception ex) { Console.WriteLine(ex); throw ex; } }
public int AddReplyGood(ReplyGood replyGood) { try { _dataContext.Entry(replyGood.ReplyInfo).State = EntityState.Unchanged; _dataContext.Entry(replyGood.GoodsUser).State = EntityState.Unchanged; _dataContext.Add(replyGood); var result = _dataContext.SaveChanges() > 0 ? replyGood.GoodsId : 0; return(result); } catch (Exception ex) { Console.WriteLine(ex); throw ex; } }
public ActionResult DeleteReplyGood([FromBody] ReplyGood replyGood) { try { if (replyGood == null || replyGood.GoodsId <= 0) { return(Ok(new { mark = "2", msg = "请求信息异常!" })); } var result = _replyGoodService.DeleteReplyGood(replyGood); if (result <= 0) { return(Ok(new { mark = "2", msg = "处理失败!" })); } else { return(Ok(new { mark = "1", msg = "成功!" })); } } catch (Exception ex) { Console.WriteLine(ex); throw ex; } }