public async Task <bool> AttachmentToComment(CommentAttachmentViewModel commentAttachment) { var comment = await _publicContext.Comment.FirstOrDefaultAsync(x => x.Id == commentAttachment.CommentId); if (comment == null) { ExceptionFactory.SoftException(ExceptionEnum.CommentNotFound, "Comment not found"); } if (!await _publicContext.Attachment.AnyAsync(x => x.Id == commentAttachment.AttachmentId)) { ExceptionFactory.SoftException(ExceptionEnum.AttachmentNotFound, $"Attachment {commentAttachment.AttachmentId} not found"); } var attachmentToComment = new AttachmentComment() { AttachmentId = commentAttachment.AttachmentId, CommentId = commentAttachment.CommentId, }; await _publicContext.AttachmentComment.AddAsync(attachmentToComment); await _publicContext.SaveChangesAsync(); return(true); }
public async Task <bool> CreateCommentAttachment(CommentAttachmentViewModel commentAttachment) { return(await _attachmentService.AttachmentToComment(commentAttachment)); }