public List <CommentBag> ShowChildComment(int id) { List <CommentBag> listChild = new List <CommentBag>(); using (var db = DatabaseFactory.OpenDbConnection()) { //pega o comentário Comment comment = db.Where <Comment>(cmt => cmt.Visible == true && cmt.Id == id).FirstOrDefault(); if (comment != null) { Channel chn = db.Where <Channel>(c => c.Id == comment.ChannelId).FirstOrDefault(); ChannelController cc = ClonedContextInstance <ChannelController>(); var userRoles = cc.ReturnRolesUser(chn.Id); bool isOwnerOrManager = (NimbusUser.UserId == chn.OwnerId || userRoles.Contains("channelmanager") || userRoles.Contains("topicmanager")); User user = db.SelectParam <User>(u => u.Id == comment.UserId).FirstOrDefault(); CommentBag child = new CommentBag(); string name = ""; if (comment.Text == "Comentário removido") { user.AvatarUrl = "/images/av130x130/person_icon.png"; name = "[removido]"; child.IsDeletable = false; child.IsRepotable = false; } else { name = user.FirstName + " " + user.LastName; child.IsDeletable = (user.Id == NimbusUser.UserId || isOwnerOrManager); child.IsRepotable = !isOwnerOrManager; } child.AvatarUrl = user.AvatarUrl; child.UserName = name; child.UserId = user.Id; child.Id = comment.Id; child.Text = comment.Text; child.ParentId = comment.ParentId; child.PostedOn = comment.PostedOn; child.IsNew = comment.IsNew; child.IsPageChannel = false; //comentario filho nao aparece na page channel child.IsAnswer = comment.IsAnswer; child.TopicId = comment.TopicId; child.IsParent = false; child.ChannelId = comment.ChannelId; listChild.Add(child); } } return(listChild); }
public override IEnumerable <CommentBlock> FindCommentsForMembers(CommentBag commentBag) { var results = new List <CommentBlock>(); results.AddRange(base.FindCommentsForMembers(commentBag)); results.AddRange(Definitions.SelectMany(model => SymbolConverter.SearchComments(commentBag, model.Comments))); return(results); }
public List <CommentBag> ShowChannelComment(int id, int skip) { List <CommentBag> listComments = new List <CommentBag>(); using (var db = DatabaseFactory.OpenDbConnection()) { using (var trans = db.OpenTransaction(System.Data.IsolationLevel.ReadCommitted)) { try { if (db.SelectParam <Channel>(c => c.Visible == true).Exists(c => c.Id == id)) { List <Comment> comment = db.SelectParam <Comment>(cmt => cmt.IsNew == true && cmt.Visible == true && cmt.ChannelId == id && cmt.ParentId == null).Skip(5 * skip).Take(5).ToList(); foreach (Comment item in comment) { User user = db.SelectParam <User>(u => u.Id == item.UserId).FirstOrDefault(); CommentBag bag = new CommentBag() { AvatarUrl = user.AvatarUrl, UserName = user.FirstName + " " + user.LastName, UserId = user.Id, Id = item.Id, Text = item.Text, ParentId = item.ParentId, PostedOn = item.PostedOn, TopicId = item.TopicId, ChannelId = item.ChannelId, IsPageChannel = true, TopicName = db.SelectParam <Topic>(t => t.Id == item.TopicId).Select(t => t.Title).FirstOrDefault() }; listComments.Add(bag); //para cada comentário que vai ser mostrado, atualizar o BD sinalizando-o como não novo. //var dado = new Nimbus.Model.Comment() { IsNew = false }; //db.Update<Nimbus.Model.Comment>(dado, cmt => cmt.Id == item.Id); //trans.Commit(); } } } catch (Exception ex) { //trans.Rollback(); throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } } } return(listComments); }
public static List <CommentBlock> SearchComments( [NotNull] CommentBag commentBag, [CanBeNull] CommentBlockModel comments) { var results = new List <CommentBlock>(); if (comments != null) { if (comments.Location.HasValue) { var before = commentBag.TryFindBefore(comments.Location.Value); var after = commentBag.TryFindAfter(comments.Location.Value); if (before != null) { // this comment is on the same line. it's probably for current model var trimmedStart = before.GetText().TrimStart(' ').Substring(0, 5); var nIndex = trimmedStart.IndexOf("\n", StringComparison.Ordinal); if (nIndex >= 0 || before.Location.StartPos == 0) { results.Add(before); comments.AddComments(before); } } if (after != null) { var trimmedStart = after.GetText().TrimStart(' ').Substring(0, 5); var nIndex = trimmedStart.IndexOf("\n", StringComparison.Ordinal); // this comment is on the same line. it's probably for current model if (nIndex < 0) { results.Add(after); comments.AddComments(after); } } } } return(results); }
public CommentBag GetComment(int id) { using (var db = DatabaseFactory.OpenDbConnection()) { Comment comment = db.Where <Comment>(c => c.Id == id).FirstOrDefault(); if (comment == null) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Comment not found")); } Channel chn = db.Where <Channel>(c => c.Id == comment.ChannelId).FirstOrDefault(); User user = db.Where <User>(u => u.Id == comment.UserId).FirstOrDefault(); ChannelController cc = ClonedContextInstance <ChannelController>(); var userRoles = cc.ReturnRolesUser(chn.Id); bool isOwnerOrManager = (NimbusUser.UserId == chn.OwnerId || userRoles.Contains("channelmanager") || userRoles.Contains("topicmanager")); CommentBag bag = new CommentBag() { AvatarUrl = user.AvatarUrl, UserName = user.FirstName + " " + user.LastName, UserId = user.Id, Id = comment.Id, Text = comment.Text, ParentId = comment.ParentId, PostedOn = comment.PostedOn, IsNew = comment.IsNew, IsPageChannel = false, //pq só aparece na page channel qnd for novo IsAnswer = comment.IsAnswer, TopicId = comment.TopicId, IsParent = comment.ParentId > 0 ? false : true, ChannelId = comment.ChannelId, CommentChild = null, IsDeletable = (user.Id == NimbusUser.UserId || isOwnerOrManager) }; return(bag); } }
public virtual IEnumerable <CommentBlock> FindCommentsForMembers([NotNull] CommentBag commentBag) { return(SymbolConverter.SearchComments(commentBag, Comments)); }
public override IEnumerable <CommentBlock> FindCommentsForMembers(CommentBag commentBag) => SymbolConverter.SearchComments(commentBag, Path.Comments);
public abstract IEnumerable <CommentBlock> FindCommentsForMembers(CommentBag commentBag);
public List <CommentBag> ShowParentComment(int id, int skip = 0) { List <CommentBag> listComments = new List <CommentBag>(); using (var db = DatabaseFactory.OpenDbConnection()) { //pega todos comentários 'pai' List <Comment> comments = db.SelectParam <Comment>(cmt => cmt.Id == id && cmt.Visible == true && cmt.ParentId == null).ToList(); if (comments.Count > 0) { Channel chn = db.Where <Channel>(c => c.Id == comments.FirstOrDefault().ChannelId).FirstOrDefault(); ChannelController cc = ClonedContextInstance <ChannelController>(); var userRoles = cc.ReturnRolesUser(chn.Id); bool isOwnerOrManager = (NimbusUser.UserId == chn.OwnerId || userRoles.Contains("channelmanager") || userRoles.Contains("topicmanager")); foreach (Comment item in comments) { User user = db.SelectParam <User>(u => u.Id == item.UserId).FirstOrDefault(); //busco todos os filhos desse comentário List <Comment> cmtChild = db.SelectParam <Comment>(c => c.ParentId == item.Id && item.Visible == true).Take(3).ToList(); List <CommentBag> listChild = new List <CommentBag>(); foreach (var itemChild in cmtChild) { CommentBag child = new CommentBag(); User userChild = db.SelectParam <User>(u => u.Id == itemChild.UserId).FirstOrDefault(); string name = ""; if (itemChild.Text == "Comentário removido") { userChild.AvatarUrl = "/images/av130x130/person_icon.png"; name = "[removido]"; child.IsDeletable = false; child.IsRepotable = false; } else { name = userChild.FirstName + " " + userChild.LastName; child.IsDeletable = (userChild.Id == NimbusUser.UserId || isOwnerOrManager); child.IsRepotable = !isOwnerOrManager; } child.AvatarUrl = userChild.AvatarUrl; child.UserName = name; child.UserId = userChild.Id; child.Id = itemChild.Id; child.Text = itemChild.Text; child.ParentId = itemChild.ParentId; child.PostedOn = itemChild.PostedOn; child.IsNew = itemChild.IsNew; child.IsPageChannel = false; child.IsAnswer = itemChild.IsAnswer; child.TopicId = itemChild.TopicId; child.IsParent = false; child.ChannelId = itemChild.ChannelId; listChild.Add(child); } //crio o objeto para o comentario CommentBag bag = new CommentBag() { AvatarUrl = user.AvatarUrl, UserName = user.FirstName + " " + user.LastName, UserId = user.Id, Id = item.Id, Text = item.Text, ParentId = item.ParentId, PostedOn = item.PostedOn, IsNew = item.IsNew, IsAnswer = item.IsAnswer, TopicId = item.TopicId, IsParent = item.ParentId > 0 ? false : true, ChannelId = item.ChannelId, CommentChild = listChild, IsDeletable = (user.Id == NimbusUser.UserId || isOwnerOrManager), IsRepotable = !isOwnerOrManager }; listComments.Add(bag); } } } return(listComments); }
public CommentBag DeleteComment(Comment comment) { CommentBag bag = new CommentBag(); using (var db = DatabaseFactory.OpenDbConnection()) { Comment cmt = new Comment(); cmt = db.SelectParam <Comment>(c => c.Id == comment.Id).FirstOrDefault(); //pegar permissões Channel channel = db.Where <Channel>(c => c.Id == cmt.ChannelId && c.Visible == true).Where(c => c != null).FirstOrDefault(); var rolesUser = db.Where <Role>(r => r.ChannelId == cmt.ChannelId && r.UserId == NimbusUser.UserId).Where(r => r != null).FirstOrDefault(); bool isAllow = false; if (rolesUser != null) { isAllow = rolesUser.ChannelMagager == true || rolesUser.TopicManager == true; } if (NimbusUser.UserId == channel.OwnerId || cmt.UserId == NimbusUser.UserId || isAllow == true) { using (var trans = db.OpenTransaction(System.Data.IsolationLevel.ReadCommitted)) { try { //se ele é pai => apaga ele e os filhos // se ele é um filho => deixa visible, coloca fo to do usuario como avatar padrao, tira o nome e coloca texto como: comentario removido if (cmt.ParentId > 0) // é filho { cmt.Text = "Comentário removido"; cmt.IsNew = false; db.Update <Comment>(cmt, c => c.Id == cmt.Id); db.Save(cmt); bag.Text = "Comentário removido"; bag.ParentId = cmt.ParentId; bag.AvatarUrl = "/images/av130x130/person_icon.png"; bag.UserName = "******"; } else { IEnumerable <int> idChilds = db.SelectParam <Comment>(c => c.ParentId == comment.Id).Select(c => c.Id); foreach (int item in idChilds) { Comment ct = new Comment(); ct = db.SelectParam <Comment>(c => c.Id == item).FirstOrDefault(); if (ct != null) { ct.Visible = false; ct.IsNew = false; db.Update <Comment>(ct, c => c.Id == item); db.Save(ct); } } cmt.Visible = false; db.Update <Comment>(cmt, c => c.Id == cmt.Id); db.Save(cmt); bag.Id = cmt.Id; bag.ParentId = cmt.ParentId; } trans.Commit(); return(bag); } catch (Exception ex) { trans.Rollback(); throw; } } } } return(bag); }