예제 #1
0
        public int AddDislike(int announ_id)
        {
            //if (Session["login"] != null)
            //{
            //string login = Session["login"].ToString();
            //var customer_id_arr = (from a in db.customers
            //                       where a.login == login
            //                       select a.customer_id);
            //int customer_id = 0;
            //foreach (int item in customer_id_arr)
            //{
            //    customer_id = item;
            //}
            var likes_arr = (from a in db.likes
                             where a.announ_id == announ_id
                             select a);
            int like_num    = 0;
            int dislike_num = 0;
            int like_id     = 0;
            int likes_final = 0;

            foreach (var item in likes_arr)
            {
                like_num    = item.like_num;
                dislike_num = item.disline_num;
                like_id     = item.id;
            }
            if (like_num == 0 && dislike_num == 0)
            {
                iproby.Data_Model.like like = new iproby.Data_Model.like();
                like.announ_id   = announ_id;
                like.like_num    = like_num + 1;
                like.disline_num = dislike_num;
                db.likes.Add(like);
                db.SaveChanges();
                likes_final = like.disline_num;
            }
            else
            {
                var like = db.likes.Find(like_id);
                if (like != null)
                {
                    like.disline_num = dislike_num + 1;
                    db.SaveChanges();
                    likes_final = like.disline_num;
                }
            }
            return(likes_final);
            //}
            //else
            //{
            //    var likes_arr = (from a in db.likes
            //                     where a.announ_id == announ_id
            //                     select a);
            //    int like_num = 0;
            //    int dislike_num = 0;
            //    int like_id = 0;
            //    int likes_final = 0;
            //    foreach (var item in likes_arr)
            //    {
            //        like_num = item.like_num;
            //        dislike_num = item.disline_num;
            //        like_id = item.id;
            //    }
            //    likes_final = dislike_num;
            //    return likes_final;
            //}
        }
예제 #2
0
 public int AddLike(int announ_id)
 {
     //if (Session["login"] != null)
     //{
         //string login = Session["login"].ToString();
         //var customer_id_arr = (from a in db.customers
         //                       where a.login == login
         //                       select a.customer_id);
         //int customer_id = 0;
         //foreach (int item in customer_id_arr)
         //{
         //    customer_id = item;
         //}
         var likes_arr = (from a in db.likes
                                where a.announ_id == announ_id
                          select a);
         int like_num = 0;
         int dislike_num = 0;
         int like_id = 0;
         int likes_final=0;
         foreach (var item in likes_arr)
         {
             like_num = item.like_num;
             dislike_num = item.disline_num;
             like_id = item.id;
         }
         if (like_num == 0 && dislike_num == 0)
         {
             iproby.Data_Model.like like = new iproby.Data_Model.like();
             like.announ_id = announ_id;
             like.like_num = like_num + 1;
             like.disline_num = dislike_num;
             db.likes.Add(like);
             db.SaveChanges();
             likes_final = like.like_num;
         }
         else {
             var like = db.likes.Find(like_id);
             if (like != null)
             {
                 like.like_num = like_num+1;
                 db.SaveChanges();
                 likes_final = like.like_num;
             }
         }
         return likes_final;
     //}
     //else
     //{
     //    var likes_arr = (from a in db.likes
     //                     where a.announ_id == announ_id
     //                     select a);
     //    int like_num = 0;
     //    int dislike_num = 0;
     //    int like_id = 0;
     //    int likes_final = 0;
     //    foreach (var item in likes_arr)
     //    {
     //        like_num = item.like_num;
     //        dislike_num = item.disline_num;
     //        like_id = item.id;
     //    }
     //    likes_final = like_num;
     //    return likes_final;
     //}
 }