public int UpdateFbPagePostStatus(Domain.Socioboard.Domain.FbPagePost _FbPagePost) { using (NHibernate.ISession session = SessionFactory.GetNewSession()) { //After Session creation, start Transaction. using (NHibernate.ITransaction transaction = session.BeginTransaction()) { try { int i = session.CreateQuery("Update FbPagePost set Likes =:Likes,Comments =:Comments,Shares=:Shares where PostId =:PostId") .SetParameter("Likes", _FbPagePost.Likes) .SetParameter("Comments", _FbPagePost.Comments) .SetParameter("Shares", _FbPagePost.Shares) .SetParameter("PostId", _FbPagePost.PostId) .ExecuteUpdate(); transaction.Commit(); return(i); } catch (Exception ex) { return(0); } } } }
/// <addFbPagePost> /// Add new FbPagePost /// </summary> /// <param name="fbmsg">Set Values in a FbPagePost Class Property and Pass the same Object of FbPagePost Class.(Domain.FbPagePost)</param> public void addFbPagePost(Domain.Socioboard.Domain.FbPagePost _FbPagePost) { //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(_FbPagePost); transaction.Commit(); } //End Transaction } //End session }
public bool IsPostExist(Domain.Socioboard.Domain.FbPagePost _FbPagePost) { //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 all Facebook Message of User. List <Domain.Socioboard.Domain.FbPagePost> alst = session.CreateQuery("from FbPagePost where UserId = :userid and PageId = :pageid and PostId = :postid and FromId = :fromid") .SetParameter("userid", _FbPagePost.UserId) .SetParameter("pageid", _FbPagePost.PageId) .SetParameter("postid", _FbPagePost.PostId) .SetParameter("fromid", _FbPagePost.FromId) .List <Domain.Socioboard.Domain.FbPagePost>() .ToList <Domain.Socioboard.Domain.FbPagePost>(); if (alst.Count > 0) { return(true); } else { return(false); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); return(true); } } //End Transaction } //End session }
public string AddFbPagePost(string userid, string accesstoken, string profileid) { logger.Error("AddFbPagePost"); logger.Error(userid + ", " + accesstoken + " , " + profileid); string ret = string.Empty; try { FacebookClient fb = new FacebookClient(); fb.AccessToken = accesstoken; dynamic post = null; try { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls; post = fb.Get("v2.0/" + profileid + "/posts?limit=10"); } catch (Exception ex) { logger.Error("profileid +posts?limit=10"); logger.Error(ex.Message); logger.Error(ex.StackTrace); } //dynamic post1 = fb.Get("me/posts"); foreach (var item in post["data"]) { objFbPagePost = new Domain.Socioboard.Domain.FbPagePost(); objFbPagePost.Id = Guid.NewGuid(); objFbPagePost.UserId = Guid.Parse(userid); objFbPagePost.PageId = profileid; try { objFbPagePost.PostId = item["object_id"].ToString(); } catch { }; if (string.IsNullOrEmpty(objFbPagePost.PostId)) { try { string pstid = item["id"]; objFbPagePost.PostId = pstid.Split('_')[1]; } catch { }; } objFbPagePost.PostDate = Convert.ToDateTime(item["created_time"]); objFbPagePost.EntryDate = DateTime.Now; try { objFbPagePost.Post = item["message"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFbPagePost.PictureUrl = item["picture"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFbPagePost.LinkUrl = item["link"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFbPagePost.IconUrl = item["icon"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFbPagePost.StatusType = item["status_type"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFbPagePost.Type = item["type"].ToString(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFbPagePost.FromId = item["from"]["id"]; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { objFbPagePost.FromName = item["from"]["name"]; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { dynamic like = fb.Get("v2.0/" + objFbPagePost.PostId + "/likes?summary=1&limit=0"); objFbPagePost.Likes = Convert.ToInt32(like["summary"]["total_count"]); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { dynamic comment = fb.Get("v2.0/" + objFbPagePost.PostId + "/comments?summary=1&limit=0"); objFbPagePost.Comments = Convert.ToInt32(comment["summary"]["total_count"]); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } try { //dynamic shares = fb.Get("v2.0/"+objFbPagePost.PostId); //objFbPagePost.Shares = Convert.ToInt32(shares["shares"]["count"]); objFbPagePost.Shares = Convert.ToInt32(item["shares"]["count"]); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); logger.Error(ex.StackTrace); } try { if (!objFbPagePostRepository.IsPostExist(objFbPagePost)) { objFbPagePostRepository.addFbPagePost(objFbPagePost); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); logger.Error(ex.StackTrace); } try { AddFbPagePostComments(objFbPagePost.PostId, accesstoken, userid); } catch (Exception ex) { logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); } try { AddFbPagePostLiker(objFbPagePost.PostId, accesstoken, userid); } catch (Exception ex) { logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); } } } catch (Exception ex) { logger.Error(ex.StackTrace); Console.WriteLine(ex.StackTrace); } return ret; }