Example #1
0
        public void UpdateComment(WorkTask.Comment comment)
        {
            var workTask = _workTaskCollection.Find(x => x.Id == comment.WorkTaskId.ToPersistenceIdentity()).FirstOrDefault();

            if (workTask == null)
            {
                throw CreateEntityNotFoundException(comment.WorkTaskId);
            }

            var entity = workTask.Comments.FirstOrDefault(x => x.Id == comment.Id.ToPersistenceIdentity());

            if (entity == null)
            {
                throw CreateEntityNotFoundException(comment.Id);
            }

            entity.Content = comment.Content;

            var result = _workTaskCollection.ReplaceOne(x => x.Id == workTask.Id, workTask);

            if (result.MatchedCount != 1)
            {
                throw CreateEntityNotFoundException(comment.WorkTaskId);
            }
        }
Example #2
0
 public static MComment ToPersistenceEntity(this Comment comment)
 {
     return(new MComment
     {
         Id = comment.Id.ToPersistenceIdentity(),
         AuthorId = comment.AuthorId.ToPersistenceIdentity(),
         Content = comment.Content,
     });
 }
Example #3
0
        public Identity AddComment(WorkTask.Comment comment)
        {
            if (comment == null || _workTaskCollection.Find(x => x.Id == comment.WorkTaskId.ToPersistenceIdentity()).FirstOrDefault() == null)
            {
                throw CreateInvalidEntityException();
            }

            var entity           = comment.ToPersistenceEntity();
            var updateDefinition = Builders <MWorkTask> .Update
                                   .Push(x => x.Comments, entity);

            var result = _workTaskCollection.UpdateOne(x => x.Id == comment.WorkTaskId.ToPersistenceIdentity(), updateDefinition);

            if (result.MatchedCount != 1)
            {
                throw CreateEntityNotFoundException(comment.WorkTaskId);
            }

            return(comment.Id);
        }