public async Task <IActionResult> UploadImages([FromForm] UploadImageDto imageDto)
        {
            if (imageDto.Image == null)
            {
                return(BadRequest("Image file should be selected"));
            }
            if (imageDto.NewBiggestDimension < 100 || imageDto.NewBiggestDimension > 10000)
            {
                return(BadRequest("Dimension size should be between 100 and 10 000"));
            }

            try
            {
                var newImageId = await _imagesService.AddImage(imageDto.Image, imageDto.ImageName, imageDto.NewBiggestDimension);

                if (imageDto.TargetRecordId != null && imageDto.TargetRecordId != Guid.Empty)
                {
                    await _recordsImagesService.AddRecordImage(imageDto.TargetRecordId.Value, newImageId);
                }

                var newImageUri = $@"{await _appSettingsService.GetHostAndPort()}/api/v1.0/images/{newImageId}";

                return(Created(newImageUri, newImageId));
            }
            catch (ArgumentException exc)
            {
                return(BadRequest(exc.Message));
            }
        }
Exemple #2
0
        public async Task <IActionResult> AddImage([FromForm] ImagePostRequest request)
        {
            this.CheckUser(request.UserId);

            var image = await _imageService.AddImage(request);

            await AddInformationToImage(image);

            return(Created(Url.Link("GetImage", new { image.Id }), image));
        }
Exemple #3
0
 /// <summary>
 /// Додає зображення
 /// </summary>
 /// <param name="imageDto">Екземпляр зображення</param>
 public void AddImage(ImagesDtoModel imageDto) => imagesService.AddImage(imageDto);