Esempio n. 1
0
        public Response <IEnumerable <Attachment> > AddAttachment(AddAttachmentRequest request)
        {
            Response <IEnumerable <Attachment> > response = new Response <IEnumerable <Attachment> >();

            if (request == null || request.attachments == null || !request.attachments.Any())
            {
                ArgumentNullException ex = new ArgumentNullException("AddAttachment request");
                LogError(ex);
                response.ErrorCode = ErrorCode.Argument;
                response.Exception = ex;
                return(response);
            }

            try
            {
                AttachmentAccessor accessor = new AttachmentAccessor();
                response.Result    = accessor.AddAttachments(request.attachments, request.IsCoverOld);
                response.IsSuccess = true;
            }
            catch (Exception ex)
            {
                LogError(ex);
                response.IsSuccess = false;
                response.ErrorCode = ErrorCode.Technical;
            }

            return(response);
        }
        public async Task <IActionResult> AddAttachmentAsync([FromBody] AddAttachmentRequest request)
        {
            Attachment attachment = new();

            attachment.Filename = request.Filename;
            attachment.Message  = await messageService.GetByIdAsync(request.MessageId);

            attachment.Url = "-";

            await attachmentService.AddAsync(attachment);

            return(Ok());
        }
Esempio n. 3
0
        public IHttpActionResult Add(AddAttachmentRequest request)
        {
            request.ValidateNotNull();

            // convert from request model to domain model
            var attachmentDomain = new AttachmentDomain()
            {
                File = request.File
            };

            return(Ok(new AddAttachmentResponse()
            {
                Data = _attachmentManipulation.AddAttachment(attachmentDomain),
                Success = Common.Enumerations.ResponseStatus.Succeeded
            }));
        }
Esempio n. 4
0
        public async Task <IActionResult> AddAttachment([FromRoute] int id, [FromForm] AddAttachmentRequest request)
        {
            if (request?.File == null || request.File.Length == 0)
            {
                throw new InvalidOperationException("Missing attachment data.");
            }

            byte[] data = await request.File.GetBytes();

            await _dispatcher.Command(new CreateAttachment
            {
                MailId   = id,
                FileName = request.File.FileName,
                File     = data
            });

            return(Created(new Uri($"/mails/{id}", UriKind.Relative), new { id }));
        }