public bool DeleteCommentComment(ICommentable entity, MongoObjectId commentId, MongoObjectId commentCommentId) { if (entity == null) { return(false); } var comment = entity.Comments.Where(c => c.Id == commentId).SingleOrDefault(); if (comment == null) { return(false); } var commentComment = comment.Comments.Where(c => c.Id == commentCommentId).SingleOrDefault(); if (commentComment == null || (commentComment.UserObjectId != CurrentUser.Id && CurrentUser.Role != UserRoles.Admin)) { return(false); } comment.Comments.Remove(commentComment); UpdateEntity(entity); bus.Send(new CommentDeletedCommand() { CommentId = commentCommentId, EntryType = entity.EntryType, UserObjectId = CurrentUser.Id }); return(true); }
private Project GetProject(MongoObjectId projectId) { using (var noSqlSession = noSqlSessionFactory()) { return(noSqlSession.GetById <Project>(projectId)); } }
public Liking UndoLikeComment(ICommentable entity, MongoObjectId commentId, MongoObjectId parentCommentId) { Comment comment, parentComment = null; if (parentCommentId != null) { parentComment = GetComment(entity, parentCommentId); comment = parentComment.Comments.Where(c => c.Id == commentId).SingleOrDefault(); } else { comment = GetComment(entity, commentId); } if (!comment.SupportingUserIds.Contains(CurrentUser.Id)) { return(null); } comment.SupportingUserIds.Remove(CurrentUser.Id); UpdateEntity(entity); var command = new CommentUnlikedCommand { ObjectId = entity.Id, CommentId = commentId, EntryType = entity.EntryType, UserObjectId = CurrentUser.Id }; bus.Send(command); return(GetCommentViewFromComment(entity.Id, comment, parentCommentId, entity.EntryType).Liking); }
private Lucene.Net.Documents.Document CreateDoc(MongoObjectId id, string text, string subject, EntryTypes type) { Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document(); doc.Add(new Lucene.Net.Documents.Field( "text", new System.IO.StringReader(text.StripHtml()))); doc.Add(new Lucene.Net.Documents.Field( "id", id.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.UN_TOKENIZED)); doc.Add(new Lucene.Net.Documents.Field( "subject", subject, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.UN_TOKENIZED)); doc.Add(new Lucene.Net.Documents.Field( "type", type.ToString(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.UN_TOKENIZED)); // For the highlighter, store the raw text doc.Add(new Lucene.Net.Documents.Field( "raw_text", text.StripHtml(), Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.UN_TOKENIZED)); return(doc); }
public virtual CommentView AddNewComment(MongoObjectId id, string text, EmbedModel embed, ForAgainst forAgainst = ForAgainst.Neutral, MongoObjectId versionId = null) { var entity = GetEntity(id); var comment = commentService.AddNewComment(entity, forAgainst, text, embed, versionId); SendCommentCommand(entity, GetAddNewCommentActionType(), comment); return(comment); }
public CommentView AddNewCommentToComment(MongoObjectId id, MongoObjectId commentId, string text, EmbedModel embed) { var entity = GetEntity(id); var comment = commentService.AddNewCommentToComment(entity, commentId, text, embed); SendCommentCommand(entity, ActionTypes.CommentCommented, comment); return(comment); }
public Liking LikeComment(MongoObjectId id, MongoObjectId commentId, MongoObjectId parentCommentId) { var entity = GetEntity(id); var comment = commentService.LikeComment(entity, commentId, parentCommentId); SendCommentCommand(entity, string.IsNullOrEmpty(parentCommentId) ? GetLikeCommentActionType() : ActionTypes.CommentCommentLiked, comment); return(comment.Liking); }
private Idea GetIdea(MongoObjectId ideaId, params string[] additionalFields) { string[] defaultFields = new string[] { "_id", "Subject", "State", "Deadline", "VotesCount", "RequiredVotes" }; additionalFields = defaultFields.Union(additionalFields).ToArray(); using (var noSqlSession = noSqlSessionFactory()) { return(noSqlSession.Find <Idea>(Query.EQ("_id", ideaId)).SetFields(additionalFields).SingleOrDefault()); } }
private Comment GetComment(ICommentable entity, MongoObjectId commentId, MongoObjectId parentCommentId) { if (!string.IsNullOrEmpty(parentCommentId)) { var parentComment = GetComment(entity, parentCommentId); return(parentComment.Comments.SingleOrDefault(c => c.Id == commentId)); } return(GetComment(entity, commentId)); }
private string GetUserFullName(MongoObjectId id) { using (var session = noSqlSessionFactory()) { var user = session.Find <Data.MongoDB.User>(Query.EQ("_id", id)).SetFields("FirstName", "LastName").SingleOrDefault(); if (user != null) { return(user.FullName); } return(string.Empty); } }
public CommentView LikeComment(ICommentable entity, MongoObjectId commentId, MongoObjectId parentCommentId) { Comment comment = GetComment(entity, commentId, parentCommentId); if (comment == null || comment.SupportingUserIds.Contains(CurrentUser.Id)) { return(null); } comment.SupportingUserIds.Add(CurrentUser.Id); UpdateEntity(entity); return(GetCommentViewFromComment(entity.Id, comment, parentCommentId, entity.EntryType)); }
public CommentView AddNewCommentToComment(ICommentable entity, MongoObjectId commentId, string text, EmbedModel embed) { if (CurrentUser.RequireUniqueAuthentication && !CurrentUser.IsUnique) { throw new UserNotUniqueException(); } var comment = GetComment(entity, commentId); if (comment == null) { return(null); } comment.LastNumber++; var cComment = new Comment { Date = DateTime.Now, Text = text, UserFullName = CurrentUser.FullName, UserObjectId = CurrentUser.Id, Number = comment.Number + comment.LastNumber }; if (embed != null && !embed.IsEmpty) { cComment.Embed = new Data.MongoDB.Embed(); cComment.Embed.InjectFrom(embed); cComment.Embed.Title = cComment.Embed.Title.Sanitize(); cComment.Embed.Description = cComment.Embed.Description.Sanitize(); } comment.Comments.Add(cComment); UpdateEntity(entity); var model = GetCommentViewFromComment(entity.Id, cComment, commentId, entity.EntryType, entity.GetRelatedVersionNumber(comment.RelatedVersionId)); model.SubscribeMain = ActionService.Subscribe(entity.Id, CurrentUser.DbId.Value, entity.EntryType); model.Subscribe = ActionService.Subscribe(comment.Id, CurrentUser.DbId.Value); return(model); }
public void DeleteIndex(MongoObjectId id) { Lucene.Net.Index.IndexModifier modifier = null; try { if (searcher != null) { try { searcher.Close(); } catch (Exception e) { logger.Error("Exception closing lucene searcher:" + e.Message, e); throw; } searcher = null; } modifier = new Lucene.Net.Index.IndexModifier(CustomAppSettings.SearchIndexFolder, analyzer, false); // same as build, but uses "modifier" instead of write. // uses additional "where" clause for bugid modifier.DeleteDocuments(new Lucene.Net.Index.Term("id", id.ToString())); } catch (Exception e) { logger.Error("Exception closing lucene searcher:" + e.Message, e); } finally { if (modifier != null) { modifier.Flush(); modifier.Close(); } } }
public FileViewModel GetFile <T>(MongoObjectId id) { var file = db.GridFS.FindOneById(id); if (file != null) { using (var stream = file.OpenRead()) { var bytes = new byte[stream.Length]; stream.Read(bytes, 0, (int)stream.Length); return(new FileViewModel { ContentType = file.ContentType, File = bytes }); } } return(null); }
private string GetUserFullName(string id) { if (string.IsNullOrEmpty(id)) { return(CommonStrings.All); } if (id == TodoAssignedTo.Unasigned) { return(CommonStrings.Unassigned); } using (var session = noSqlSessionFactory()) { MongoObjectId mid = id; var user = session.Find <Data.MongoDB.User>(Query.EQ("_id", mid)).SetFields("FirstName", "LastName").SingleOrDefault(); if (user != null) { return(user.FullName); } return(string.Empty); } }
public void UpdateById <T>(MongoObjectId id, IMongoUpdate update) { db.GetCollection <T>().Update(Query.EQ("_id", id), update); }
public T FindByIdAndModify <T>(MongoObjectId id, IMongoUpdate update) { return(db.GetCollection <T>().FindAndModify(Query.EQ("_id", id), SortBy.Ascending("_id"), update, true).GetModifiedDocumentAs <T>()); }
public ExpandableList <CommentView> GetCommentsByVersion(MongoObjectId id, MongoObjectId versionId, int pageNumber, ForAgainst?posOrNeg = null) { var entity = GetEntity(id); return(commentService.GetCommentsByVersion(entity, versionId, pageNumber, posOrNeg)); }
public ExpandableList <CommentView> GetCommentsMostRecent(MongoObjectId id, int pageNumber, ForAgainst?posOrNeg = null, bool orderResultAsc = false) { var entity = GetEntity(id); return(commentService.GetCommentsMostRecent(entity, pageNumber, posOrNeg, orderResultAsc)); }
public ExpandableList <CommentView> GetCommentsMostSupported(MongoObjectId id, int pageNumber, ForAgainst?posOrNeg = null) { var entity = GetEntity(id); return(commentService.GetCommentsMostSupported(entity, pageNumber, posOrNeg)); }
protected virtual ICommentable GetEntity(MongoObjectId id) { throw new NotImplementedException(); }
public void UpdateIndex(MongoObjectId id, EntryTypes type) { if (id == null) { return; } Lucene.Net.Index.IndexModifier modifier = null; try { if (searcher != null) { try { searcher.Close(); } catch (Exception e) { logger.Error("Exception closing lucene searcher:" + e.Message, e); throw; } searcher = null; } modifier = new Lucene.Net.Index.IndexModifier(CustomAppSettings.SearchIndexFolder, analyzer, false); // same as build, but uses "modifier" instead of write. // uses additional "where" clause for bugid modifier.DeleteDocuments(new Lucene.Net.Index.Term("id", id.ToString())); using (var noSqlSession = noSqlSessionFactory()) { switch (type) { case EntryTypes.Idea: var idea = noSqlSession.GetById <Idea>(id); if (idea != null) { modifier.AddDocument(CreateDoc(id, CreateSearchText(idea), idea.Subject, type)); } break; case EntryTypes.Issue: var issue = noSqlSession.GetById <Issue>(id); if (issue != null) { modifier.AddDocument(CreateDoc(id, CreateSearchText(issue), issue.Subject, type)); } break; case EntryTypes.User: var user = noSqlSession.GetById <User>(id); if (user != null) { modifier.AddDocument(CreateDoc(id, user.FullName, user.FullName, type)); } break; case EntryTypes.Organization: var org = noSqlSession.GetById <Organization>(id); if (org != null) { modifier.AddDocument(CreateDoc(id, org.Name, org.Name, type)); } break; case EntryTypes.Problem: var prob = noSqlSession.GetById <Problem>(id); if (prob != null) { modifier.AddDocument(CreateDoc(id, CreateSearchText(prob), prob.Text.LimitLength(100), type)); } break; default: break; } } } catch (Exception e) { logger.Error("exception updating Lucene index: " + e.Message, e); } finally { try { if (modifier != null) { modifier.Flush(); modifier.Close(); } } catch (Exception e) { logger.Error("exception updating Lucene index: " + e.Message, e); } } }
public ExpandableList <CommentView> GetCommentsByVersion(ICommentable entity, MongoObjectId versionId, int pageNumber, ForAgainst?posOrNeg = null) { var comments = new List <CommentView>(); var query = entity.Comments.AsEnumerable(); if (posOrNeg.HasValue) { query = query.Where(c => c.PositiveOrNegative == posOrNeg); } foreach (var comment in query.Where(c => c.RelatedVersionId == versionId).OrderByDescending(c => c.SupportingUserIds.Count).ThenByDescending(c => c.Date).GetExpandablePage(pageNumber, CustomAppSettings.PageSizeComment)) { comments.Add(GetCommentViewWithComments(entity, comment)); } return(new ExpandableList <CommentView>(comments, CustomAppSettings.PageSizeComment)); }
public virtual CommentView AddNewComment(ICommentable entity, ForAgainst forAgainst, string text, EmbedModel embed, MongoObjectId versionId = null) { if (CurrentUser.RequireUniqueAuthentication && !CurrentUser.IsUnique) { throw new UserNotUniqueException(); } if (entity.Id == CurrentUser.Id) { forAgainst = ForAgainst.Neutral; } entity.LastNumber++; var comment = new Comment { Date = DateTime.Now, Text = text, UserFullName = CurrentUser.FullName, UserObjectId = CurrentUser.Id, RelatedVersionId = versionId, PositiveOrNegative = forAgainst, Number = entity.LastNumber.ToString() + "." }; if (embed != null && !embed.IsEmpty) { comment.Embed = new Data.MongoDB.Embed(); comment.Embed.InjectFrom(embed); comment.Embed.Title = comment.Embed.Title.Sanitize(); comment.Embed.Description = comment.Embed.Description.Sanitize(); } entity.Comments.Add(comment); UpdateEntity(entity); var model = GetCommentViewFromComment(entity.Id, comment, null, entity.EntryType, entity.GetRelatedVersionNumber(comment.RelatedVersionId)); model.SubscribeMain = ActionService.Subscribe(entity.Id, CurrentUser.DbId.Value, entity.EntryType); model.Subscribe = ActionService.Subscribe(comment.Id, CurrentUser.DbId.Value); return(model); }
private Idea GetIdea(MongoObjectId ideaId) { return(GetIdea(ideaId, new string[] {})); }
public CommentView GetCommentViewFromComment(string objectId, Data.MongoDB.Comment comment, MongoObjectId parentId, EntryTypes type, string relatedVersion = null) { var hiddenText = Globalization.Resources.Comments.Resource.CommentHidden; var model = new CommentView { CommentText = comment.IsHidden ? hiddenText : comment.Text.NewLineToHtml().ActivateLinks() ?? string.Empty, CommentDate = comment.Date, AuthorFullName = comment.UserFullName, AuthorObjectId = comment.UserObjectId, ForAgainst = comment.PositiveOrNegative, ProfilePictureThumbId = UserService.GetProfilePictureThumbId(comment.UserObjectId), Liking = new Liking() { EntryId = objectId, ParentId = parentId, CommentId = comment.Id, Type = type, LikesCount = GetLikesCountString(comment.SupportingUserIds.Count), IsLikeVisible = !comment.IsHidden && CurrentUser.IsAuthenticated && !comment.SupportingUserIds.Contains(CurrentUser.Id) && comment.UserObjectId != CurrentUser.Id, IsUnlikeVisible = !comment.IsHidden && CurrentUser.IsAuthenticated && comment.SupportingUserIds.Contains(CurrentUser.Id) && comment.UserObjectId != CurrentUser.Id }, Id = comment.Id, IsCreatedByCurrentUser = CurrentUser.IsAuthenticated && (comment.UserObjectId == CurrentUser.Id || CurrentUser.Role == UserRoles.Admin), IsCommentable = type != EntryTypes.Problem && CurrentUser.IsAuthenticated, ParentId = parentId, EntryId = objectId, VersionId = comment.RelatedVersionId, RelatedVersion = relatedVersion, EntryType = type, IsHidden = comment.IsHidden, Number = comment.Number, Embed = comment.Embed != null ? new EmbedModel() { Url = comment.Embed.Url, Author_Name = comment.Embed.Author_Name, Author_Url = comment.Embed.Author_Url, Cache_Age = comment.Embed.Cache_Age, Description = comment.Embed.Description, Height = comment.Embed.Height, Html = comment.Embed.Type != "link" ? comment.Embed.Html : string.Empty, Provider_Name = comment.Embed.Provider_Name, Provider_Url = comment.Embed.Provider_Url, Thumbnail_Url = comment.Embed.Thumbnail_Url, Title = comment.Embed.Title, Type = comment.Embed.Type, Version = comment.Embed.Version, Width = comment.Embed.Width } : null }; if (CurrentUser.IsAuthenticated && parentId == null) { model.Subscribe = ActionService.IsSubscribed(comment.Id, CurrentUser.DbId.Value); } //model.Liking.IsCreatedByCurrentUser = CurrentUser.IsAuthenticated && comment.UserObjectId == CurrentUser.Id; return(model); }
public Liking UndoLikeComment(MongoObjectId id, MongoObjectId commentId, MongoObjectId parentCommentId) { var entity = GetEntity(id); return(commentService.UndoLikeComment(entity, commentId, parentCommentId)); }
public bool DeleteComment(MongoObjectId id, MongoObjectId commentId) { var entity = GetEntity(id); return(commentService.DeleteComment(entity, commentId)); }
private Comment GetComment(ICommentable entity, MongoObjectId commentId) { return(entity.Comments.Where(c => c.Id == commentId).SingleOrDefault()); }