Esempio n. 1
0
        /// <summary>
        /// User subcribe to tag
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="user"></param>
        public static void SubcribeToTag(int tag, int user)
        {
            using (var db = new QaAContext())
            {
                //Check the subcribe
                var q = (from t in db.UserHasSubscribes where (t.TagId == tag && t.UserId == user) select t).FirstOrDefault();
                //if it does not exist yet
                if (q == null)
                {
                    var subc = new UserHasSubscribe
                    {
                        TagId = tag,
                        UserId = user
                    };
                    db.UserHasSubscribes.Add(subc);
                    db.SaveChanges();
                }

            }
        }
Esempio n. 2
0
 /// <summary>
 /// User subcribes to more tags
 /// </summary>
 /// <param name="tags"></param>
 /// <param name="user"></param>
 public static void SubcribeToMoreTags(List<Tag> tags, int user)
 {
     using (var db = new QaAContext())
     {
         foreach (var item in tags)
         {
             //Check the subcribe
             var q = (from t in db.UserHasSubscribes where (t.TagId == item.Id && t.UserId == user) select t).FirstOrDefault();
             //if it does not exist yet
             if (q == null)
             {
                 var subc = new UserHasSubscribe
                 {
                     TagId = item.Id,
                     UserId = user
                 };
                 db.UserHasSubscribes.Add(subc);
                 db.SaveChanges();
             }
         }
     }
 }