protected void indexchange(object sender, EventArgs e)
        {
            calendar_entity db = new calendar_entity();

            IEnumerable<onlyid_> searchRes = (IEnumerable<onlyid_>)Session["searchfriendonlyid"];
            Guid selected= searchRes.ElementAtOrDefault( gv.SelectedIndex).userid;

            Guid myid=(Guid)Membership.GetUser().ProviderUserKey;

            var res = from i in db.calendar_friend

                      where i.myUserId == myid && i.friendUserId == selected
                      select i;

            if(res.Count()==0)
            {
                calendar_friend newf=new calendar_friend();
                newf.friendUserId=selected;
                newf.myUserId=myid;
                newf.relationship="";
                db.calendar_friend.AddObject(newf);
                db.SaveChanges();
            }

            calendar_globalevent newg=new calendar_globalevent() {
                userid =(Guid) Membership.GetUser().ProviderUserKey,
                createtime = DateTime.Today,
                eventtype = "addfriend"
            };
            globaleventContext.insertevent(newg, selected);
        }
Example #2
0
        public bool removeFriend(Guid target, Guid me)
        {
            IEnumerable<calendar_friend> tmp = Friend_DAL.getFriendByMyId(me);
            calendar_friend tmp2 = new calendar_friend() { myUserId = me, friendUserId = target };
            if (!tmp.Contains(tmp2))
                return false;

            Friend_DAL.deleteFriend(target, me);
            return true;
        }
Example #3
0
        public static void addFriend(Guid target, Guid me)
        {
            calendar_entity db = new calendar_entity();
            calendar_friend f = new calendar_friend()
            {

             friendUserId=target,
             myUserId=me
            };

            db.calendar_friend.AddObject(f);
            db.SaveChanges();
        }