//Added by Sumit Gupta [02-02-15]
        private void AddFacebookMessageWithPagination(string UserId, FacebookClient fb, dynamic profile)
        {
            int K = 0;
            objFacebookMessage = new Domain.Myfashion.Domain.FacebookMessage();
            try
            {
                string nexturl = "v2.0/me/inbox";

                for (int i = 0; i < 50; i++)
                {
                    dynamic messages = fb.Get(nexturl);
                    if (messages != null)
                    {
                        try
                        {
                            nexturl = messages["paging"]["next"].ToString();
                            logger.Error("Facebook.asmx >> AddFacebookMessageWithPagination >> nexturl : " + nexturl);
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.Message);
                            logger.Error(ex.StackTrace);
                        }

                        foreach (dynamic result in messages["data"])
                        {
                            try
                            {
                                foreach (dynamic message in result["comments"]["data"])
                                {
                                    objFacebookMessage.MessageId = message["id"];
                                    objFacebookMessage.FromName = message["from"]["name"];
                                    objFacebookMessage.FromId = message["from"]["id"];
                                    objFacebookMessage.Message = message["message"];
                                    objFacebookMessage.MessageDate = DateTime.Parse(message["created_time"].ToString());
                                    objFacebookMessage.FromProfileUrl = "http://graph.facebook.com/" + message["from"]["id"] + "/picture?type=small";
                                    objFacebookMessage.EntryDate = DateTime.Now;
                                    objFacebookMessage.Id = Guid.NewGuid();
                                    objFacebookMessage.ProfileId = profile["id"].ToString();
                                    objFacebookMessage.Type = "inbox_message";
                                    objFacebookMessage.UserId = Guid.Parse(UserId);
                                    if (!objFacebookMessageRepository.checkFacebookMessageExists(objFacebookMessage.MessageId))
                                    {
                                        K++;
                                        objFacebookMessageRepository.addFacebookMessage(objFacebookMessage);
                                        logger.Error("AddFacebookMessageWithPaginationCount>>"+K);
                                    }

                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.StackTrace);
                            }

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
                Console.WriteLine(ex.StackTrace);
            }
        }
        private void AddFacebookUserHome(string UserId, FacebookClient fb, dynamic profile)
        {
            int J = 0;

            objFacebookMessage = new Domain.Myfashion.Domain.FacebookMessage();
            try
            {
                dynamic home = fb.Get("v2.0/me/home");
                if (home != null)
                {
                    int lstfbcount = 0;
                    foreach (dynamic result in home["data"])
                    {
                        string message = string.Empty;
                        string imgprof = "http://graph.facebook.com/" + result["from"]["id"] + "/picture?type=small";
                        objFacebookMessage.EntryDate = DateTime.Now;
                        objFacebookMessage.MessageId = result["id"].ToString();
                        objFacebookMessage.FromId = result["from"]["id"].ToString();
                        objFacebookMessage.FromName = result["from"]["name"].ToString();
                        objFacebookMessage.FromProfileUrl = imgprof;
                        objFacebookMessage.Id = Guid.NewGuid();
                        objFacebookMessage.MessageDate = DateTime.Parse(result["created_time"].ToString());
                        objFacebookMessage.UserId = Guid.Parse(UserId);

                        try
                        {
                            objFacebookMessage.Picture = result["picture"].ToString();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                            objFacebookMessage.Picture = null;
                        }
                        try
                        {
                            if (result["message_tags"][0] != null)
                            {
                                if (result["to"] != null)
                                {
                                    foreach (var item in result["to"]["data"])
                                    {
                                        if (result["from"] != null)
                                        {

                                            if (item["id"] != profile["id"])
                                            {
                                                if (result["from"]["id"] == profile["id"])
                                                {
                                                    objFacebookMessage.Type = "fb_tag";
                                                }
                                                else
                                                {
                                                    objFacebookMessage.Type = "fb_home";
                                                }
                                            }
                                            else
                                            {
                                                objFacebookMessage.Type = "fb_home";
                                            }
                                        }
                                    }

                                }
                                else
                                {
                                    objFacebookMessage.Type = "fb_home";

                                }
                            }
                            else
                            {
                                objFacebookMessage.Type = "fb_home";
                            }
                        }
                        catch (Exception ex)
                        {
                            objFacebookMessage.Type = "fb_home";
                            Console.WriteLine(ex.StackTrace);
                        }
                        objFacebookMessage.ProfileId = profile["id"].ToString();
                        objFacebookMessage.FbComment = "http://graph.facebook.com/" + result["id"] + "/comments";
                        dynamic likes = fb.Get("v2.0/" + result["id"].ToString() + "/likes?limit=50000000");
                        string likestatus = "likes";
                        foreach (dynamic like in likes["data"])
                        {
                            try
                            {
                                if (profile["id"].ToString() == like["id"].ToString())
                                {
                                    likestatus = "unlike";
                                    break;
                                }
                            }
                            catch (Exception ex)
                            {
                                likestatus = "likes";

                            }
                        }
                        objFacebookMessage.FbLike = likestatus;
                        if (lstfbcount < 25)
                        {
                            try
                            {
                                if (result["message"] != null)
                                {
                                    message = result["message"];
                                    lstfbcount++;
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.StackTrace);
                                try
                                {
                                    if (result["description"] != null)
                                    {
                                        message = result["description"];
                                        lstfbcount++;
                                    }
                                }
                                catch (Exception exx)
                                {
                                    try
                                    {
                                        Console.WriteLine(exx.StackTrace);
                                        if (result["story"] != null)
                                        {
                                            message = result["story"];
                                            lstfbcount++;
                                        }
                                    }
                                    catch (Exception exxx)
                                    {
                                        Console.WriteLine(exxx.StackTrace);
                                        message = string.Empty;
                                    }
                                }
                            }
                        }
                        objFacebookMessage.Message = message;

                        if (!objFacebookMessageRepository.checkFacebookMessageExists(objFacebookMessage.MessageId))
                        {
                            J++;
                            objFacebookMessageRepository.addFacebookMessage(objFacebookMessage);
                            logger.Error("AddFacebookUserHomeCount>>"+J);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.StackTrace);
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);

            }
        }
 public string FacebookLike(String msgguid, String profileid, string msgid, string userid)
 {
     string ret = "";
     Domain.Myfashion.Domain.FacebookAccount objFacebookAccount = objFacebookAccountRepository.getFacebookAccountDetailsById(profileid, Guid.Parse(userid));
     FacebookClient fb = new FacebookClient();
     fb.AccessToken = objFacebookAccount.AccessToken;
     objFacebookMessage = objFacebookMessageRepository.GetFacebookUserWallPostDetails(Guid.Parse(msgguid));
     if (objFacebookMessage.FbLike == "likes")
     {
         System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
         var s = fb.Post("v2.0/" + msgid + "/likes", null);
         objFacebookMessage.FbLike = "unlike";
     }
     else
     {
         var s = fb.Delete(msgid + "/likes", null);
         objFacebookMessage.FbLike = "likes";
     }
     objFacebookMessageRepository.updateFacebookMessage(objFacebookMessage);
     return ret;
 }