/// <updateInstagramUser>
 /// update InstagramUser account.
 /// </summary>
 /// <param name="insaccount">Set Values in a InstagramAccount Class Property and Pass the same Object of InstagramAccount Class.(Domain.InstagramAccount)</param>
 public void updateInstagramUser(Domain.Myfashion.Domain.InstagramAccount insaccount)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             //Proceed action to Update InstagrameAccount
             // And Set the reuired paremeters to find the specific values.
             try
             {
                 session.CreateQuery("Update InstagramAccount set InsUserName =:InsUserName,ProfileUrl=:ProfileUrl,AccessToken =:AccessToken,Followers =:Followers,FollowedBy=:FollowedBy,TotalImages=:TotalImages where InstagramId = :InstagramId and UserId = :userid")
                 .SetParameter("InsUserName", insaccount.InsUserName)
                 .SetParameter("ProfileUrl", insaccount.ProfileUrl)
                 .SetParameter("AccessToken", insaccount.AccessToken)
                 .SetParameter("Followers", insaccount.Followers)
                 .SetParameter("FollowedBy", insaccount.FollowedBy)
                 .SetParameter("TotalImages", insaccount.TotalImages)
                 .SetParameter("InstagramId", insaccount.InstagramId)
                 .SetParameter("userid", insaccount.UserId)
                 .ExecuteUpdate();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 // return 0;
             }
         } //End Transaction
     }     //End session
 }
 /// <getInstagramAccountById>
 /// Get Instagram account from database by InsId(String)
 /// </summary>
 /// <param name="InsId"> InsId InstagramAccount(String)</param>
 /// <returns>Return object of InstagramAccount Class with  value of each member.</returns>
 public Domain.Myfashion.Domain.InstagramAccount getInstagramAccountById(string InsId)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 //Proceed action to get Instagram account from database.
                 NHibernate.IQuery query = session.CreateQuery("from InstagramAccount where  InstagramId = :InstagramId");
                 query.SetParameter("InstagramId", InsId);
                 Domain.Myfashion.Domain.InstagramAccount insAccount = new Domain.Myfashion.Domain.InstagramAccount();
                 foreach (Domain.Myfashion.Domain.InstagramAccount item in query.Enumerable <Domain.Myfashion.Domain.InstagramAccount>())
                 {
                     insAccount = item;
                     break;
                 }
                 return(insAccount);
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 return(null);
             }
         } //End Transaction
     }     //End session
 }
예제 #3
0
        public string AddComment(string UserId, string FeedId, string Text, string InstagramId)
        {
            GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", ConfigurationManager.AppSettings["InstagramClientKey"], ConfigurationManager.AppSettings["InstagramClientSec"], ConfigurationManager.AppSettings["RedirectUrl"], "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
            oAuthInstagram _api = new oAuthInstagram();

            _api = oAuthInstagram.GetInstance(configi);
            objInstagramAccount = objInstagramAccountRepository.getInstagramAccountDetailsById(InstagramId, Guid.Parse(UserId));
            CommentController objComment = new CommentController();

            bool ret = objComment.PostCommentAdd(FeedId, Text, objInstagramAccount.AccessToken);

            return("");
        }
예제 #4
0
 public string UpdateInstagramAccountByAdmin(string ObjInstagram)
 {
     Domain.Myfashion.Domain.InstagramAccount ObjInstagramAccount = (Domain.Myfashion.Domain.InstagramAccount)(new JavaScriptSerializer().Deserialize(ObjInstagram, typeof(Domain.Myfashion.Domain.InstagramAccount)));
     try
     {
         objInstagramAccountRepository.updateInstagramUser(ObjInstagramAccount);
         return(new JavaScriptSerializer().Serialize("Update Successfully"));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.StackTrace);
         return(new JavaScriptSerializer().Serialize("Something went Wrong"));
     }
 }
 /// <addInstagramUser>
 /// add a new account of Instagram for user.
 /// </summary>
 /// <param name="insaccount">Set Values in a InstagramAccount Class Property and Pass the same Object of InstagramAccount Class.(Domain.InstagramAccount)</param>
 public void addInstagramUser(Domain.Myfashion.Domain.InstagramAccount insaccount)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             //Proceed action, to Save data.
             session.Save(insaccount);
             transaction.Commit();
         } //End Transaction
     }     //End session
 }
 /// <getInstagramAccountDetailsById>
 /// Get Instagram Account Details by Insuserid(string) userId(Guid).
 /// </summary>
 /// <param name="Insuserid">Insuserid InstagramAccount(String)</param>
 /// <param name="userId">Insuserid InstagramAccount(Guid)</param>
 /// <returns>Return a object of FacebookMessage Class with  value of each member.</returns>
 public Domain.Myfashion.Domain.InstagramAccount getInstagramAccountDetailsById(string Insuserid, Guid userId)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             //Proceed action to get Instagram Account Details.
             NHibernate.IQuery query = session.CreateQuery("from InstagramAccount where  InstagramId = :InstagramId and UserId = :UserId")
                                       .SetParameter("InstagramId", Insuserid)
                                       .SetParameter("UserId", userId);
             Domain.Myfashion.Domain.InstagramAccount result = (Domain.Myfashion.Domain.InstagramAccount)query.UniqueResult();
             return(result);
         } //End Transaction
     }     //End session
 }
        public string SheduleInstagramMessage(string InstagramId, string UserId, string sscheduledmsgguid)
        {
            string str = string.Empty;
            try
            {
                objScheduledMessage = objScheduledMessageRepository.GetScheduledMessageDetails(Guid.Parse(sscheduledmsgguid));
                objInstagramAccount = objInstagramAccountRepository.getInstagramAccountDetailsById(InstagramId, Guid.Parse(UserId));

                // oAuthInstagram Instagram_oauth = new oAuthInstagram();
                // Instagram_oauth.ConsumerKey = System.Configuration.ConfigurationSettings.AppSettings["LiApiKey"].ToString();
                //Instagram_oauth.
            }
            catch (Exception ex)
            {

                throw;
            }
            return str;
        }
예제 #8
0
        public string SheduleInstagramMessage(string InstagramId, string UserId, string sscheduledmsgguid)
        {
            string str = string.Empty;

            try
            {
                objScheduledMessage = objScheduledMessageRepository.GetScheduledMessageDetails(Guid.Parse(sscheduledmsgguid));
                objInstagramAccount = objInstagramAccountRepository.getInstagramAccountDetailsById(InstagramId, Guid.Parse(UserId));

                // oAuthInstagram Instagram_oauth = new oAuthInstagram();
                // Instagram_oauth.ConsumerKey = System.Configuration.ConfigurationSettings.AppSettings["LiApiKey"].ToString();
                //Instagram_oauth.
            }
            catch (Exception ex)
            {
                throw;
            }
            return(str);
        }
 public Domain.Myfashion.Domain.InstagramAccount getInstagramAccountDetailsById(string Insuserid)
 {
     //Creates a database connection and opens up a session
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         //After Session creation, start Transaction.
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             //Proceed action to get Instagram Account Details.
             List <Domain.Myfashion.Domain.InstagramAccount> objlst = session.CreateQuery("from InstagramAccount where  InstagramId = :InstagramId ")
                                                                      .SetParameter("InstagramId", Insuserid)
                                                                      .List <Domain.Myfashion.Domain.InstagramAccount>().ToList <Domain.Myfashion.Domain.InstagramAccount>();
             Domain.Myfashion.Domain.InstagramAccount result = new Domain.Myfashion.Domain.InstagramAccount();
             if (objlst.Count > 0)
             {
                 result = objlst[0];
             }
             return(result);
         } //End Transaction
     }     //End session
 }
예제 #10
0
        public string InstagramLikeUnLike(string LikeCount, string IsLike, string FeedId, string InstagramId, string UserId)
        {
            string str = string.Empty;

            GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", ConfigurationManager.AppSettings["InstagramClientKey"], ConfigurationManager.AppSettings["InstagramClientSec"], ConfigurationManager.AppSettings["RedirectUrl"], "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
            oAuthInstagram _api = new oAuthInstagram();

            _api = oAuthInstagram.GetInstance(configi);
            try
            {
                objInstagramAccount = objInstagramAccountRepository.getInstagramAccountDetailsById(InstagramId, Guid.Parse(UserId));

                LikesController objlikes   = new LikesController();
                int             islike     = Convert.ToInt32(IsLike);
                int             LikeCounts = Convert.ToInt32(LikeCount);

                if (islike == 0)
                {
                    islike = 1;
                    bool dd = objlikes.PostUserLike(FeedId, objInstagramAccount.AccessToken);
                    LikeCounts++;
                    objInstagramFeedRepository.UpdateLikesOfProfile(FeedId, islike, LikeCounts);
                    str = "unlike";
                }
                else
                {
                    islike = 0;
                    bool i = objlikes.DeleteLike(FeedId, objInstagramAccount.AccessToken);
                    LikeCounts = LikeCounts - 1;
                    objInstagramFeedRepository.UpdateLikesOfProfile(FeedId, islike, LikeCounts);
                    str = "like";
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            return(str);
        }
예제 #11
0
        public string getInstagramData(string UserId, string InstagramId)
        {
            Guid userId = Guid.Parse(UserId);
            InstagramAccountRepository objInstagramAccountRepository = new InstagramAccountRepository();

            //LinkedInAccountRepository objLinkedInAccountRepository = new LinkedInAccountRepository();

            Domain.Myfashion.Domain.InstagramAccount           objInstagramAccount = objInstagramAccountRepository.getInstagramAccountDetailsById(InstagramId, userId);
            GlobusInstagramLib.Authentication.ConfigurationIns configi             = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", ConfigurationManager.AppSettings["InstagramClientKey"], ConfigurationManager.AppSettings["InstagramClientSec"], ConfigurationManager.AppSettings["RedirectUrl"], "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
            oAuthInstagram _api = new oAuthInstagram();

            _api = oAuthInstagram.GetInstance(configi);
            //GetIntagramImages(objInstagramAccount);
            GetInstagramFeeds(objInstagramAccount);
            #region UpdateTeammemberprofile
            Domain.Myfashion.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Myfashion.Domain.TeamMemberProfile();
            objTeamMemberProfile.ProfileName   = objInstagramAccount.InsUserName;
            objTeamMemberProfile.ProfilePicUrl = objInstagramAccount.ProfileUrl;
            objTeamMemberProfile.ProfileId     = objInstagramAccount.InstagramId;
            objTeamMemberProfileRepository.updateTeamMemberbyprofileid(objTeamMemberProfile);
            #endregion
            return("Instagram Info is Updated successfully");
        }
        public string AddComment(string UserId, string FeedId, string Text, string InstagramId)
        {

            GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", ConfigurationManager.AppSettings["InstagramClientKey"], ConfigurationManager.AppSettings["InstagramClientSec"], ConfigurationManager.AppSettings["RedirectUrl"], "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
            oAuthInstagram _api = new oAuthInstagram();
            _api = oAuthInstagram.GetInstance(configi);
            objInstagramAccount = objInstagramAccountRepository.getInstagramAccountDetailsById(InstagramId, Guid.Parse(UserId));
            CommentController objComment = new CommentController();

            bool ret = objComment.PostCommentAdd(FeedId, Text, objInstagramAccount.AccessToken);

            return "";

        
        }
        public string InstagramLikeUnLike(string LikeCount, string IsLike, string FeedId, string InstagramId, string UserId)
        {
            string str = string.Empty;
            GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", ConfigurationManager.AppSettings["InstagramClientKey"], ConfigurationManager.AppSettings["InstagramClientSec"], ConfigurationManager.AppSettings["RedirectUrl"], "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
            oAuthInstagram _api = new oAuthInstagram();
            _api = oAuthInstagram.GetInstance(configi);
            try
            {
                objInstagramAccount = objInstagramAccountRepository.getInstagramAccountDetailsById(InstagramId, Guid.Parse(UserId));

                LikesController objlikes = new LikesController();
                int islike = Convert.ToInt32(IsLike);
                int LikeCounts = Convert.ToInt32(LikeCount);

                if (islike == 0)
                {
                    islike = 1;
                    bool dd = objlikes.PostUserLike(FeedId, objInstagramAccount.AccessToken);
                    LikeCounts++;
                    objInstagramFeedRepository.UpdateLikesOfProfile(FeedId, islike, LikeCounts);
                    str = "unlike";

                }
                else
                {

                    islike = 0;
                    bool i = objlikes.DeleteLike(FeedId, objInstagramAccount.AccessToken);
                    LikeCounts = LikeCounts - 1;
                    objInstagramFeedRepository.UpdateLikesOfProfile(FeedId, islike, LikeCounts);
                    str = "like";

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            return str;
        }
        public string AddInstagramAccount(string client_id, string client_secret, string redirect_uri, string UserId, string GroupId, string code)
        {
            string ret = string.Empty;
            oAuthInstagram objInsta = new oAuthInstagram();
            GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", client_id, client_secret, redirect_uri, "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
            oAuthInstagram _api = new oAuthInstagram();
            _api = oAuthInstagram.GetInstance(configi);
            AccessToken access = new AccessToken();
            access = _api.AuthGetAccessToken(code);
            #region InstagramAccount
            UserController objusercontroller = new UserController();
            InstagramResponse<GlobusInstagramLib.App.Core.User> objuser = objusercontroller.GetUserDetails(access.user.id, access.access_token);
            objInstagramAccount = new Domain.Myfashion.Domain.InstagramAccount();
            objInstagramAccount.AccessToken = access.access_token;
            objInstagramAccount.InstagramId = access.user.id;
            try
            {
                objInstagramAccount.ProfileUrl = access.user.profile_picture;
            }
            catch (Exception ex)
            {
                logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
            }
            try
            {
                objInstagramAccount.InsUserName = access.user.username;
            }
            catch (Exception ex)
            {
                logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
            }
            try
            {
                objInstagramAccount.TotalImages = objuser.data.counts.media;
            }
            catch (Exception ex)
            {
                logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
            }
            try
            {
                objInstagramAccount.FollowedBy = objuser.data.counts.followed_by;
            }
            catch (Exception ex)
            {
                logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
            }
            try
            {
                objInstagramAccount.Followers = objuser.data.counts.follows;
            }
            catch (Exception ex)
            {
                logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
            }
            objInstagramAccount.UserId = Guid.Parse(UserId);
            #endregion


            if (!objInstagramAccountRepository.checkInstagramUserExists(objInstagramAccount.InstagramId, Guid.Parse(UserId)))
            {
                objInstagramAccountRepository.addInstagramUser(objInstagramAccount);
                #region Add TeamMemberProfile
                Domain.Myfashion.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                Domain.Myfashion.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Myfashion.Domain.TeamMemberProfile();
                objTeamMemberProfile.Id = Guid.NewGuid();
                objTeamMemberProfile.TeamId = objTeam.Id;
                objTeamMemberProfile.Status = 1;
                objTeamMemberProfile.ProfileType = "instagram";
                objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                objTeamMemberProfile.ProfileId = objInstagramAccount.InstagramId;

                //Modified [13-02-15]
                objTeamMemberProfile.ProfilePicUrl = objInstagramAccount.ProfileUrl;
                objTeamMemberProfile.ProfileName = objInstagramAccount.InsUserName;

                objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);
                #endregion
                #region SocialProfile
                Domain.Myfashion.Domain.SocialProfile objSocialProfile = new Domain.Myfashion.Domain.SocialProfile();
                objSocialProfile.Id = Guid.NewGuid();
                objSocialProfile.ProfileType = "instagram";
                objSocialProfile.ProfileId = objInstagramAccount.InstagramId;
                objSocialProfile.UserId = Guid.Parse(UserId);
                objSocialProfile.ProfileDate = DateTime.Now;
                objSocialProfile.ProfileStatus = 1;
                #endregion
                #region Add SocialProfile
                if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                {
                    objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                }

                #endregion
                ret = "Account Added Successfully";
            }
            else
            {
                ret = "Account already Exist !";
            }

            //GetIntagramImages(objInstagramAccount);
            GetInstagramFeeds(objInstagramAccount);
            return ret;
        }
예제 #15
0
        public void GetInstagramFeeds(Domain.Myfashion.Domain.InstagramAccount objInsAccount)
        {
            int I = 0;

            try
            {
                GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users();
                InstagramResponse <InstagramMedia[]> userinf2 = userInstagram.CurrentUserFeed("", "", "20", objInsAccount.AccessToken);
                InstagramResponse <Comment[]>        usercmts = new InstagramResponse <Comment[]>();
                objInstagramComment = new Domain.Myfashion.Domain.InstagramComment();
                objInstagramFeed    = new Domain.Myfashion.Domain.InstagramFeed();
                CommentController objComment = new CommentController();
                LikesController   objLikes   = new LikesController();
                if (userinf2 != null)
                {
                    for (int j = 0; j < userinf2.data.Count(); j++)
                    {
                        try
                        {
                            objInstagramFeed.EntryDate = DateTime.Now;
                            try
                            {
                                objInstagramFeed.FeedDate = userinf2.data[j].created_time.ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedId = userinf2.data[j].id;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString();
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.InstagramId = objInsAccount.InstagramId;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.LikeCount = userinf2.data[j].likes.count;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.CommentCount = userinf2.data[j].comments.count;
                            }
                            catch { }
                            try
                            {
                                string str = userinf2.data[j].user_has_liked.ToString();
                                if (str == "False")
                                {
                                    objInstagramFeed.IsLike = 0;
                                }
                                else
                                {
                                    objInstagramFeed.IsLike = 1;
                                }
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.AdminUser = userinf2.data[j].caption.from.username;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.Feed = userinf2.data[j].caption.text;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.ImageUrl = userinf2.data[j].caption.from.profile_picture;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FromId = userinf2.data[j].caption.from.id;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.FeedUrl = userinf2.data[j].link;
                            }
                            catch { }
                            try
                            {
                                objInstagramFeed.UserId = objInsAccount.UserId;
                            }
                            catch { }
                            if (!objInstagramFeedRepository.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId))
                            {
                                I++;
                                objInstagramFeedRepository.addInstagramFeed(objInstagramFeed);
                                logger.Error("GetInstagramFeedsCount>>>" + I);
                            }

                            usercmts = objComment.GetComment(userinf2.data[j].id, objInsAccount.AccessToken);
                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                try
                                {
                                    try
                                    {
                                        objInstagramComment.Comment = usercmts.data[cmt].text;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.CommentDate = usercmts.data[cmt].created_time.ToString();
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.CommentId = usercmts.data[cmt].id;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.EntryDate = DateTime.Now;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FeedId = userinf2.data[j].id;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.Id = Guid.NewGuid();
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.InstagramId = objInsAccount.InstagramId;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.UserId = objInsAccount.UserId;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FromName = usercmts.data[cmt].from.username;
                                    }
                                    catch { }
                                    try
                                    {
                                        objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                    }
                                    catch { }
                                    if (!objInstagramCommentRepository.checkInstagramCommentExists(usercmts.data[cmt].id, objInsAccount.UserId))
                                    {
                                        objInstagramCommentRepository.addInstagramComment(objInstagramComment);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                    Console.WriteLine(ex.StackTrace);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
            }
        }
        public Domain.Myfashion.Domain.InstagramAccount getInstagramAccountDetailsById(string Insuserid)
        {
            //Creates a database connection and opens up a session
            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                //After Session creation, start Transaction.
                using (NHibernate.ITransaction transaction = session.BeginTransaction())
                {

                    //Proceed action to get Instagram Account Details.
                    List<Domain.Myfashion.Domain.InstagramAccount> objlst = session.CreateQuery("from InstagramAccount where  InstagramId = :InstagramId ")
                     .SetParameter("InstagramId", Insuserid)
                    .List<Domain.Myfashion.Domain.InstagramAccount>().ToList<Domain.Myfashion.Domain.InstagramAccount>();
                    Domain.Myfashion.Domain.InstagramAccount result = new Domain.Myfashion.Domain.InstagramAccount();
                    if (objlst.Count > 0)
                    {
                        result = objlst[0];
                    }
                    return result;
                }//End Transaction
            }//End session
        }
        /// <getInstagramAccountById>
        /// Get Instagram account from database by InsId(String)
        /// </summary>
        /// <param name="InsId"> InsId InstagramAccount(String)</param>
        /// <returns>Return object of InstagramAccount Class with  value of each member.</returns>
        public Domain.Myfashion.Domain.InstagramAccount getInstagramAccountById(string InsId)
        {
            //Creates a database connection and opens up a session
            using (NHibernate.ISession session = SessionFactory.GetNewSession())
            {
                //After Session creation, start Transaction.
                using (NHibernate.ITransaction transaction = session.BeginTransaction())
                {
                    try
                    {

                        //Proceed action to get Instagram account from database.
                        NHibernate.IQuery query = session.CreateQuery("from InstagramAccount where  InstagramId = :InstagramId");
                        query.SetParameter("InstagramId", InsId);
                        Domain.Myfashion.Domain.InstagramAccount insAccount = new Domain.Myfashion.Domain.InstagramAccount();
                        foreach (Domain.Myfashion.Domain.InstagramAccount item in query.Enumerable<Domain.Myfashion.Domain.InstagramAccount>())
                        {
                            insAccount = item;
                            break;
                        }
                        return insAccount;

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

                }//End Transaction
            }//End session

        }
예제 #18
0
        public string GetIntagramImages(Domain.Myfashion.Domain.InstagramAccount objInsAccount)
        {
            {
                InstagramResponse <GlobusInstagramLib.App.Core.User[]> userinf  = new InstagramResponse <GlobusInstagramLib.App.Core.User[]>();
                InstagramResponse <GlobusInstagramLib.App.Core.User[]> userinf1 = new InstagramResponse <GlobusInstagramLib.App.Core.User[]>();
                InstagramResponse <InstagramMedia[]> userinf2 = new InstagramResponse <InstagramMedia[]>();
                InstagramResponse <Comment[]>        usercmts = new InstagramResponse <Comment[]>();
                MediaController   objMedia   = new MediaController();
                CommentController objComment = new CommentController();
                LikesController   objLikes   = new LikesController();
                objInstagramComment = new Domain.Myfashion.Domain.InstagramComment();
                objInstagramFeed    = new Domain.Myfashion.Domain.InstagramFeed();
                string   html          = string.Empty;
                int      i             = 0;
                string[] allhtmls      = new string[0];
                int      countofimages = 0;
                GlobusInstagramLib.Instagram.Core.UsersMethods.Users userInstagram = new GlobusInstagramLib.Instagram.Core.UsersMethods.Users();
                try
                {
                    userinf2 = userInstagram.UserRecentMedia(objInsAccount.InstagramId, string.Empty, string.Empty, "20", string.Empty, string.Empty, objInsAccount.AccessToken);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }


                if (userinf2 != null)
                {
                    for (int j = 0; j < userinf2.data.Count(); j++)
                    {
                        try
                        {
                            usercmts = objComment.GetComment(userinf2.data[j].id, objInsAccount.AccessToken);
                            bool liked = false;
                            try
                            {
                                //liked = objLikes.LikeToggle(userinf2.data[j].id, objInsAccount.InstagramId, objInsAccount.AccessToken);
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            int n = usercmts.data.Count();
                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                try
                                {
                                    objInstagramComment.Comment        = Uri.EscapeDataString(usercmts.data[cmt].text);
                                    objInstagramComment.CommentDate    = usercmts.data[cmt].created_time.ToString();
                                    objInstagramComment.CommentId      = usercmts.data[cmt].id;
                                    objInstagramComment.EntryDate      = DateTime.Now;
                                    objInstagramComment.FeedId         = userinf2.data[j].id;
                                    objInstagramComment.Id             = Guid.NewGuid();
                                    objInstagramComment.InstagramId    = objInsAccount.InstagramId;
                                    objInstagramComment.UserId         = objInsAccount.UserId;
                                    objInstagramComment.FromName       = usercmts.data[cmt].from.full_name;
                                    objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                    if (!objInstagramCommentRepository.checkInstagramCommentExists(usercmts.data[cmt].id, objInsAccount.UserId))
                                    {
                                        objInstagramCommentRepository.addInstagramComment(objInstagramComment);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                    Console.WriteLine(ex.StackTrace);
                                }
                            }
                            objInstagramFeed.EntryDate = DateTime.Now;
                            try
                            {
                                objInstagramFeed.FeedDate = userinf2.data[j].created_time.ToString();
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.FeedId = userinf2.data[j].id;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString();
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.InstagramId = objInsAccount.InstagramId;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.LikeCount = userinf2.data[j].likes.count;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.UserId = objInsAccount.UserId;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                objInstagramFeed.CommentCount = userinf2.data[j].comments.count;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            try
                            {
                                string str = userinf2.data[j].user_has_liked.ToString();

                                if (str == "False")
                                {
                                    objInstagramFeed.IsLike = 0;
                                }
                                else
                                {
                                    objInstagramFeed.IsLike = 1;
                                }
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }


                            try
                            {
                                objInstagramFeed.AdminUser = userinf2.data[j].caption.from.username;
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }


                            if (!objInstagramFeedRepository.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId))
                            {
                                objInstagramFeedRepository.addInstagramFeed(objInstagramFeed);
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.StackTrace);
                        }
                        i++;
                    }
                }

                try
                {
                    userinf2 = userInstagram.CurrentUserFeed(string.Empty, string.Empty, "20", objInsAccount.AccessToken);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.StackTrace);
                }


                if (userinf2 != null)
                {
                    for (int j = 0; j < userinf2.data.Count(); j++)
                    {
                        try
                        {
                            usercmts = objComment.GetComment(userinf2.data[j].id, objInsAccount.AccessToken);
                            bool liked = false;
                            try
                            {
                                // liked = objLikes.LikeToggle(userinf2.data[j].id, objInsAccount.InstagramId, objInsAccount.AccessToken);
                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex.StackTrace);
                            }
                            int n = usercmts.data.Count();
                            for (int cmt = 0; cmt < usercmts.data.Count(); cmt++)
                            {
                                try
                                {
                                    objInstagramComment.Comment        = Uri.EscapeDataString(usercmts.data[cmt].text);
                                    objInstagramComment.CommentDate    = usercmts.data[cmt].created_time.ToString();
                                    objInstagramComment.CommentId      = usercmts.data[cmt].id;
                                    objInstagramComment.EntryDate      = DateTime.Now;
                                    objInstagramComment.FeedId         = userinf2.data[j].id;
                                    objInstagramComment.Id             = Guid.NewGuid();
                                    objInstagramComment.InstagramId    = objInsAccount.InstagramId;
                                    objInstagramComment.UserId         = objInsAccount.UserId;
                                    objInstagramComment.FromName       = usercmts.data[cmt].from.full_name;
                                    objInstagramComment.FromProfilePic = usercmts.data[cmt].from.profile_picture;
                                    if (!objInstagramCommentRepository.checkInstagramCommentExists(usercmts.data[cmt].id, objInsAccount.UserId))
                                    {
                                        objInstagramCommentRepository.addInstagramComment(objInstagramComment);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    logger.Error(ex.StackTrace);
                                    Console.WriteLine(ex.StackTrace);
                                }
                            }
                            objInstagramFeed.EntryDate    = DateTime.Now;
                            objInstagramFeed.FeedDate     = userinf2.data[j].created_time.ToString();
                            objInstagramFeed.FeedId       = userinf2.data[j].id;
                            objInstagramFeed.FeedImageUrl = userinf2.data[j].images.low_resolution.url.ToString();
                            objInstagramFeed.InstagramId  = objInsAccount.InstagramId;
                            objInstagramFeed.LikeCount    = userinf2.data[j].likes.count;
                            objInstagramFeed.CommentCount = userinf2.data[j].comments.count;
                            string str = userinf2.data[j].user_has_liked.ToString();
                            if (str == "False")
                            {
                                objInstagramFeed.IsLike = 0;
                            }
                            else
                            {
                                objInstagramFeed.IsLike = 1;
                            }
                            objInstagramFeed.AdminUser = userinf2.data[j].caption.from.username + "-" + userinf2.data[j].caption.from.full_name;

                            objInstagramFeed.UserId = objInsAccount.UserId;
                            if (!objInstagramFeedRepository.checkInstagramFeedExists(userinf2.data[j].id, objInsAccount.UserId))
                            {
                                objInstagramFeedRepository.addInstagramFeed(objInstagramFeed);
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex.StackTrace);
                        }
                        i++;
                    }
                }

                i++;

                string totalhtml = string.Empty;
                try
                {
                    for (int k = 0; k < countofimages; k++)
                    {
                        totalhtml = totalhtml + allhtmls[k];
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                // Session["AllHtmls"] = allhtmls;
                return(totalhtml);
            }
        }
예제 #19
0
        public string AddInstagramAccount(string client_id, string client_secret, string redirect_uri, string UserId, string GroupId, string code)
        {
            string         ret      = string.Empty;
            oAuthInstagram objInsta = new oAuthInstagram();

            GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", client_id, client_secret, redirect_uri, "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
            oAuthInstagram _api = new oAuthInstagram();

            _api = oAuthInstagram.GetInstance(configi);
            AccessToken access = new AccessToken();

            access = _api.AuthGetAccessToken(code);
            #region InstagramAccount
            UserController objusercontroller = new UserController();
            InstagramResponse <GlobusInstagramLib.App.Core.User> objuser = objusercontroller.GetUserDetails(access.user.id, access.access_token);
            objInstagramAccount             = new Domain.Myfashion.Domain.InstagramAccount();
            objInstagramAccount.AccessToken = access.access_token;
            objInstagramAccount.InstagramId = access.user.id;
            try
            {
                objInstagramAccount.ProfileUrl = access.user.profile_picture;
            }
            catch (Exception ex)
            {
                logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
            }
            try
            {
                objInstagramAccount.InsUserName = access.user.username;
            }
            catch (Exception ex)
            {
                logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
            }
            try
            {
                objInstagramAccount.TotalImages = objuser.data.counts.media;
            }
            catch (Exception ex)
            {
                logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
            }
            try
            {
                objInstagramAccount.FollowedBy = objuser.data.counts.followed_by;
            }
            catch (Exception ex)
            {
                logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
            }
            try
            {
                objInstagramAccount.Followers = objuser.data.counts.follows;
            }
            catch (Exception ex)
            {
                logger.Error("Instagram.asmx.cs >> AddInstagramAccount >> " + ex.StackTrace);
            }
            objInstagramAccount.UserId = Guid.Parse(UserId);
            #endregion


            if (!objInstagramAccountRepository.checkInstagramUserExists(objInstagramAccount.InstagramId, Guid.Parse(UserId)))
            {
                objInstagramAccountRepository.addInstagramUser(objInstagramAccount);
                #region Add TeamMemberProfile
                Domain.Myfashion.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId));
                Domain.Myfashion.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Myfashion.Domain.TeamMemberProfile();
                objTeamMemberProfile.Id               = Guid.NewGuid();
                objTeamMemberProfile.TeamId           = objTeam.Id;
                objTeamMemberProfile.Status           = 1;
                objTeamMemberProfile.ProfileType      = "instagram";
                objTeamMemberProfile.StatusUpdateDate = DateTime.Now;
                objTeamMemberProfile.ProfileId        = objInstagramAccount.InstagramId;

                //Modified [13-02-15]
                objTeamMemberProfile.ProfilePicUrl = objInstagramAccount.ProfileUrl;
                objTeamMemberProfile.ProfileName   = objInstagramAccount.InsUserName;

                objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile);
                #endregion
                #region SocialProfile
                Domain.Myfashion.Domain.SocialProfile objSocialProfile = new Domain.Myfashion.Domain.SocialProfile();
                objSocialProfile.Id            = Guid.NewGuid();
                objSocialProfile.ProfileType   = "instagram";
                objSocialProfile.ProfileId     = objInstagramAccount.InstagramId;
                objSocialProfile.UserId        = Guid.Parse(UserId);
                objSocialProfile.ProfileDate   = DateTime.Now;
                objSocialProfile.ProfileStatus = 1;
                #endregion
                #region Add SocialProfile
                if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile))
                {
                    objSocialProfilesRepository.addNewProfileForUser(objSocialProfile);
                }

                #endregion
                ret = "Account Added Successfully";
            }
            else
            {
                ret = "Account already Exist !";
            }

            //GetIntagramImages(objInstagramAccount);
            GetInstagramFeeds(objInstagramAccount);
            return(ret);
        }