Esempio n. 1
0
        public async Task AddImages([FromBody] IEnumerable <ImageViewModel> images)
        {
            var client = await _clientRepository.GetClient(int.Parse(User.GetName()));

            var newImages = await _imageService
                            .AddImagesAsync(client.Login, images.Select(i => i.Image));

            await _profileRepository.AddImages(client.Id, newImages);

            var imagesWithTags = newImages
                                 .Zip(images, (ni, i) => new
            {
                ni.Id,
                i.Tags
            });

            try
            {
                foreach (var it in imagesWithTags)
                {
                    await _profileRepository.AddTagsToImage(it.Id, it.Tags);
                }
            }
            catch (RepositoryException ex)
            {
                BadRequest(new { message = ex.Message });
            }
        }
Esempio n. 2
0
        public override async Task <FeedViewModel> AddAsync <TCreateRequest>(TCreateRequest createRequest)
        {
            if (!(createRequest is CreateFeedRequest request))
            {
                var message = GetImproperRequestErrorMessage(typeof(TCreateRequest), nameof(IFeedService));
                throw new ArgumentException(message);
            }

            var entity        = createRequest.CreateEntity();
            var createdEntity = await Repository.AddAsync(entity);

            await Repository.SaveChangesAsync();

            var tempEntity = await Repository.GetFeedWithAfflictionsById(createdEntity.Id);

            createdEntity.DogAfflictions = tempEntity.DogAfflictions;
            var viewModel = new FeedViewModel();

            viewModel.Construct(createdEntity);

            await _imageService.AddImagesAsync(request.Photos, viewModel.UniqueId);

            viewModel.PhotosIds = await _imageService.GetImagesIdsByOwnerGuidAsync(
                viewModel.UniqueId,
                CancellationToken.None);

            return(viewModel);
        }
Esempio n. 3
0
        public async Task <IActionResult> AddImagesAsync([FromBody] Guid ownerId)
        {
            await _imageService.AddImagesAsync(Request.Form.Files, ownerId);

            return(Ok());
        }