public void updateLinkedinPostofPage(Domain.Socioboard.Domain.LinkedinCompanyPagePosts lipost)
 {
     using (NHibernate.ISession session = SessionFactory.GetNewSession())
     {
         using (NHibernate.ITransaction transaction = session.BeginTransaction())
         {
             try
             {
                 session.CreateQuery("Update LinkedinCompanyPagePosts set Likes =:Likes,Comments =:Comments,IsLiked=:IsLiked where PostId = :PostId and UserId = :UserId")
                 .SetParameter("Likes", lipost.Likes)
                 .SetParameter("Comments", lipost.Comments)
                 .SetParameter("IsLiked", lipost.IsLiked)
                 .SetParameter("PostId", lipost.PostId)
                 .SetParameter("UserId", lipost.UserId)
                 .ExecuteUpdate();
                 transaction.Commit();
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 // return 0;
             }
         }
     }
 }
 public Domain.Socioboard.Domain.LinkedinCompanyPagePosts getCompanyPagPostInformation(string UpdateKey)
 {
     //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 details of account.
                 List <Domain.Socioboard.Domain.LinkedinCompanyPagePosts> objlst = session.CreateQuery("from LinkedinCompanyPagePosts where UpdateKey = :UpdateKey ")
                                                                                   .SetParameter("UpdateKey", UpdateKey)
                                                                                   .List <Domain.Socioboard.Domain.LinkedinCompanyPagePosts>().ToList <Domain.Socioboard.Domain.LinkedinCompanyPagePosts>();
                 Domain.Socioboard.Domain.LinkedinCompanyPagePosts result = new Domain.Socioboard.Domain.LinkedinCompanyPagePosts();
                 if (objlst.Count > 0)
                 {
                     result = objlst[0];
                 }
                 return(result);
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.StackTrace);
                 return(null);
             }
         } //End Transaction
     }     //End Session
 }
 public void addLinkedInPagepost(Domain.Socioboard.Domain.LinkedinCompanyPagePosts lipost)
 {
     //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())
         {
             session.Save(lipost);
             transaction.Commit();
         } //End Transaction
     }     //End Session
 }
        public void GetLinkedinCompanyPageFeeds(oAuthLinkedIn _oauth, string UserId, string PageId)
        {
            LinkedinPageUpdate objlinkedinpageupdate = new LinkedinPageUpdate();
            LinkedinPagePostRepository objlipagepostRepo = new LinkedinPagePostRepository();
            List<LinkedinPageUpdate.CompanyPagePosts> objcompanypagepost = new List<LinkedinPageUpdate.CompanyPagePosts>();
            objcompanypagepost = objlinkedinpageupdate.GetPagePosts(_oauth, PageId);
            LinkedinCompanyPagePosts lipagepost = new LinkedinCompanyPagePosts();
            foreach (var item in objcompanypagepost)
            {
                lipagepost.Id = Guid.NewGuid();
                lipagepost.Posts = item.Posts;
                lipagepost.PostDate = Convert.ToDateTime(item.PostDate);
                lipagepost.EntryDate = DateTime.Now;
                lipagepost.UserId = Guid.Parse(UserId);
                lipagepost.Type = item.Type;
                lipagepost.PostId = item.PostId;
                lipagepost.UpdateKey = item.UpdateKey;
                lipagepost.PageId = PageId;
                lipagepost.PostImageUrl = item.PostImageUrl;
                lipagepost.Likes = item.Likes;
                lipagepost.Comments = item.Comments;
                if (!objlipagepostRepo.checkLinkedInPostExists(lipagepost.PostId, lipagepost.UserId))
                {
                    objlipagepostRepo.addLinkedInPagepost(lipagepost);
                }
                else
                {
                    objlipagepostRepo.updateLinkedinPostofPage(lipagepost);
                }

            }
        }
        public Domain.Socioboard.Domain.LinkedinCompanyPagePosts getCompanyPagPostInformation(string UpdateKey)
        {
            //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 details of account.
                        List<Domain.Socioboard.Domain.LinkedinCompanyPagePosts> objlst = session.CreateQuery("from LinkedinCompanyPagePosts where UpdateKey = :UpdateKey ")
                        .SetParameter("UpdateKey", UpdateKey)
                        .List<Domain.Socioboard.Domain.LinkedinCompanyPagePosts>().ToList<Domain.Socioboard.Domain.LinkedinCompanyPagePosts>();
                        Domain.Socioboard.Domain.LinkedinCompanyPagePosts result = new Domain.Socioboard.Domain.LinkedinCompanyPagePosts();
                        if (objlst.Count > 0)
                        {
                            result = objlst[0];
                        }
                        return result;

                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                        return null;
                    }
                }//End Transaction
            }//End Session
        }
        public IHttpActionResult PsotCommentOnLinkedinCompanyPageUpdate(LinkedInManager LinkedInManager)
        {
            try
            {
                Domain.Socioboard.Domain.LinkedinCompanyPage objlicompanypage = new Domain.Socioboard.Domain.LinkedinCompanyPage();
                objlicompanypage = objLinkedCmpnyPgeRepo.getCompanyPageInformation(LinkedInManager.ProfileId);
                oAuthLinkedIn Linkedin_oauth = new oAuthLinkedIn();
                try
                {
                    Linkedin_oauth.ConsumerKey = ConfigurationManager.AppSettings["LinkedinApiKey"];
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                try
                {
                    Linkedin_oauth.ConsumerSecret = ConfigurationManager.AppSettings["LinkedinSecretKey"];
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                Linkedin_oauth.Verifier = objlicompanypage.OAuthVerifier;
                Linkedin_oauth.TokenSecret = objlicompanypage.OAuthSecret;
                Linkedin_oauth.Token = objlicompanypage.OAuthToken;
                Linkedin_oauth.Id = objlicompanypage.LinkedinPageId;
                Linkedin_oauth.FirstName = objlicompanypage.LinkedinPageName;
                Company company = new Company();
                string res = company.SetCommentOnPagePost(Linkedin_oauth, LinkedInManager.ProfileId, LinkedInManager.Updatekey, LinkedInManager.comment);
                if (res != "Failed")
                {
                    Domain.Socioboard.Domain.LinkedinCompanyPagePosts lipost = new LinkedinCompanyPagePosts();
                    lipost = objLinkedinPagePostRepository.getCompanyPagPostInformation(LinkedInManager.Updatekey);
                    lipost.Comments = lipost.Comments + 1;
                    objLinkedinPagePostRepository.updateLinkedinPostCommentofPage(lipost);
                }
                string data= new JavaScriptSerializer().Serialize(res);
                return Ok(data);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                return Ok("Something Went Wrong");
            }

        }