public string LinkedInScheduleUpdate(LinkedInManager LinkedInManager)
        {
            string json = "";
            if (LinkedInManager.ScheduleTime<=DateTime.Now)
            {
                oAuthLinkedIn _oauth = new oAuthLinkedIn();
                
                Domain.Socioboard.Domain.LinkedInAccount _LinkedinAccount = objLinkedInAccountRepository.getLinkedinAccountDetailsById(LinkedInManager.ProfileId);
                try
                {
                    _oauth.ConsumerKey = ConfigurationManager.AppSettings["LinkedinApiKey"];
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.Error(ex.Message);
                }

                try
                {
                    _oauth.ConsumerSecret = ConfigurationManager.AppSettings["LinkedinSecretKey"];
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    logger.Error(ex.Message);
                }
                _oauth.Token = _LinkedinAccount.OAuthToken;
                string PostUrl = "https://api.linkedin.com/v1/people/~/shares?format=json";
                if (string.IsNullOrEmpty(LinkedInManager.ImageUrl))
                {
                    json = _oauth.LinkedProfilePostWebRequest("POST", PostUrl, LinkedInManager.comment);
                }
                else
                {

                    string imagepath = ConfigurationManager.AppSettings["DomainName"].ToString() + Regex.Split(LinkedInManager.ImageUrl, "wwwroot")[1].Replace("\\", "/");
                    json = _oauth.LinkedProfilePostWebRequestWithImage("POST", PostUrl, LinkedInManager.comment, imagepath);
                }
                if (!string.IsNullOrEmpty(json))
                {
                    json = "Message post on LinkedIn for Id :" + LinkedInManager.ProfileId + " and Message: " + LinkedInManager.comment;
                    objScheduledMessageRepository.UpdateScheduledMessage(Guid.Parse(LinkedInManager.ScheduleMessageId));
                }
                else {
                    json= "Something Went Wrong";
                }
            }

            return json;
            
        }
Esempio n. 2
0
        public string SetPostOnPageWithImage(oAuthLinkedIn oauth, string PageId, string imageurl, string post)
        {
            //string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
            //xml += " <share><visibility><code>anyone</code></visibility><comment>" + post + "</comment>";
            ////xml += "<content><submitted-url>http://socioboard.com/</submitted-url><title>none</title> <submitted-image-url>" + imageurl + "</submitted-image-url></content></share>";
            //xml += "<content><submitted-url>http://localhost:5334/</submitted-url><title>none</title> <submitted-image-url>" + imageurl + "</submitted-image-url></content></share>";


            string url = "https://api.linkedin.com/v1/companies/" + PageId + "/shares?format=json";
            string response = oauth.LinkedProfilePostWebRequestWithImage("POST", url, post, imageurl);
            return response;

        }
        public IHttpActionResult LinkedInProfileUpdate(LinkedInManager LinkedInManager)
        {
            oAuthLinkedIn _oauth = new oAuthLinkedIn();
            string json = "";
            Domain.Socioboard.Domain.LinkedInAccount _LinkedinAccount = objLinkedInAccountRepository.getLinkedinAccountDetailsById(LinkedInManager.ProfileId);
            try
            {
                _oauth.ConsumerKey = ConfigurationManager.AppSettings["LinkedinApiKey"];
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
            }

            try
            {
                _oauth.ConsumerSecret = ConfigurationManager.AppSettings["LinkedinSecretKey"];
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
            }
            _oauth.Token = _LinkedinAccount.OAuthToken;
            string PostUrl = "https://api.linkedin.com/v1/people/~/shares?format=json";
            if (string.IsNullOrEmpty(LinkedInManager.ImageUrl))
            {
                 json = _oauth.LinkedProfilePostWebRequest("POST", PostUrl, LinkedInManager.comment);
            }
            else {

                string imagepath = ConfigurationManager.AppSettings["DomainName"].ToString() + Regex.Split(LinkedInManager.ImageUrl, "wwwroot")[1].Replace("\\", "/");
                json = _oauth.LinkedProfilePostWebRequestWithImage("POST", PostUrl, LinkedInManager.comment,imagepath);
            }
            #region ScheduledMessage
            if (!string.IsNullOrEmpty(json))
            {
                objScheduledMessage.Id = Guid.NewGuid();
                objScheduledMessage.PicUrl = LinkedInManager.ImageUrl;
                objScheduledMessage.ProfileId = LinkedInManager.ProfileId;
                objScheduledMessage.ProfileType = "linkedin";
                objScheduledMessage.ScheduleTime = DateTime.Now;
                objScheduledMessage.ShareMessage = LinkedInManager.comment;
                objScheduledMessage.Status = true;
                objScheduledMessage.UserId = Guid.Parse(LinkedInManager.UserId);
                objScheduledMessage.CreateTime = DateTime.Now;
                objScheduledMessage.ClientTime = DateTime.Now;
                if (!objScheduledMessageRepository.checkMessageExistsAtTime(objScheduledMessage.UserId, objScheduledMessage.ScheduleTime))
                {
                    objScheduledMessageRepository.addNewMessage(objScheduledMessage);
                }
            
            }
            #endregion
            return Ok();
        }