コード例 #1
0
        public async Task <IActionResult> UploadCampaignAttachment([FromRoute] Guid campaignId, [FromForm] IFormFile file)
        {
            if (file == null)
            {
                ModelState.AddModelError(nameof(file), "File is empty.");
                return(BadRequest(new ValidationProblemDetails(ModelState)));
            }
            var campaign = await CampaignService.GetCampaignById(campaignId);

            if (campaign is null)
            {
                return(NotFound());
            }
            var attachment = await CampaignService.CreateAttachment(file);

            await CampaignService.AssociateCampaignAttachment(campaignId, attachment.Id);

            return(Ok(attachment));
        }