public void GetLinkedInFeeds(oAuthLinkedIn _oauth,string profileId,Guid userId) { LinkedInNetwork objln = new LinkedInNetwork(); LinkedInFeedRepository objliFeedsRepo = new LinkedInFeedRepository(); List<LinkedInNetwork.Network_Updates> userUPdate = objln.GetNetworkUpdates(_oauth, 20); LinkedInFeed lnkfeeds=new LinkedInFeed(); foreach (var item in userUPdate) { lnkfeeds.Feeds = item.Message; lnkfeeds.FromId = item.PersonId; lnkfeeds.FromName = item.PersonFirstName + " " + item.PersonLastName; lnkfeeds.FeedsDate =Convert.ToDateTime(item.DateTime); lnkfeeds.EntryDate = DateTime.Now; lnkfeeds.ProfileId = profileId; lnkfeeds.Type = item.UpdateType; lnkfeeds.UserId = userId; lnkfeeds.FromPicUrl = item.PictureUrl; objliFeedsRepo.addLinkedInFeed(lnkfeeds); } }
public string AddLinkedinAccount(string oauth_token, string oauth_verifier, string reuqestTokenSecret, string consumerKey, string consumerSecret, string UserId, string GroupId) { try { logger.Error("AddLinkedinAccount()"); System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; string ret = string.Empty; LinkedInProfile objProfile = new LinkedInProfile(); LinkedInProfile.UserProfile objUserProfile = new LinkedInProfile.UserProfile(); objSocialProfile = new Domain.Socioboard.Domain.SocialProfile(); oAuthLinkedIn _oauth = new oAuthLinkedIn(); objLinkedInAccount = new LinkedInAccount(); #region Get linkedin Profile data from Api try { _oauth.ConsumerKey = consumerKey; } catch (Exception ex) { Console.WriteLine(ex.Message); logger.Error(ex.Message); } try { _oauth.ConsumerSecret = consumerSecret; } catch (Exception ex) { Console.WriteLine(ex.Message); logger.Error(ex.Message); } try { _oauth.Token = oauth_token; } catch (Exception ex) { Console.WriteLine(ex.Message); logger.Error(ex.Message); } try { _oauth.TokenSecret = reuqestTokenSecret; } catch (Exception ex) { Console.WriteLine(ex.Message); logger.Error(ex.Message); } try { _oauth.Verifier = oauth_verifier; } catch (Exception ex) { Console.WriteLine(ex.Message); logger.Error(ex.Message); } try { _oauth.AccessTokenGet(oauth_token); } catch (Exception ex) { Console.WriteLine(ex.Message); logger.Error(ex.Message); } try { objUserProfile = objProfile.GetUserProfile(_oauth); } catch (Exception ex) { Console.WriteLine(ex.Message); logger.Error(ex.Message); } #endregion dynamic data = objUserProfile; try { #region LinkedInAccount objLinkedInAccount.UserId = Guid.Parse(UserId); objLinkedInAccount.LinkedinUserId = data.id.ToString(); try { objLinkedInAccount.EmailId = data.email.ToString(); } catch (Exception ex) { logger.Error(ex.StackTrace); } objLinkedInAccount.LinkedinUserName = data.first_name.ToString() + data.last_name.ToString(); objLinkedInAccount.OAuthToken = _oauth.Token; objLinkedInAccount.OAuthSecret = _oauth.TokenSecret; objLinkedInAccount.OAuthVerifier = _oauth.Verifier; try { objLinkedInAccount.ProfileImageUrl = data.picture_url.ToString(); } catch (Exception ex) { logger.Error(ex.StackTrace); } try { objLinkedInAccount.ProfileUrl = data.profile_url.ToString(); } catch (Exception ex) { logger.Error(ex.StackTrace); } #endregion #region SocialProfiles try { objLinkedInAccount.Connections = data.connections; objLinkedInAccount.IsActive = true; objSocialProfile.UserId = Guid.Parse(UserId); objSocialProfile.ProfileType = "linkedin"; objSocialProfile.ProfileId = data.id.ToString(); objSocialProfile.ProfileStatus = 1; objSocialProfile.ProfileDate = DateTime.Now; objSocialProfile.Id = Guid.NewGuid(); } catch (Exception ex) { logger.Error(ex.Message); } #endregion SocialProfiles #region Add TeamMemberProfile try { Domain.Socioboard.Domain.Team objTeam = objTeamRepository.GetTeamByGroupId(Guid.Parse(GroupId)); objTeamMemberProfile = new Domain.Socioboard.Domain.TeamMemberProfile(); objTeamMemberProfile.Id = Guid.NewGuid(); objTeamMemberProfile.TeamId = objTeam.Id; objTeamMemberProfile.Status = 1; objTeamMemberProfile.ProfileType = "linkedin"; objTeamMemberProfile.StatusUpdateDate = DateTime.Now; objTeamMemberProfile.ProfileId = objLinkedInAccount.LinkedinUserId; objTeamMemberProfile.ProfileName = objLinkedInAccount.LinkedinUserName; objTeamMemberProfile.ProfilePicUrl = objLinkedInAccount.ProfileImageUrl; } catch (Exception ex) { logger.Error(ex.Message); } #endregion } catch (Exception ex) { logger.Error(ex.StackTrace); } try { if (!objLinkedInAccountRepository.checkLinkedinUserExists(objLinkedInAccount.LinkedinUserId, Guid.Parse(UserId))) { objLinkedInAccountRepository.addLinkedinUser(objLinkedInAccount); ret = "LinkedIn Account Added Successfully"; } else { ret = "LinkedIn Account Already Exist"; } if (!objSocialProfilesRepository.checkUserProfileExist(objSocialProfile)) { objSocialProfilesRepository.addNewProfileForUser(objSocialProfile); } if (!objTeamMemberProfileRepository.checkTeamMemberProfile(objTeamMemberProfile.TeamId, objLinkedInAccount.LinkedinUserId)) { objTeamMemberProfileRepository.addNewTeamMember(objTeamMemberProfile); } #region Add LinkedIn Feeds LinkedInNetwork objln = new LinkedInNetwork(); List<LinkedInNetwork.Network_Updates> userUPdate = objln.GetNetworkUpdates(_oauth, 20); foreach (var item in userUPdate) { try { objLinkedInFeed = new Domain.Socioboard.Domain.LinkedInFeed(); objLinkedInFeed.Feeds = item.Message; objLinkedInFeed.FromId = item.PersonId; objLinkedInFeed.FromName = item.PersonFirstName + " " + item.PersonLastName; objLinkedInFeed.FeedsDate = Convert.ToDateTime(item.DateTime); objLinkedInFeed.EntryDate = DateTime.Now; objLinkedInFeed.ProfileId = objLinkedInAccount.LinkedinUserId; objLinkedInFeed.Type = item.UpdateType; objLinkedInFeed.UserId = Guid.Parse(UserId); objLinkedInFeed.FromPicUrl = item.PictureUrl; objLinkedInFeed.ImageUrl = item.ImageUrl; objLinkedInFeed.FromUrl = item.url; } catch (Exception ex) { logger.Error(ex.StackTrace); } if (!objLinkedInFeedRepository.checkLinkedInFeedExists(objLinkedInFeed.FeedId, Guid.Parse(UserId))) { objLinkedInFeedRepository.addLinkedInFeed(objLinkedInFeed); } } #endregion #region Add LinkedIn UserUpdates GlobusLinkedinLib.App.Core.LinkedInUser l = new GlobusLinkedinLib.App.Core.LinkedInUser(); List<Domain.Socioboard.Domain.LinkedIn_Update_Messages> lst_Messages = l.GetUserUpdateNew(_oauth, objLinkedInAccount.LinkedinUserId, 10); foreach (var item_Messages in lst_Messages) { try { objLinkedInMessage = new Domain.Socioboard.Domain.LinkedInMessage(); objLinkedInMessage.Id = Guid.NewGuid(); objLinkedInMessage.Message = item_Messages.Message; objLinkedInMessage.ProfileId = item_Messages.ProfileId; objLinkedInMessage.ProfileName = item_Messages.ProfileName; objLinkedInMessage.CreatedDate = Convert.ToDateTime(item_Messages.CreatedDate); objLinkedInMessage.EntryDate = DateTime.Now; objLinkedInMessage.Type = item_Messages.Type; objLinkedInMessage.UserId = Guid.Parse(UserId); objLinkedInMessage.ImageUrl = item_Messages.ImageUrl; objLinkedInMessage.FeedId = item_Messages.FeedId; objLinkedInMessage.ProfileUrl = item_Messages.ProfileUrl; objLinkedInMessage.Comments = item_Messages.Comments; objLinkedInMessage.Likes = item_Messages.Likes; objLinkedInMessage.ProfileImageUrl = item_Messages.ProfileImageUrl; } catch (Exception ex) { logger.Error(ex.StackTrace); } if (!objLinkedInMessageRepository.checkLinkedInMessageExists(objLinkedInAccount.LinkedinUserId, objLinkedInMessage.FeedId, Guid.Parse(UserId))) { objLinkedInMessageRepository.addLinkedInMessage(objLinkedInMessage); } } #endregion } catch (Exception ex) { logger.Error(ex.StackTrace); } return ""; } catch (Exception ex) { logger.Error(ex.StackTrace); return ""; } }