Esempio n. 1
0
        static void Main(string[] args)
        {
            User vasya    = new User("vasya");
            User kolya    = new User("kolya");
            User petya    = new User("petya");
            User sasha    = new User("sasha");
            User cool1234 = new User("cool1234");

            SocialNet social = new SocialNet(10);

            social.AddUsers(vasya, new User[] { kolya, petya, sasha });
            social.AddUsers(sasha, new User[] { vasya, cool1234, petya });
            social.AddUsers(cool1234, new User[] { kolya });
            social.AddUsers(kolya, new User[] { cool1234 });

            social.AddMessage(new Message(vasya, new DateTime(2014, 10, 20, 8, 0, 0), "mes1"));
            social.AddMessage(new Message(cool1234, new DateTime(2014, 10, 20, 8, 5, 0), "mes2"));
            social.AddMessage(new Message(kolya, new DateTime(2014, 10, 20, 8, 39, 0), "mes3"));
            social.AddMessage(new Message(petya, new DateTime(2014, 10, 20, 8, 41, 0), "mes4"));
            social.AddMessage(new Message(sasha, new DateTime(2014, 10, 20, 8, 52, 0), "mes5"));
            social.AddMessage(new Message(petya, new DateTime(2014, 10, 20, 9, 3, 0), "mes6"));
            social.AddMessage(new Message(cool1234, new DateTime(2014, 10, 20, 11, 0, 0), "mes7"));
            social.AddMessage(new Message(kolya, new DateTime(2014, 10, 20, 9, 24, 0), "mes8"));
            social.AddMessage(new Message(sasha, new DateTime(2014, 10, 20, 9, 45, 0), "mes9"));
            social.AddMessage(new Message(kolya, new DateTime(2014, 10, 20, 9, 51, 0), "mes10"));

            social.ShowMessage(kolya);
            // Console.WriteLine("Рукопожатий - {0}", social.Handshake(vasya,cool1234));
            Console.ReadKey();
        }
        public async Task <HttpResponseMessage> PostSocialNetwork([FromBody]  SocialNet body, int id)
        {
            var adminId     = GetToken();
            var instance    = CommunityService.GetInstance();
            var accessToken = await getLongLiveToken(body.Token, body);

            if (adminId == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, new Forbidden(Request.RequestUri, "token not present in authorization header or not valid"), "application/problem+json"));
            }
            if (body == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new BadRequest(Request.RequestUri, "The body must not be null"), "application/problem+json"));
            }

            var res = await instance.InsertSocialNetwork(new CreateCommunitySocial { adminId = adminId, social = body.Social, token = accessToken, url = body.Url, communityId = id });

            if (res.Success)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, new { }, "application/json"));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Conflict, new Conflict(Request.RequestUri, res.Message), "application/problem+json"));
            }
        }
 public ActionResult Update(SocialNet socials)
 {
     if (ModelState.IsValid)
     {
         db.Entry(socials).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(socials));
 }
        public ActionResult Update(int?id)
        {
            SocialNet socials = db.SocialNet.Find(id);

            if (socials == null)
            {
                return(RedirectToAction("Error", "Home"));
            }
            return(View(socials));
        }
 public ActionResult Create(SocialNet socials)
 {
     if (ModelState.IsValid)
     {
         db.SocialNet.Add(socials);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(socials));
 }
        public ActionResult Delete(int?id)
        {
            SocialNet socials = db.SocialNet.Find(id);

            if (socials == null)
            {
                return(RedirectToAction("Error", "Home"));
            }
            db.SocialNet.Remove(socials);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        private async Task <string> getLongLiveToken(string token, SocialNet body)
        {
            //facebook request GET /oauth/access_token?grant_type = fb_exchange_token & amp;client_id ={ app - id}&amp;client_secret ={ app - secret}&amp;fb_exchange_token ={ short-lived - token}
            if (body.Social == "Twitter")
            {
                return(token);
            }
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://graph.facebook.com");
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain"));

                HttpResponseMessage response = await client.GetAsync("/oauth/access_token?grant_type=fb_exchange_token&amp&client_id=1738062506473012&amp&client_secret=5e6aeb8f92541b00963bdf257c6cdd5c&amp&fb_exchange_token=" + token);

                if (response.IsSuccessStatusCode)
                {
                    string product = await response.Content.ReadAsStringAsync();

                    var res = HttpUtility.ParseQueryString(product);
                    return(res["access_token"]);
                }
            }
            return("");
        }