예제 #1
0
        public ActionResult AddRelation(ht_comm_relation relation)
        {
            AuthenticationUser loginInfo = BLLUser.GetLoginUserInfo();

            if (loginInfo == null)
            {
                apiResp.msg  = "请先登录";
                apiResp.code = (int)HT.Model.Enum.APIErrCode.UserIsNotLogin;
                return(Json(apiResp));
            }
            if (BLLRelation.IsExistRelation(relation.main_id, loginInfo.id.ToString(), "praise"))
            {
                apiResp.msg  = "重复关注";
                apiResp.code = (int)HT.Model.Enum.APIErrCode.UserIsNotLogin;
                return(Json(apiResp));
            }
            ht_comm_relation model = new ht_comm_relation();

            model.add_time      = DateTime.Now;
            model.relation_type = "praise";
            model.main_id       = relation.main_id;
            model.relation_id   = loginInfo.id.ToString();
            if (BLLNews.AddPraise(int.Parse(relation.main_id), model) > 0)
            {
                apiResp.status = true;
                apiResp.msg    = "点赞成功";
            }
            else
            {
                apiResp.msg  = "点赞出错";
                apiResp.code = (int)HT.Model.Enum.APIErrCode.OperateFail;
            }
            return(Json(apiResp));
        }
예제 #2
0
        /// <summary>
        /// 点赞
        /// </summary>
        /// <param name="news_id"></param>
        /// <returns></returns>
        public ActionResult AddRelation(string news_id)
        {
            ht_comm_relation model = new ht_comm_relation();

            AuthenticationUser loginInfo = HT.BLL.BLLUser.GetLoginUserInfo();

            if (loginInfo == null)
            {
                apiResp.msg  = "请先登录";
                apiResp.code = (int)HT.Model.Enum.APIErrCode.UserIsNotLogin;
                return(Json(apiResp));
            }
            model.add_time      = DateTime.Now;
            model.relation_type = "praise";
            model.main_id       = news_id;
            model.relation_id   = loginInfo.id.ToString();
            if (HT.BLL.BLLRelation.AddRelation(model) > 0)
            {
                apiResp.status = true;
                apiResp.msg    = "点赞成功";
            }
            else
            {
                apiResp.msg  = "点赞出错";
                apiResp.code = (int)HT.Model.Enum.APIErrCode.OperateFail;
            }
            return(Json(apiResp));
        }
예제 #3
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="review"></param>
 /// <returns></returns>
 public static int AddRelation(ht_comm_relation relation)
 {
     using (Entities db = new Entities())
     {
         db.ht_comm_relation.Add(relation);
         return(db.SaveChanges());
     }
 }
예제 #4
0
 /// <summary>
 /// 点赞数加
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static int AddPraise(int id, ht_comm_relation relation)
 {
     using (Entities db = new Entities())
     {
         db.ht_comm_relation.Add(relation);
         db.ht_news.Find(id).praise_num++;
         return(db.SaveChanges());
     }
 }
예제 #5
0
 /// <summary>
 /// 取消点赞
 /// </summary>
 /// <param name="relation"></param>
 /// <returns></returns>
 public static int DeleteRelation(ht_comm_relation relation)
 {
     using (Entities db = new Entities())
     {
         ht_comm_relation model = db.ht_comm_relation.FirstOrDefault(p => p.main_id == relation.main_id && p.relation_id == relation.relation_id && p.relation_type == relation.relation_type);
         if (model != null)
         {
             db.ht_comm_relation.Remove(model);
             return(db.SaveChanges());
         }
         return(0);
     }
 }
예제 #6
0
 /// <summary>
 /// 点赞数减
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static int DeletePraise(int id, ht_comm_relation relation)
 {
     using (Entities db = new Entities())
     {
         ht_comm_relation model = db.ht_comm_relation.FirstOrDefault(p => p.main_id == relation.main_id && p.relation_id == relation.relation_id && p.relation_type == relation.relation_type);
         if (model == null)
         {
             return(0);
         }
         db.ht_comm_relation.Remove(model);
         db.ht_news.Find(id).praise_num--;
         int rusult = db.SaveChanges();
         return(rusult);
     }
 }
예제 #7
0
 public ActionResult DeleteRelation(ht_comm_relation relation)
 {
     relation.relation_type = "praise";
     relation.relation_id   = BLLUser.GetUserId().ToString();
     if (BLLNews.DeletePraise(int.Parse(relation.main_id), relation) > 0)
     {
         apiResp.msg    = "取消点赞成功";
         apiResp.status = true;
     }
     else
     {
         apiResp.msg  = "取消点赞出错";
         apiResp.code = (int)HT.Model.Enum.APIErrCode.OperateFail;
     }
     return(Json(apiResp));
 }
예제 #8
0
 /// <summary>
 /// 是否存在关系
 /// </summary>
 /// <param name="relation"></param>
 /// <returns></returns>
 public static bool IsExistRelation(ht_comm_relation relation)
 {
     using (Entities db = new Entities())
     {
         db.Configuration.ProxyCreationEnabled = false;
         var data = db.ht_comm_relation.Where(p => true);
         if (!string.IsNullOrWhiteSpace(relation.relation_type))
         {
             data = data.Where(p => p.relation_type == relation.relation_type);
         }
         if (!string.IsNullOrWhiteSpace(relation.main_id))
         {
             data = data.Where(p => p.main_id == relation.main_id);
         }
         if (!string.IsNullOrWhiteSpace(relation.relation_id))
         {
             data = data.Where(p => p.relation_id == relation.relation_id);
         }
         return(data.Count() > 0 ? true : false);
     }
 }
예제 #9
0
 /// <summary>
 /// 取消点赞
 /// </summary>
 /// <param name="relation"></param>
 /// <returns></returns>
 public static int DeleteRelation(ht_comm_relation relation)
 {
     using (Entities db = new Entities())
     {
         var data = db.ht_comm_relation.Where(p => true);
         if (!string.IsNullOrWhiteSpace(relation.relation_type))
         {
             data = data.Where(p => p.relation_type == relation.relation_type);
         }
         if (!string.IsNullOrWhiteSpace(relation.main_id))
         {
             data = data.Where(p => p.main_id == relation.main_id);
         }
         if (!string.IsNullOrWhiteSpace(relation.relation_id))
         {
             data = data.Where(p => p.relation_id == relation.relation_id);
         }
         foreach (var item in data)
         {
             db.ht_comm_relation.Remove(item);
         }
         return(db.SaveChanges());
     }
 }