示例#1
0
 //添加关注
 public void Add(String SourceQQ, String Attention, String GroupNum)
 {
     if (Attention.Contains(" ") || Attention.Equals(""))
     {
         throw new Exception("不允许输入空格和空字符串");
     }
     using (var dbcontext = new AttentionContext())
     {
         Attention newatt = new Attention(SourceQQ, GroupNum, Attention);
         dbcontext.Attentions.Add(newatt);
         dbcontext.SaveChanges();
         this.Attentions = QueryAll();
     }
     UpdateListeners();
 }
示例#2
0
 //删除关注
 public Boolean Remove(String SourceQQ, String Attention, String GroupNum)
 {
     using (var dbcontext = new AttentionContext())
     {
         Attention temp = dbcontext.Attentions.FirstOrDefault(p => p.Listener == SourceQQ && p.Group == GroupNum && p.AttentionPoint == Attention);
         if (temp != null)
         {
             dbcontext.Attentions.Remove(temp);
             dbcontext.SaveChanges();
             this.Attentions = QueryAll();
             UpdateListeners();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
示例#3
0
 //更新关注
 public Boolean Update(String SourceQQ, String OldAttention, String NewAttention, String GroupNum)
 {
     //检查是否存在,
     //如有删除之,并插入新的
     //允许GroupNum为空,这样就只要查询所有的Attention字段相等的部分
     using (var dbcontext = new AttentionContext())
     {
         var quary = dbcontext.Attentions
                     .Where(att => att.AttentionPoint == OldAttention && att.Group == GroupNum);
         foreach (Attention att in quary)
         {
             dbcontext.Attentions.Remove(att);
             dbcontext.Attentions.Add(new Attention(SourceQQ, GroupNum, NewAttention));
         }
         dbcontext.SaveChanges();
         this.Attentions = QueryAll();
     }
     return(true);
 }