public async Task <ActionResult <Claim> > AddClaimAttachment([FromForm] AddClaimAttachmentApiModel addClaimAttachmentApiModel)
        {
            ////I assume that we accept more than one file each request.
            if (this.Request.Form.Files.Count != 1)
            {
                ////TODO add error model for missing file attached to the request
                return(this.BadRequest());
            }

            ////Take this out from there and make it reusable.
            var file = this.Request.Form.Files[0];

            var fileAttachment = await file.ReadToFileAttachmentModel();

            var addClaimAttachmentApiRequest =
                new AddClaimAttachmentWithFileApiRequest(addClaimAttachmentApiModel, fileAttachment);

            var newClaimAttachment = await this.mediator.Send(addClaimAttachmentApiRequest);

            ////TODO find the best way to handle bad requests. Exception or null returns ?
            if (newClaimAttachment == null || newClaimAttachment.ClaimAttachmentId == null)
            {
                return(this.BadRequest());
            }

            return(this.CreatedAtRoute(nameof(GetSingleClaimAttachment), new { id = newClaimAttachment }));
        }
Exemplo n.º 2
0
        public AddClaimAttachmentWithFileApiRequest(
            AddClaimAttachmentApiModel addClaimAttachmentApiModel,
            FileAttachmentModel fileAttachment)
        {
            Ensure.That(addClaimAttachmentApiModel, nameof(addClaimAttachmentApiModel)).IsNotNull();
            Ensure.That(fileAttachment, nameof(fileAttachment)).IsNotNull();

            this.AddClaimAttachmentApiModel = addClaimAttachmentApiModel;
            this.FileAttachment             = fileAttachment;
        }
        public AddClaimAttachmentApiRequest(AddClaimAttachmentApiModel addClaimAttachmentApiModel)
        {
            Ensure.That(addClaimAttachmentApiModel, nameof(addClaimAttachmentApiModel)).IsNotNull();

            this.AddClaimAttachmentApiModel = addClaimAttachmentApiModel;
        }