Esempio n. 1
0
        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));
            }
        }
Esempio n. 2
0
        public async Task OnPostSaveUpdatedAsNewImageAsync(Guid imageId, Guid?recordId)
        {
            RecordId = recordId;
            var newImageId = await _imagesEditService.CreateNewImageFromChanged(imageId);

            if (RecordId != null && RecordId.Value != Guid.Empty)
            {
                await _recordImagesService.AddRecordImage(RecordId.Value, newImageId);
            }
            await UpdateModel(newImageId);
        }
        public async Task <IActionResult> AddImageToRecord(Guid recordId, Guid imageId, [FromQuery] int?order)
        {
            try
            {
                await _recordImagesService.AddRecordImage(recordId, imageId, order);

                return(Ok());
            }
            catch (ArgumentException exc)
            {
                return(BadRequest(exc.Message));
            }
        }
Esempio n. 4
0
        public async Task AddImageForRecord_AfterDeletingTheSame_ShouldUnmarkAsDeleted()
        {
            var(recId, imgId, recImgSvc, imgSvc, context) = await CreateRecordWithLinkedImage();

            context.SoftDeleting = true;

            await recImgSvc.RemoveRecordImage(recId, imgId);

            await recImgSvc.AddRecordImage(recId, imgId);

            int bindedRecordCount = await context.RecordImages.CountAsync(br => br.RecordId == recId && br.ImageId == imgId);

            bindedRecordCount.Should().Be(1);
        }