public IList <ViewComment> GetViewComments(int postid, int pageindex, int pagesize, out int pagecount) { string sql = "usp_getcommentinfo"; SqlParameter[] spm = SqlHelper.GetSqpParameters(new string[] { "@postid", "@pageindex", "@pagesize", "@pagecount" }, new object[] { postid, pageindex, pagesize, DBNull.Value }, new SqlDbType[] { SqlDbType.Int, SqlDbType.Int, SqlDbType.Int, SqlDbType.Int, }); spm[3].Direction = ParameterDirection.Output; DataSet set = new DataSet(); SqlHelper.GetDataTable(sql, CommandType.StoredProcedure, set, spm); pagecount = Convert.ToInt32(spm[3].Value); List <ViewComment> list = new List <ViewComment>(); foreach (DataRow comment in set.Tables[0].Rows) { ViewComment viewComment = new ViewComment(); viewComment.User.UserId = Convert.ToInt32(comment[0]); viewComment.User.UserName = comment[1].ToString(); viewComment.User.Head = comment[2].ToString(); viewComment.Comment.CommentId = Convert.ToInt32(comment[3]); viewComment.Comment.Content = comment[4].ToString(); viewComment.Comment.ParentId = Convert.ToInt32(comment[5]); viewComment.Comment.DateLine = Convert.ToDateTime(comment[6]); list.Add(viewComment); } return(list); }
public List <ViewComment> CommentRead(String artist, String song) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); dictionary.Add("artist_name", artist); dictionary.Add("song_name", song); CypherQuery query = new CypherQuery("MATCH (comment:Comment)-[relation: COMMENT_TO]->(song: Song)-[relation1:PERFORMED_BY]->(artist:Artist) WHERE song.name = { song_name } AND artist.name = { artist_name} RETURN comment", dictionary, CypherResultMode.Set); List <Comment> qres = ((IRawGraphClient)client).ExecuteGetCypherResults <Comment>(query).ToList(); List <ViewComment> comments = new List <ViewComment>(); foreach (Comment comment in qres) { dictionary = new Dictionary <string, object>(); dictionary.Add("id", comment.id); query = new CypherQuery("MATCH (user:User)-[relation:COMMENTED_BY]->(comment:Comment) WHERE comment.id = {id} RETURN user", dictionary, CypherResultMode.Set); User qresUser = ((IRawGraphClient)client).ExecuteGetCypherResults <User>(query).ToList().FirstOrDefault(); if (qresUser != null) { ViewComment temp = new ViewComment(comment, qresUser.name); comments.Add(temp); } } return(comments); }
//通过电影ID查找所有评论 public List <ViewComment> GetCommentByMovie(string MovieID) { //找到评论 var comments = context.Comment.ToLookup(mc => mc.m_id)[MovieID].ToList(); var returnList = new List <ViewComment> { }; foreach (var temp in comments) { //找到评论 //Comment tempcomment = context.Comment.FirstOrDefault(c => c.c_id == temp.c_id); //找到联系集 //UserComment userR = context.UserComment.FirstOrDefault(uc => uc.c_id == tempcomment.c_id); //找到评论者 User tempuser = context.User.FirstOrDefault(u => u.u_id == temp.u_id); var add = new ViewComment { UserName = tempuser.u_name, CommentID = temp.c_id, Rating = temp.rating, Review = temp.review, TotalLike = temp.total_like }; returnList.Add(add); } return(returnList); }
public HttpResponseMessage PostComment(ViewComment comment) { if (ModelState.IsValid) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created); _db.Comment.Add(new Comment { ProposalId = comment.Id, Body = comment.Body, CreatedBy = WebSecurity.CurrentUserId, CreatedDate = DateTime.UtcNow }); _db.SaveChanges(); Service service = _db.User.FirstOrDefault(c => c.UserId == WebSecurity.CurrentUserId).Services.FirstOrDefault(c => c.Provider == "facebook"); //get service for posting to feed Proposal proposal = _db.Proposal.FirstOrDefault(c => c.Id == comment.Id && c.FacebookPostId != null && c.FacebookPostId != ""); if (service != null && proposal != null) { FacebookAPI facebook = new FacebookAPI(service.Token); int status = facebook.postCommentToPost(proposal.FacebookPostId, comment.Body, WebSecurity.CurrentUserId); if (status == 1) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } else if (status == 2) { return(Request.CreateResponse(HttpStatusCode.BadGateway)); } else if (status == 3) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } //facebook.postCommentToPost(); } return(response); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }