public void updateYoutubeUser(Domain.Socioboard.Domain.YoutubeAccount youtubeAccount) { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { session.CreateQuery("Update YoutubeAccount set YtUserName =:Ytusername,YtUserId=:Ytuserid,YtProfileImage=:Ytprofileimage,AccessToken=:Accesstoken,RefreshToken=:Refreshtoken,IsActive=:IsActive,EmailId=:Emailid,EntryDate=:Entrydate,UserId=:UserId where YtUserId =:Ytuserid and UserId = :UserId") .SetParameter("Ytusername", youtubeAccount.Ytusername) .SetParameter("Ytuserid", youtubeAccount.Ytuserid) .SetParameter("Accesstoken", youtubeAccount.Accesstoken) .SetParameter("Refreshtoken", youtubeAccount.Refreshtoken) .SetParameter("UserId", youtubeAccount.UserId) .SetParameter("Emailid", youtubeAccount.Emailid) .SetParameter("Entrydate", youtubeAccount.Entrydate) .SetParameter("Ytprofileimage", youtubeAccount.Ytprofileimage) .SetParameter("IsActive", "1") .ExecuteUpdate(); transaction.Commit(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); // return 0; } } } }
public bool checkTubmlrUserExists(Domain.Socioboard.Domain.YoutubeAccount objTumblrAccount) { //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 Check if FacebookUser is Exist in database or not by UserId and FbuserId. // And Set the reuired paremeters to find the specific values. NHibernate.IQuery query = session.CreateQuery("from YoutubeAccount where UserId = :uidd and YtUserId = :tbuname"); query.SetParameter("uidd", objTumblrAccount.UserId); query.SetParameter("tbuname", objTumblrAccount.Ytuserid); var result = query.UniqueResult(); if (result == null) { return(false); } else { return(true); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(true); } } //End Transaction } //End session }
public string UpdateYouTubeAccountByAdmin(string ObjYouTube) { Domain.Socioboard.Domain.YoutubeAccount ObjYouTubeAccount = (Domain.Socioboard.Domain.YoutubeAccount)(new JavaScriptSerializer().Deserialize(ObjYouTube, typeof(Domain.Socioboard.Domain.YoutubeAccount))); try { objYoutubeAccountRepository.updateYoutubeUser(ObjYouTubeAccount); return(new JavaScriptSerializer().Serialize("Update Successfully")); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(new JavaScriptSerializer().Serialize("Something went Wrong")); } }
public string GetData(object UserId,string youtubeId ) { string ret = string.Empty; Guid userId = (Guid)UserId; YoutubeAccount ObjYoutubeAccount = new YoutubeAccount(); Api.YoutubeAccount.YoutubeAccount ApiObjYoutubeAccount = new Api.YoutubeAccount.YoutubeAccount(); List<Domain.Socioboard.Domain.YoutubeAccount> LstYoutubeAccount = (List<Domain.Socioboard.Domain.YoutubeAccount>)(new JavaScriptSerializer().Deserialize(ApiObjYoutubeAccount.GetAllYoutubeAccountDetailsById(userId.ToString()), typeof(List<Domain.Socioboard.Domain.YoutubeAccount>))); List<YoutubeAccount> lstYoutubeAccount = new List<YoutubeAccount>(); foreach (YoutubeAccount Lstitem in LstYoutubeAccount) { Api.Youtube.Youtube ApiObjYoutube = new Api.Youtube.Youtube(); ret= ApiObjYoutube.getYoutubeData(Lstitem.UserId.ToString(), Lstitem.Ytuserid); } return ret; }
public string SheduleYoutubeMessage(string YoutubeId, string UserId, string sscheduledmsgguid) { string str = string.Empty; try { objScheduledMessage = objScheduledMessageRepository.GetScheduledMessageDetails(Guid.Parse(sscheduledmsgguid)); Domain.Socioboard.Domain.YoutubeAccount ObjYoutubeAccount = objYoutubeAccountRepository.getYoutubeAccountDetailsById(YoutubeId, Guid.Parse(UserId)); oAuthToken OAuthToken = new oAuthToken(); OAuthToken.ConsumerKey = ConfigurationManager.AppSettings["YtconsumerKey"]; OAuthToken.ConsumerSecret = ConfigurationManager.AppSettings["YtconsumerSecret"]; } catch (Exception ex) { throw; } return(str); }
public string getYoutubeData(string UserId, string youtubeId) { string ret = string.Empty; try { Guid userId = Guid.Parse(UserId); oAuthToken OAuthToken = new oAuthToken(); OAuthToken.ConsumerKey = ConfigurationManager.AppSettings["YtconsumerKey"]; OAuthToken.ConsumerSecret = ConfigurationManager.AppSettings["YtconsumerSecret"]; YoutubeAccountRepository ObjYoutubeAccountRepository = new YoutubeAccountRepository(); Domain.Socioboard.Domain.YoutubeAccount ObjYoutubeAccount = ObjYoutubeAccountRepository.getYoutubeAccountDetailsById(youtubeId, userId); AddYouTubeChannels(userId.ToString(), ObjYoutubeAccount.Accesstoken, youtubeId); return("Youtube Channel is added"); } catch (Exception ex) { throw; } }
public static void Add(Domain.Socioboard.Domain.YoutubeAccount YoutubeAccount) { //Creates a database connection and opens up a session using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start and open Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { //Proceed action to save data. try { session.Save(YoutubeAccount); transaction.Commit(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } //End Using trasaction } //End Using session }
public Domain.Socioboard.Domain.YoutubeAccount getYoutubeAccountDetailsById(string youtubeId) { Domain.Socioboard.Domain.YoutubeAccount result = new Domain.Socioboard.Domain.YoutubeAccount(); //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 all Facebook Account of User by UserId(Guid) and FbUserId(string). List <Domain.Socioboard.Domain.YoutubeAccount> objlstfb = session.CreateQuery("from YoutubeAccount where YtUserId = :Fbuserid ") .SetParameter("Fbuserid", youtubeId) .List <Domain.Socioboard.Domain.YoutubeAccount>().ToList <Domain.Socioboard.Domain.YoutubeAccount>(); if (objlstfb.Count > 0) { result = objlstfb[0]; } return(result); } //End Transaction } //End session }
public string GetYoutubeChannelVideos(string userid, string profileid) { string ret = string.Empty; string strfinaltoken = string.Empty; string channelDetails = string.Empty; Domain.Socioboard.Domain.YoutubeAccount objYoutubeAccount = objYoutubeAccountRepository.getYoutubeAccountDetailsById(profileid, Guid.Parse(userid)); Domain.Socioboard.Domain.YoutubeChannel objYoutubeChannel = objYoutubeChannelRepository.getYoutubeChannelDetailsById(profileid, Guid.Parse(userid)); oAuthTokenYoutube objoAuthTokenYoutube = new oAuthTokenYoutube(); string finaltoken = objoAuthTokenYoutube.GetAccessToken(objYoutubeAccount.Refreshtoken); JObject objArray = JObject.Parse(finaltoken); //foreach (var item in objArray) //{ try { strfinaltoken = objArray["access_token"].ToString(); // break; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } //} PlaylistItems objPlaylistItems = new PlaylistItems(); try { channelDetails = objPlaylistItems.Get_PlaylistItems_List(strfinaltoken, GlobusGooglePlusLib.Authentication.oAuthTokenYoutube.Parts.snippet.ToString(), objYoutubeChannel.Uploadsid); } catch (Exception ex) { } return(channelDetails); }
public string AddYoutubeAccount(string client_id, string client_secret, string redirect_uri, string UserId, string GroupId, string code) { #region Local variables Inisitalisation string ret = string.Empty; string objRefresh = string.Empty; string refreshToken = string.Empty; string access_token = string.Empty; oAuthTokenYoutube ObjoAuthTokenYoutube = new oAuthTokenYoutube(); oAuthToken objToken = new oAuthToken(); Domain.Socioboard.Domain.YoutubeAccount objYoutubeAccount = new Domain.Socioboard.Domain.YoutubeAccount(); Domain.Socioboard.Domain.YoutubeChannel objYoutubeChannel; YoutubeChannelRepository objYoutubeChannelRepository = new YoutubeChannelRepository(); YoutubeAccountRepository objYoutubeAccountRepository = new YoutubeAccountRepository(); #endregion #region Get AccessToken and RefreshToken objToken.ConsumerKey = client_id; objToken.ConsumerSecret = client_secret; try { objRefresh = ObjoAuthTokenYoutube.GetRefreshToken(code, client_id, client_secret, redirect_uri); logger.Error("Abhay: ObjoAuthTokenYoutube()"); } catch (Exception ex) { logger.Error(ex.Message); logger.Error(ex.StackTrace); } JObject objaccesstoken = JObject.Parse(objRefresh); try { refreshToken = objaccesstoken["refresh_token"].ToString(); } catch (Exception ex) { access_token = objaccesstoken["access_token"].ToString(); ObjoAuthTokenYoutube.RevokeToken(access_token); Console.WriteLine(ex.StackTrace); return "Refresh Token Not Found"; } try { access_token = objaccesstoken["access_token"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } #endregion #region Get user Profile and Add Youtube Account JArray userinfo = new JArray(); try { userinfo = objToken.GetUserInfo("me", access_token.ToString()); } catch (Exception ex) { } foreach (var itemEmail in userinfo) { try { objYoutubeAccount.Id = Guid.NewGuid(); objYoutubeAccount.Ytuserid = itemEmail["id"].ToString(); objYoutubeAccount.Emailid = itemEmail["email"].ToString(); try { objYoutubeAccount.Ytusername = itemEmail["given_name"].ToString(); } catch (Exception ex) { objYoutubeAccount.Ytusername = itemEmail["name"].ToString(); } objYoutubeAccount.Ytprofileimage = itemEmail["picture"].ToString(); objYoutubeAccount.Accesstoken = access_token; objYoutubeAccount.Refreshtoken = refreshToken; objYoutubeAccount.Isactive = 1; objYoutubeAccount.Entrydate = DateTime.Now; objYoutubeAccount.UserId = Guid.Parse(UserId); if (!objYoutubeAccountRepository.checkYoutubeUserExists(objYoutubeAccount)) { YoutubeAccountRepository.Add(objYoutubeAccount); ret = "Account Added Successfully"; } else { ret = "Account already Exist !"; } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } #endregion #region Add Youtube Channels GlobusGooglePlusLib.Youtube.Core.Channels ObjChannel = new GlobusGooglePlusLib.Youtube.Core.Channels(); JArray objarray = new JArray(); try { string part = (oAuthTokenYoutube.Parts.contentDetails.ToString() + "," + oAuthTokenYoutube.Parts.statistics.ToString()); string Value = ObjChannel.Get_Channel_List(access_token, part, 50, true); JObject UserChannels = JObject.Parse(@Value); objarray = (JArray)UserChannels["items"]; } catch (Exception ex) { } foreach (var item in objarray) { objYoutubeChannel = new Domain.Socioboard.Domain.YoutubeChannel(); try { objYoutubeChannel.Id = Guid.NewGuid(); objYoutubeChannel.Channelid = item["id"].ToString(); objYoutubeChannel.Likesid = item["contentDetails"]["relatedPlaylists"]["likes"].ToString(); objYoutubeChannel.Favoritesid = item["contentDetails"]["relatedPlaylists"]["favorites"].ToString(); objYoutubeChannel.Uploadsid = item["contentDetails"]["relatedPlaylists"]["uploads"].ToString(); objYoutubeChannel.Watchhistoryid = item["contentDetails"]["relatedPlaylists"]["watchHistory"].ToString(); objYoutubeChannel.Watchlaterid = item["contentDetails"]["relatedPlaylists"]["watchLater"].ToString(); objYoutubeChannel.Googleplususerid = objYoutubeAccount.Ytuserid; objYoutubeChannel.UserId = Guid.Parse(UserId); try { string viewcnt = item["statistics"]["viewCount"].ToString(); objYoutubeChannel.ViewCount = Convert.ToInt32(viewcnt); string videocnt = item["statistics"]["videoCount"].ToString(); objYoutubeChannel.VideoCount = Convert.ToInt32(videocnt); string commentcnt = item["statistics"]["commentCount"].ToString(); objYoutubeChannel.CommentCount = Convert.ToInt32(commentcnt); string Subscribercnt = item["statistics"]["subscriberCount"].ToString(); objYoutubeChannel.SubscriberCount = Convert.ToInt32(Subscribercnt); try { string str = item["statistics"]["hiddenSubscriberCount"].ToString(); if (str == "false") { objYoutubeChannel.HiddenSubscriberCount = 0; } else { objYoutubeChannel.HiddenSubscriberCount = 1; } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } if (!objYoutubeChannelRepository.checkYoutubeChannelExists(objYoutubeChannel.Channelid, Guid.Parse(UserId))) { YoutubeChannelRepository.Add(objYoutubeChannel); } } #endregion #region Add TeamMemberProfile Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId)); Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile(); objTeamMemberProfile.Id = Guid.NewGuid(); objTeamMemberProfile.TeamId = objTeam.Id; objTeamMemberProfile.Status = 1; objTeamMemberProfile.ProfileType = "youtube"; objTeamMemberProfile.StatusUpdateDate = DateTime.Now; objTeamMemberProfile.ProfileId = objYoutubeAccount.Ytuserid; objTeamMemberProfile.ProfileName = objYoutubeAccount.Ytusername; objTeamMemberProfile.ProfilePicUrl = objYoutubeAccount.Ytprofileimage; if (!objTeamMemberProfileRepository.checkTeamMemberProfile(objTeam.Id, objYoutubeAccount.Ytuserid)) { objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile); } #endregion #region SocialProfile Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile(); objSocialProfile.Id = Guid.NewGuid(); objSocialProfile.ProfileType = "youtube"; objSocialProfile.ProfileId = objYoutubeAccount.Ytuserid; objSocialProfile.UserId = Guid.Parse(UserId); objSocialProfile.ProfileDate = DateTime.Now; objSocialProfile.ProfileStatus = 1; if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile)) { objSocialProfilesRepository.addNewProfileForUser(objSocialProfile); } #endregion return ret; }
public Domain.Socioboard.Domain.YoutubeAccount getYoutubeAccountDetailsById(string youtubeId,Guid userid) { Domain.Socioboard.Domain.YoutubeAccount result = new Domain.Socioboard.Domain.YoutubeAccount(); //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 all Facebook Account of User by UserId(Guid) and FbUserId(string). List<Domain.Socioboard.Domain.YoutubeAccount> objlstfb = session.CreateQuery("from YoutubeAccount where YtUserId = :Fbuserid and UserId=:userid") .SetParameter("Fbuserid", youtubeId) .SetParameter("userid", userid) .List<Domain.Socioboard.Domain.YoutubeAccount>().ToList<Domain.Socioboard.Domain.YoutubeAccount>(); if (objlstfb.Count > 0) { result = objlstfb[0]; } return result; }//End Transaction }//End session }
public string ProfilesConnected(string UserId) { try { Guid userid = Guid.Parse(UserId); SocialProfilesRepository socialRepo = new SocialProfilesRepository(); List <Domain.Socioboard.Domain.SocialProfile> lstsocioprofile = socialRepo.getAllSocialProfilesOfUser(userid); List <profileConnected> lstProfile = new List <profileConnected>(); foreach (Domain.Socioboard.Domain.SocialProfile sp in lstsocioprofile) { profileConnected pc = new profileConnected(); pc.Id = sp.Id; pc.ProfileDate = sp.ProfileDate; pc.ProfileId = sp.ProfileId; pc.ProfileStatus = sp.ProfileStatus; pc.ProfileType = sp.ProfileType; pc.UserId = sp.UserId; if (sp.ProfileType == "facebook") { try { FacebookAccountRepository objFbAccRepo = new FacebookAccountRepository(); Domain.Socioboard.Domain.FacebookAccount objFbAcc = objFbAccRepo.getUserDetails(sp.ProfileId); pc.ProfileName = objFbAcc.FbUserName; pc.ProfileImgUrl = "http://graph.facebook.com/" + sp.ProfileId + "/picture?type=small"; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } else if (sp.ProfileType == "twitter") { try { TwitterAccountRepository objTwtAccRepo = new TwitterAccountRepository(); Domain.Socioboard.Domain.TwitterAccount objTwtAcc = objTwtAccRepo.getUserInfo(sp.ProfileId); pc.ProfileName = objTwtAcc.TwitterScreenName; pc.ProfileImgUrl = objTwtAcc.ProfileImageUrl; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } else if (sp.ProfileType == "instagram") { try { InstagramAccountRepository objInsAccRepo = new InstagramAccountRepository(); Domain.Socioboard.Domain.InstagramAccount objInsAcc = objInsAccRepo.getInstagramAccountById(sp.ProfileId); pc.ProfileName = objInsAcc.InsUserName; pc.ProfileImgUrl = objInsAcc.ProfileUrl; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } else if (sp.ProfileType == "linkedin") { try { LinkedInAccountRepository objLiAccRepo = new LinkedInAccountRepository(); Domain.Socioboard.Domain.LinkedInAccount objLiAcc = objLiAccRepo.getLinkedinAccountDetailsById(sp.ProfileId); pc.ProfileName = objLiAcc.LinkedinUserName; pc.ProfileImgUrl = objLiAcc.ProfileImageUrl; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } else if (sp.ProfileType == "googleplus") { try { GooglePlusAccountRepository objGpAccRepo = new GooglePlusAccountRepository(); Domain.Socioboard.Domain.GooglePlusAccount objGpAcc = objGpAccRepo.getUserDetails(sp.ProfileId); pc.ProfileName = objGpAcc.GpUserName; pc.ProfileImgUrl = objGpAcc.GpProfileImage; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } else if (sp.ProfileType == "tumblr") { try { TumblrAccountRepository objTumblrAccountRepository = new TumblrAccountRepository(); Domain.Socioboard.Domain.TumblrAccount objTumblrAccount = objTumblrAccountRepository.getTumblrAccountDetailsById(sp.ProfileId); pc.ProfileName = objTumblrAccount.tblrUserName; pc.ProfileImgUrl = objTumblrAccount.tblrProfilePicUrl; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } else if (sp.ProfileType == "youtube") { try { YoutubeAccountRepository objYoutubeAccountRepository = new YoutubeAccountRepository(); Domain.Socioboard.Domain.YoutubeAccount objYoutubeAccount = objYoutubeAccountRepository.getYoutubeAccountDetailsById(sp.ProfileId); pc.ProfileName = objYoutubeAccount.Ytusername; pc.ProfileImgUrl = objYoutubeAccount.Ytprofileimage; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } lstProfile.Add(pc); } return(new JavaScriptSerializer().Serialize(lstProfile)); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(new JavaScriptSerializer().Serialize("Please Try Again")); } }
public string AddYoutubeAccountwithLogin(string client_id, string client_secret, string redirect_uri, string UserId, string GroupId, string access_token) { #region Local variables Inisitalisation string ret = string.Empty; string objRefresh = string.Empty; string refreshToken = string.Empty; oAuthTokenYoutube ObjoAuthTokenYoutube = new oAuthTokenYoutube(); oAuthToken objToken = new oAuthToken(); Domain.Socioboard.Domain.YoutubeAccount objYoutubeAccount = new Domain.Socioboard.Domain.YoutubeAccount(); Domain.Socioboard.Domain.YoutubeChannel objYoutubeChannel; YoutubeChannelRepository objYoutubeChannelRepository = new YoutubeChannelRepository(); YoutubeAccountRepository objYoutubeAccountRepository = new YoutubeAccountRepository(); #endregion #region Get user Profile and Add Youtube Account JArray userinfo = new JArray(); try { userinfo = objToken.GetUserInfo("me", access_token.ToString()); } catch (Exception ex) { } foreach (var itemEmail in userinfo) { try { objYoutubeAccount.Id = Guid.NewGuid(); objYoutubeAccount.Ytuserid = itemEmail["id"].ToString(); objYoutubeAccount.Emailid = itemEmail["email"].ToString(); try { objYoutubeAccount.Ytusername = itemEmail["given_name"].ToString(); } catch (Exception ex) { objYoutubeAccount.Ytusername = itemEmail["name"].ToString(); } objYoutubeAccount.Ytprofileimage = itemEmail["picture"].ToString(); objYoutubeAccount.Accesstoken = access_token; objYoutubeAccount.Refreshtoken = refreshToken; objYoutubeAccount.Isactive = 1; objYoutubeAccount.Entrydate = DateTime.Now; objYoutubeAccount.UserId = Guid.Parse(UserId); if (!objYoutubeAccountRepository.checkYoutubeUserExists(objYoutubeAccount)) { YoutubeAccountRepository.Add(objYoutubeAccount); ret = "Account Added Successfully"; } else { ret = "Account already Exist !"; } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } #endregion #region Add Youtube Channels GlobusGooglePlusLib.Youtube.Core.Channels ObjChannel = new GlobusGooglePlusLib.Youtube.Core.Channels(); JArray objarray = new JArray(); try { string part = (oAuthTokenYoutube.Parts.contentDetails.ToString() + "," + oAuthTokenYoutube.Parts.statistics.ToString()); string Value = ObjChannel.Get_Channel_List(access_token, part, 50, true); JObject UserChannels = JObject.Parse(@Value); objarray = (JArray)UserChannels["items"]; } catch (Exception ex) { } foreach (var item in objarray) { objYoutubeChannel = new Domain.Socioboard.Domain.YoutubeChannel(); try { objYoutubeChannel.Id = Guid.NewGuid(); objYoutubeChannel.Channelid = item["id"].ToString(); objYoutubeChannel.Likesid = item["contentDetails"]["relatedPlaylists"]["likes"].ToString(); objYoutubeChannel.Favoritesid = item["contentDetails"]["relatedPlaylists"]["favorites"].ToString(); objYoutubeChannel.Uploadsid = item["contentDetails"]["relatedPlaylists"]["uploads"].ToString(); objYoutubeChannel.Watchhistoryid = item["contentDetails"]["relatedPlaylists"]["watchHistory"].ToString(); objYoutubeChannel.Watchlaterid = item["contentDetails"]["relatedPlaylists"]["watchLater"].ToString(); objYoutubeChannel.Googleplususerid = objYoutubeAccount.Ytuserid; objYoutubeChannel.UserId = Guid.Parse(UserId); try { string viewcnt = item["statistics"]["viewCount"].ToString(); objYoutubeChannel.ViewCount = Convert.ToInt32(viewcnt); string videocnt = item["statistics"]["videoCount"].ToString(); objYoutubeChannel.VideoCount = Convert.ToInt32(videocnt); string commentcnt = item["statistics"]["commentCount"].ToString(); objYoutubeChannel.CommentCount = Convert.ToInt32(commentcnt); string Subscribercnt = item["statistics"]["subscriberCount"].ToString(); objYoutubeChannel.SubscriberCount = Convert.ToInt32(Subscribercnt); try { string str = item["statistics"]["hiddenSubscriberCount"].ToString(); if (str == "false") { objYoutubeChannel.HiddenSubscriberCount = 0; } else { objYoutubeChannel.HiddenSubscriberCount = 1; } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } if (!objYoutubeChannelRepository.checkYoutubeChannelExists(objYoutubeChannel.Channelid, Guid.Parse(UserId))) { YoutubeChannelRepository.Add(objYoutubeChannel); } } #endregion #region Add TeamMemberProfile Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId)); Domain.Socioboard.Domain.TeamMemberProfile objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile(); objTeamMemberProfile.Id = Guid.NewGuid(); objTeamMemberProfile.TeamId = objTeam.Id; objTeamMemberProfile.Status = 1; objTeamMemberProfile.ProfileType = "youtube"; objTeamMemberProfile.StatusUpdateDate = DateTime.Now; objTeamMemberProfile.ProfileId = objYoutubeAccount.Ytuserid; objTeamMemberProfile.ProfileName = objYoutubeAccount.Ytusername; objTeamMemberProfile.ProfilePicUrl = objYoutubeAccount.Ytprofileimage; if (!objTeamMemberProfileRepository.checkTeamMemberProfile(objTeam.Id, objYoutubeAccount.Ytuserid)) { objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile); } #endregion #region SocialProfile Domain.Socioboard.Domain.SocialProfile objSocialProfile = new Domain.Socioboard.Domain.SocialProfile(); objSocialProfile.Id = Guid.NewGuid(); objSocialProfile.ProfileType = "youtube"; objSocialProfile.ProfileId = objYoutubeAccount.Ytuserid; objSocialProfile.UserId = Guid.Parse(UserId); objSocialProfile.ProfileDate = DateTime.Now; objSocialProfile.ProfileStatus = 1; if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile)) { objSocialProfilesRepository.addNewProfileForUser(objSocialProfile); } #endregion return(ret); }
public void GetYoutubeChannelVideos(string userid, string profileid) { string ret = string.Empty; string strfinaltoken = string.Empty; string channelDetails = string.Empty; Domain.Socioboard.Domain.YoutubeAccount objYoutubeAccount = objYoutubeAccountRepository.getYoutubeAccountDetailsById(profileid, Guid.Parse(userid)); List <Domain.Socioboard.Domain.YoutubeChannel> lstYoutubeChannel = objYoutubeChannelRepository.getYoutubeChannelDetailsById(profileid, Guid.Parse(userid)); foreach (Domain.Socioboard.Domain.YoutubeChannel objYoutubeChannel in lstYoutubeChannel) { oAuthTokenYoutube objoAuthTokenYoutube = new oAuthTokenYoutube(); string finaltoken = objoAuthTokenYoutube.GetAccessToken(objYoutubeAccount.Refreshtoken); JObject objArray = JObject.Parse(finaltoken); //foreach (var item in objArray) //{ try { strfinaltoken = objArray["access_token"].ToString(); // break; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } //} PlaylistItems objPlaylistItems = new PlaylistItems(); Video objVideo = new Video(); try { Domain.Socioboard.MongoDomain.YouTubeFeed _YouTubeFeed; channelDetails = objPlaylistItems.Get_PlaylistItems_List(strfinaltoken, GlobusGooglePlusLib.Authentication.oAuthTokenYoutube.Parts.snippet.ToString(), objYoutubeChannel.Uploadsid); JObject obj = JObject.Parse(channelDetails); JArray array = (JArray)obj["items"]; foreach (var item in array) { try { _YouTubeFeed = new Domain.Socioboard.MongoDomain.YouTubeFeed(); _YouTubeFeed.Id = ObjectId.GenerateNewId(); _YouTubeFeed.ChannelName = item["snippet"]["channelTitle"].ToString(); _YouTubeFeed.PublishTime = DateTime.Parse(item["snippet"]["publishedAt"].ToString()).ToString("yyyy/MM/dd HH:mm:ss"); _YouTubeFeed.Thumbnail = item["snippet"]["thumbnails"]["maxres"]["url"].ToString(); _YouTubeFeed.Title = item["snippet"]["title"].ToString(); _YouTubeFeed.ChannelId = item["snippet"]["channelId"].ToString(); _YouTubeFeed.Description = item["snippet"]["description"].ToString(); _YouTubeFeed.VideoId = item["snippet"]["resourceId"]["videoId"].ToString(); _YouTubeFeed.YoutubeId = profileid; string videodetail = objVideo.Get_VideoDetails_byId(_YouTubeFeed.VideoId, strfinaltoken, "contentDetails,statistics"); JObject objv = JObject.Parse(videodetail); var videodata = objv["items"][0]; _YouTubeFeed.commentCount = videodata["statistics"]["commentCount"].ToString(); _YouTubeFeed.dislikeCount = videodata["statistics"]["dislikeCount"].ToString(); _YouTubeFeed.duration = videodata["contentDetails"]["duration"].ToString(); _YouTubeFeed.favoriteCount = videodata["statistics"]["favoriteCount"].ToString(); _YouTubeFeed.likeCount = videodata["statistics"]["likeCount"].ToString(); _YouTubeFeed.viewCount = videodata["statistics"]["viewCount"].ToString(); var rt = youtubefeedrepo.Find <Domain.Socioboard.MongoDomain.YouTubeFeed>(t => t.VideoId.Equals(_YouTubeFeed.VideoId)); var task = Task.Run(async() => { return(await rt); }); int count = task.Result.Count; if (count < 1) { youtubefeedrepo.Add(_YouTubeFeed); } else { FilterDefinition <BsonDocument> filter = new BsonDocument("VideoId", _YouTubeFeed.VideoId); var update = Builders <BsonDocument> .Update.Set("commentCount", _YouTubeFeed.commentCount).Set("dislikeCount", _YouTubeFeed.dislikeCount).Set("duration", _YouTubeFeed.duration).Set("favoriteCount", _YouTubeFeed.favoriteCount) .Set("likeCount", _YouTubeFeed.likeCount).Set("viewCount", _YouTubeFeed.viewCount); youtubefeedrepo.Update <Domain.Socioboard.MongoDomain.YouTubeFeed>(update, filter); } } catch (Exception ex) { } } } catch (Exception ex) { } } }
public ActionResult UpdateProfileDetails(string Network, string ProfileName) { if (Session["User"] != null) { Domain.Socioboard.Domain.User _User = (Domain.Socioboard.Domain.User)Session["User"]; if (_User.UserType != "SuperAdmin") { return(RedirectToAction("Index", "Index")); } } else { return(RedirectToAction("Index", "Index")); } string ReturnMessage = string.Empty; bool Status = false; if (Network == "Facebook") { Domain.Socioboard.Domain.FacebookAccount objfb = (FacebookAccount)Session["UpdateProfileData"]; objfb.IsActive = 1; objfb.FbUserName = ProfileName; string objFacebook = new JavaScriptSerializer().Serialize(objfb); Api.Facebook.Facebook ApiObjfb = new Api.Facebook.Facebook(); string FbMessage = (string)(new JavaScriptSerializer().Deserialize(ApiObjfb.UpdateFacebookAccountByAdmin(objFacebook), typeof(string))); ReturnMessage = FbMessage; } if (Network == "Twitter") { Status = true; Domain.Socioboard.Domain.TwitterAccount objfb = (TwitterAccount)Session["UpdateProfileData"]; objfb.IsActive = Status; objfb.TwitterScreenName = ProfileName; string objFacebook = new JavaScriptSerializer().Serialize(objfb); Api.Twitter.Twitter ApiObjfb = new Api.Twitter.Twitter(); string FbMessage = (string)(new JavaScriptSerializer().Deserialize(ApiObjfb.UpdateTwitterAccountByAdmin(objFacebook), typeof(string))); ReturnMessage = FbMessage; } if (Network == "Linkedin") { Status = true; Domain.Socioboard.Domain.LinkedInAccount objfb = (LinkedInAccount)Session["UpdateProfileData"]; objfb.IsActive = Status; objfb.LinkedinUserName = ProfileName; string objFacebook = new JavaScriptSerializer().Serialize(objfb); Api.Twitter.Twitter ApiObjfb = new Api.Twitter.Twitter(); string FbMessage = (string)(new JavaScriptSerializer().Deserialize(ApiObjfb.UpdateTwitterAccountByAdmin(objFacebook), typeof(string))); ReturnMessage = FbMessage; } if (Network == "Instagram") { Status = true; Domain.Socioboard.Domain.InstagramAccount objfb = (InstagramAccount)Session["UpdateProfileData"]; objfb.IsActive = Status; objfb.InsUserName = ProfileName; string objFacebook = new JavaScriptSerializer().Serialize(objfb); Api.Instagram.Instagram ApiObjfb = new Api.Instagram.Instagram(); string FbMessage = (string)(new JavaScriptSerializer().Deserialize(ApiObjfb.UpdateInstagramAccountByAdmin(objFacebook), typeof(string))); ReturnMessage = FbMessage; } //if (Network == "Tumblr") //{ // Status = true; // Domain.Socioboard.Domain.TwitterAccount objfb = (TwitterAccount)Session["UpdateProfileData"]; // objfb.IsActive = Status; // objfb.TwitterScreenName = ProfileName; // string objFacebook = new JavaScriptSerializer().Serialize(objfb); // Api.Twitter.Twitter ApiObjfb = new Api.Twitter.Twitter(); // string FbMessage = (string)(new JavaScriptSerializer().Deserialize(ApiObjfb.UpdateTwitterAccountByAdmin(objFacebook), typeof(string))); // ReturnMessage = FbMessage; //} if (Network == "Youtube") { Status = true; Domain.Socioboard.Domain.YoutubeAccount objfb = (YoutubeAccount)Session["UpdateProfileData"]; objfb.Isactive = 1; objfb.Ytusername = ProfileName; string objFacebook = new JavaScriptSerializer().Serialize(objfb); Api.Youtube.Youtube ApiObjfb = new Api.Youtube.Youtube(); string FbMessage = (string)(new JavaScriptSerializer().Deserialize(ApiObjfb.UpdateYouTubeAccountByAdmin(objFacebook), typeof(string))); ReturnMessage = FbMessage; } if (Network == "GooglePlus") { Status = true; Domain.Socioboard.Domain.GooglePlusAccount objfb = (GooglePlusAccount)Session["UpdateProfileData"]; objfb.IsActive = 1; objfb.GpUserName = ProfileName; string objFacebook = new JavaScriptSerializer().Serialize(objfb); Api.Twitter.Twitter ApiObjfb = new Api.Twitter.Twitter(); string FbMessage = (string)(new JavaScriptSerializer().Deserialize(ApiObjfb.UpdateTwitterAccountByAdmin(objFacebook), typeof(string))); ReturnMessage = FbMessage; } return(Content(ReturnMessage)); }
private static async Task<ISocialSiteAccount> GetSocialAccountFromGroupProfile(Guid objUserid, Domain.Socioboard.Domain.GroupProfile objGroupProfile) { ISocialSiteAccount objSocialSiteAccount = null; string accesstoken = string.Empty; try { accesstoken = System.Web.HttpContext.Current.Session["access_token"].ToString(); } catch { } if (objGroupProfile.ProfileType == "facebook" || objGroupProfile.ProfileType == "facebook_page") { //using (Api.FacebookAccount.FacebookAccount ApiobjFacebookAccount = new Api.FacebookAccount.FacebookAccount()) //{ // ApiobjFacebookAccount.Timeout = 300000; // objSocialSiteAccount = (FacebookAccount)(new JavaScriptSerializer().Deserialize(ApiobjFacebookAccount.getFacebookAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(FacebookAccount))); //} FacebookAccount fbaccount = new FacebookAccount(); HttpResponseMessage fbresponse = await WebApiReq.GetReq("api/ApiFacebookAccount/GetFacebookAcoount?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken); if (fbresponse.IsSuccessStatusCode) { fbaccount = await fbresponse.Content.ReadAsAsync<Domain.Socioboard.Domain.FacebookAccount>(); objSocialSiteAccount = fbaccount; } } else if (objGroupProfile.ProfileType == "twitter") { //using (Api.TwitterAccount.TwitterAccount ApiobjTwitterAccount = new Api.TwitterAccount.TwitterAccount()) //{ // ApiobjTwitterAccount.Timeout = 300000; // objSocialSiteAccount = (TwitterAccount)(new JavaScriptSerializer().Deserialize(ApiobjTwitterAccount.GetTwitterAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(TwitterAccount))); //} TwitterAccount twitterAcc = new TwitterAccount(); HttpResponseMessage twitterresponse = await WebApiReq.GetReq("api/ApiTwitterAccount/GetTwitterAccountDetailsById?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken); if (twitterresponse.IsSuccessStatusCode) { twitterAcc = await twitterresponse.Content.ReadAsAsync<Domain.Socioboard.Domain.TwitterAccount>(); objSocialSiteAccount = twitterAcc; } } else if (objGroupProfile.ProfileType == "linkedin") { //using (Api.LinkedinAccount.LinkedinAccount ApiobjLinkedinAccount = new Api.LinkedinAccount.LinkedinAccount()) //{ // ApiobjLinkedinAccount.Timeout = 300000; // objSocialSiteAccount = (LinkedInAccount)(new JavaScriptSerializer().Deserialize(ApiobjLinkedinAccount.GetLinkedinAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(LinkedInAccount))); //} LinkedInAccount LinkedinAcc = new LinkedInAccount(); HttpResponseMessage Linkedinresponse = await WebApiReq.GetReq("api/ApiLinkedinAccount/GetLinkedinAccountDetailsById?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken); if (Linkedinresponse.IsSuccessStatusCode) { LinkedinAcc = await Linkedinresponse.Content.ReadAsAsync<Domain.Socioboard.Domain.LinkedInAccount>(); objSocialSiteAccount = LinkedinAcc; } } else if (objGroupProfile.ProfileType == "instagram") { //using (Api.InstagramAccount.InstagramAccount ApiobjInstagramAccount = new Api.InstagramAccount.InstagramAccount()) //{ // objSocialSiteAccount = (InstagramAccount)(new JavaScriptSerializer().Deserialize(ApiobjInstagramAccount.UserInformation(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(InstagramAccount))); //} InstagramAccount instAcc = new InstagramAccount(); HttpResponseMessage response = await WebApiReq.GetReq("api/ApiInstagramAccount/GetInstagramAccount?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken); if (response.IsSuccessStatusCode) { instAcc = await response.Content.ReadAsAsync<Domain.Socioboard.Domain.InstagramAccount>(); objSocialSiteAccount = instAcc; } } else if (objGroupProfile.ProfileType == "youtube") { //using (Api.YoutubeAccount.YoutubeAccount ApiobjYoutubeAccount = new Api.YoutubeAccount.YoutubeAccount()) //{ // ApiobjYoutubeAccount.Timeout = 300000; // objSocialSiteAccount = (YoutubeAccount)(new JavaScriptSerializer().Deserialize(ApiobjYoutubeAccount.GetYoutubeAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(YoutubeAccount))); //} YoutubeAccount ytAcc = new YoutubeAccount(); HttpResponseMessage response = await WebApiReq.GetReq("api/ApiYoutubeAccount/GetYoutubeAccount?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken); if (response.IsSuccessStatusCode) { ytAcc = await response.Content.ReadAsAsync<Domain.Socioboard.Domain.YoutubeAccount>(); objSocialSiteAccount = ytAcc; } } else if (objGroupProfile.ProfileType == "tumblr") { //using (Api.TumblrAccount.TumblrAccount ApiobjTumblrAccount = new Api.TumblrAccount.TumblrAccount()) //{ // ApiobjTumblrAccount.Timeout = 300000; // objSocialSiteAccount = (TumblrAccount)(new JavaScriptSerializer().Deserialize(ApiobjTumblrAccount.GetTumblrAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(TumblrAccount))); //} TumblrAccount ytAcc = new TumblrAccount(); HttpResponseMessage response = await WebApiReq.GetReq("api/ApiTumblrAccount/GetTumblrAccountDetailsById?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken); if (response.IsSuccessStatusCode) { ytAcc = await response.Content.ReadAsAsync<Domain.Socioboard.Domain.TumblrAccount>(); objSocialSiteAccount = ytAcc; } } else if (objGroupProfile.ProfileType == "linkedincompanypage") { //using (Api.LinkedinCompanyPage.LinkedinCompanyPage objLinkedinCompanyPage = new Api.LinkedinCompanyPage.LinkedinCompanyPage()) //{ // objLinkedinCompanyPage.Timeout = 300000; // objSocialSiteAccount = (LinkedinCompanyPage)(new JavaScriptSerializer().Deserialize(objLinkedinCompanyPage.GetLinkedinCompanyPageDetailsByUserIdAndPageId(objUserid.ToString(), objGroupProfile.ProfileId.ToString()), typeof(LinkedinCompanyPage))); //} LinkedinCompanyPage licompanypage = new LinkedinCompanyPage(); HttpResponseMessage response = await WebApiReq.GetReq("api/ApiLinkedinCompanyPage/GetLinkedinCompanyPageDetailsByUserIdAndPageId?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken); if (response.IsSuccessStatusCode) { licompanypage = await response.Content.ReadAsAsync<Domain.Socioboard.Domain.LinkedinCompanyPage>(); objSocialSiteAccount = licompanypage; } } else if (objGroupProfile.ProfileType == "gplus") { //using (Api.GooglePlusAccount.GooglePlusAccount ApiobjGooglePlusAccount = new Api.GooglePlusAccount.GooglePlusAccount()) //{ // ApiobjGooglePlusAccount.Timeout = 300000; // objSocialSiteAccount = (GooglePlusAccount)(new JavaScriptSerializer().Deserialize(ApiobjGooglePlusAccount.GetGooglePlusAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId), typeof(GooglePlusAccount))); //} GooglePlusAccount googlePlusAccount = new GooglePlusAccount(); HttpResponseMessage response = await WebApiReq.GetReq("api/ApiGooglePlusAccount/GetGooglePlusAccount?ProfileId=" + objGroupProfile.ProfileId, "Bearer", accesstoken); if (response.IsSuccessStatusCode) { googlePlusAccount = await response.Content.ReadAsAsync<Domain.Socioboard.Domain.GooglePlusAccount>(); objSocialSiteAccount = googlePlusAccount; } } else if (objGroupProfile.ProfileType == "googleanalytics") { //using (Api.GoogleAnalyticsAccount.GoogleAnalyticsAccount ApiobjGoogleAnalyticsAccount = new Api.GoogleAnalyticsAccount.GoogleAnalyticsAccount()) //{ // ApiobjGoogleAnalyticsAccount.Timeout = 300000; // objSocialSiteAccount = (GoogleAnalyticsAccount)(new JavaScriptSerializer().Deserialize(ApiobjGoogleAnalyticsAccount.GetGooglePlusAccountDetailsById(objUserid.ToString(), objGroupProfile.ProfileId), typeof(GoogleAnalyticsAccount))); //} GoogleAnalyticsAccount googlePlusAccount = new GoogleAnalyticsAccount(); HttpResponseMessage response = await WebApiReq.GetReq("api/ApiGoogleAnalyticsAccount/GetGooglePlusAccountDetailsById?ProfileId=" + objGroupProfile.ProfileId + "&UserId=" + objUserid.ToString(), "Bearer", accesstoken); if (response.IsSuccessStatusCode) { googlePlusAccount = await response.Content.ReadAsAsync<Domain.Socioboard.Domain.GoogleAnalyticsAccount>(); objSocialSiteAccount = googlePlusAccount; } } return objSocialSiteAccount; }