public bool AddFacebookFriendsGender(string ProfileId, string FacebookUserId)
        {
            Api.Myfashionmarketer.Models.FacebookAccount _FacebookAccount = new FacebookAccount();
            Domain.Myfashion.Domain.FacebookAccount      _facebookAccount = new Domain.Myfashion.Domain.FacebookAccount();

            _facebookAccount = (Domain.Myfashion.Domain.FacebookAccount)(new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize(_FacebookAccount.getFacebookAccountDetailsById(ProfileId, FacebookUserId), typeof(Domain.Myfashion.Domain.FacebookAccount)));

            if (string.IsNullOrEmpty(_facebookAccount.AccessToken))
            {
                _facebookAccount = new Domain.Myfashion.Domain.FacebookAccount();
                Api.Myfashionmarketer.Models.FacebookAccountRepository _FacebookAccountRepository = new FacebookAccountRepository();

                System.Collections.ArrayList lstFacebookAccounts = _FacebookAccountRepository.getAllFacebookAccounts();

                Random _random = new Random();
                var    rnum    = _random.Next(0, lstFacebookAccounts.Count - 1);
                _facebookAccount = (Domain.Myfashion.Domain.FacebookAccount)lstFacebookAccounts[rnum];
            }
            int malecount   = 0;
            int femalecount = 0;

            Domain.Myfashion.Domain.FacebookStats objfbStats = new Domain.Myfashion.Domain.FacebookStats();
            FacebookStatsRepository objFBStatsRepo           = new FacebookStatsRepository();

            FacebookClient fb = new FacebookClient();

            fb.AccessToken = _facebookAccount.AccessToken;
            try
            {
                dynamic data = fb.Get("v2.0/me/friends?fields=gender");

                //dynamic data, dynamic profile, Guid userId


                foreach (var item in data["data"])
                {
                    try
                    {
                        if (item["gender"] == "male")
                        {
                            malecount++;
                        }
                        else if (item["gender"] == "female")
                        {
                            femalecount++;
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
                return(false);
            }
            objfbStats.EntryDate   = DateTime.Now;
            objfbStats.FbUserId    = _facebookAccount.FbUserId;//profile["id"].ToString();
            objfbStats.FemaleCount = femalecount;
            objfbStats.Id          = Guid.NewGuid();
            objfbStats.MaleCount   = malecount;
            objfbStats.UserId      = _facebookAccount.UserId;
            objfbStats.FanCount    = getfanCount(objfbStats, _facebookAccount.AccessToken);

            if (objFBStatsRepo.checkFacebookStatsExists(objfbStats.FbUserId.ToString(), objfbStats.UserId, objfbStats.FanCount, objfbStats.MaleCount, objfbStats.FemaleCount))
            {
                objFBStatsRepo.addFacebookStats(objfbStats);
            }


            return(true);
        }
        public bool AddFacebookFriendsGender(string ProfileId, string FacebookUserId)
        {
            Api.Myfashionmarketer.Models.FacebookAccount _FacebookAccount = new FacebookAccount();
            Domain.Myfashion.Domain.FacebookAccount _facebookAccount = new Domain.Myfashion.Domain.FacebookAccount();

            _facebookAccount = (Domain.Myfashion.Domain.FacebookAccount)(new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize(_FacebookAccount.getFacebookAccountDetailsById(ProfileId, FacebookUserId), typeof(Domain.Myfashion.Domain.FacebookAccount)));

            if (string.IsNullOrEmpty(_facebookAccount.AccessToken))
            {
                _facebookAccount = new Domain.Myfashion.Domain.FacebookAccount();
                Api.Myfashionmarketer.Models.FacebookAccountRepository _FacebookAccountRepository = new FacebookAccountRepository();

                System.Collections.ArrayList lstFacebookAccounts = _FacebookAccountRepository.getAllFacebookAccounts();

                Random _random = new Random();
                var rnum = _random.Next(0, lstFacebookAccounts.Count - 1);
                _facebookAccount = (Domain.Myfashion.Domain.FacebookAccount)lstFacebookAccounts[rnum];
            }
            int malecount = 0;
            int femalecount = 0;

            Domain.Myfashion.Domain.FacebookStats objfbStats = new Domain.Myfashion.Domain.FacebookStats();
            FacebookStatsRepository objFBStatsRepo = new FacebookStatsRepository();

            FacebookClient fb = new FacebookClient(); 
            fb.AccessToken = _facebookAccount.AccessToken;
            try
            {
                dynamic data = fb.Get("v2.0/me/friends?fields=gender");

                //dynamic data, dynamic profile, Guid userId


                foreach (var item in data["data"])
                {

                    try
                    {
                        if (item["gender"] == "male")
                            malecount++;
                        else if (item["gender"] == "female")
                            femalecount++;
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                        logger.Error(ex.StackTrace);
                    }

                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
                return false;
            }
            objfbStats.EntryDate = DateTime.Now;
            objfbStats.FbUserId = _facebookAccount.FbUserId;//profile["id"].ToString();
            objfbStats.FemaleCount = femalecount;
            objfbStats.Id = Guid.NewGuid();
            objfbStats.MaleCount = malecount;
            objfbStats.UserId = _facebookAccount.UserId;
            objfbStats.FanCount = getfanCount(objfbStats, _facebookAccount.AccessToken);

            if (objFBStatsRepo.checkFacebookStatsExists(objfbStats.FbUserId.ToString(), objfbStats.UserId, objfbStats.FanCount, objfbStats.MaleCount, objfbStats.FemaleCount))
            {
                objFBStatsRepo.addFacebookStats(objfbStats);
            }


            return true;
        }