Esempio n. 1
0
 /// <summary>
 /// 取消赞
 /// </summary>
 /// <param name="postGood"></param>
 /// <returns></returns>
 public int DeletePostGood(PostGood postGood)
 {
     try
     {
         _dataContext.Remove(postGood);
         var result = _dataContext.SaveChanges();
         return(result);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         throw ex;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 验证是否点过赞
 /// </summary>
 /// <param name="postGood"></param>
 /// <returns></returns>
 public PostGood GetPostGood(PostGood postGood)
 {
     try
     {
         return(_dataContext.PostGoods
                .Where(x => x.PostInfo.PostId == postGood.PostInfo.PostId &&
                       x.GoodsUser.UserId == postGood.GoodsUser.UserId).FirstOrDefault());
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         throw ex;
     }
 }
Esempio n. 3
0
 public int AddPostGood(PostGood postGood)
 {
     try
     {
         _dataContext.Entry(postGood.PostInfo).State  = EntityState.Unchanged;
         _dataContext.Entry(postGood.GoodsUser).State = EntityState.Unchanged;
         _dataContext.Add(postGood);
         var result = _dataContext.SaveChanges() > 0 ? postGood.GoodsId : 0;
         return(result);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         throw ex;
     }
 }
 public ActionResult DeletePostGood([FromBody] PostGood postGood)
 {
     try
     {
         if (postGood == null || postGood.GoodsId <= 0)
         {
             return(Ok(new
             {
                 mark = "2",
                 msg = "请求信息异常!"
             }));
         }
         var result = _postGoodService.DeletePostGood(postGood);
         if (result <= 0)
         {
             return(Ok(new
             {
                 mark = "2",
                 msg = "处理失败!"
             }));
         }
         else
         {
             return(Ok(new
             {
                 mark = "1",
                 msg = "成功!"
             }));
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(Ok(new
         {
             mark = "2",
             msg = ex.Message
         }));
     }
 }
 public ActionResult AddPostGood([FromBody] PostInfo postInfo)
 {
     try
     {
         if (postInfo == null || postInfo.PostId <= 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 postGood = new PostGood
         {
             PostInfo   = postInfo,
             GoodsUser  = user,
             CreateDate = DateTime.Now,
             UpdateDate = DateTime.Now
         };
         var pg = _postGoodService.GetPostGood(postGood);
         if (pg != null && pg.GoodsId > 0)
         {
             return(Ok(new
             {
                 mark = "2",
                 msg = "已经点过了!"
             }));
         }
         var result = _postGoodService.AddPostGood(postGood);
         if (result <= 0)
         {
             return(Ok(new
             {
                 mark = "2",
                 msg = "处理失败!"
             }));
         }
         else
         {
             return(Ok(new
             {
                 mark = "1",
                 result,
                 msg = "成功!"
             }));
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         return(Ok(new
         {
             mark = "2",
             msg = ex.Message
         }));
     }
 }