コード例 #1
0
        public IActionResult UploadCarImage([FromForm(Name = "Image")] IFormFile file, [FromForm] CarImage carImage)
        {
            if (file == null)
            {
                return(BadRequest(new ErrorResult(CoreMessages.fileIsEmpty)));
            }

            var guid             = WebApiFileHelper.NewGuid();
            var fileDto          = new FileDto(ImageDir, guid, _imageExtension);
            var resultFromHelper = WebApiFileHelper.Add(file, fileDto);

            if (resultFromHelper.IsSuccess == false)
            {
                return(BadRequest(resultFromHelper));
            }

            var resultFromCarImageService = _carImageService.Add(carImage, fileDto);

            if (resultFromCarImageService.IsSuccess)
            {
                return(Ok(resultFromCarImageService));
            }

            return(BadRequest(resultFromCarImageService));
        }