Beispiel #1
0
        public async Task <int> UpdateUser()
        {
            var rp = await _fb.GetTaskAsync <FbUser>("/me?fields=id,name,picture");

            using (var db = new FbsEntities())
            {
                var cUser = db.Users.FirstOrDefault(x => x.Id == rp.id);
                if (cUser != null)
                {
                    cUser.Token    = _token;
                    cUser.Name     = rp.name;
                    cUser.ImageUrl = rp.picture;
                    db.SaveChanges();
                    return(1);
                }
            }
            return(0);
        }
Beispiel #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var cap = txtAddCaption.Text;

            if (string.IsNullOrEmpty(cap))
            {
                return;
            }
            using (var db = new FbsEntities())
            {
                db.Captions.Add(new Caption {
                    Title = cap
                });
                db.SaveChanges();
            }

            LoadGridCaption();
            panel2.BringToFront();
        }
Beispiel #3
0
        public object GetGroups()
        {
            var user = GetUser();
            var rp   = _fb.GetTaskAsync <Result>("/me/groups?fields=id,name,privacy,member_count").Result;

            using (var db = new FbsEntities())
            {
                var cUser = db.Users.FirstOrDefault(x => x.Id == user.Id);
                if (cUser != null)
                {
                    db.Groups.AddRange(rp.data.Select(x => new Group()
                    {
                        Name         = x.name,
                        UserId       = cUser.Id,
                        Id           = x.id,
                        Member_count = x.member_count,
                        Privacy      = x.privacy
                    }));
                }
                else
                {
                    var rs = db.Users.Add(user);
                    db.Groups.AddRange(rp.data.Select(x => new Group()
                    {
                        Name         = x.name,
                        UserId       = rs.Id,
                        Id           = x.id,
                        Member_count = x.member_count,
                        Privacy      = x.privacy,
                        Enable       = true
                    }));
                }

                var rss = db.SaveChanges();
            }

            return(rp);
        }
Beispiel #4
0
        private void btnAddAccount_Click(object sender, EventArgs e)
        {
            var token = txtToken.Text;

            switch (_action)
            {
            case "CREATE":
                _fb = new Fb(token);
                var rs = _fb.GetGroups();
                break;

            case "UPDATE":
                using (var db = new FbsEntities())
                {
                    var cUser = db.Users.FirstOrDefault(x => x.Id == _id);
                    if (cUser != null)
                    {
                        cUser.Token = token;
                        db.SaveChanges();
                    }
                }
                break;
            }
        }