public async Task <AttachmentResponse> AddMessageAttachmentAsync(AddMessageAttachmentRequest request)
        {
            var message = await UnitOfWork.MessageRepository.GetMessageByIdAsync(request.MessageId);

            Ensure.That(message).WithException(x => new NotFoundException(new ErrorDto(ErrorCode.NotFound, "Message does not exist."))).IsNotNull();
            var messageAttachments = await UnitOfWork.AttachmentRepository.GetMessageAttachmentsAsync(message.Id);

            if (messageAttachments.Count == _attachmentConfiguration.Limit)
            {
                throw new LimitedAttachmentsException(new ErrorDto(ErrorCode.LimmitedAttachmentsError, "Attachments count is limited."));
            }

            var attachment = new Domain.Attachment.Attachment
            {
                Id          = Guid.NewGuid(),
                ContentType = request.ContentType,
                Created     = DateTimeOffset.UtcNow,
                FileName    = Guid.NewGuid() + "." + request.Extension,
                MessageId   = request.MessageId,
                Size        = request.Size
            };

            // Save attachment in database
            await UnitOfWork.AttachmentRepository.AddAttachmentAsync(attachment);

            // Save attachment in blob storage
            await _contentStorage.SaveContentAsync(attachment.FileName, request.Content, _cloudStorageConfiguration.MessageAttachmentsContainer);

            return(attachment.ToAttachmentResponse());
        }
        public static AttachmentResponse ToAttachmentResponse(this Domain.Attachment.Attachment attachment)
        {
            var attachmentResponse = new AttachmentResponse();

            if (attachment != null)
            {
                attachmentResponse.Id          = attachment.Id;
                attachmentResponse.ContentType = attachment.ContentType;
                attachmentResponse.Created     = attachment.Created;
                attachmentResponse.FileName    = attachment.FileName;
                attachmentResponse.MessageId   = attachment.MessageId;
                attachmentResponse.Size        = attachment.Size;
            }
            return(attachmentResponse);
        }