public async Task <IActionResult> GetAnnounce(int id) { var announce = await _announceRepository.GetAnnounce(id); var announceToReturn = _mapper.Map <AnnounceForReturnDto>(announce); return(Ok(announceToReturn)); }
public async Task <IActionResult> AddPhotoForAnnounce(int userId, int announceId, [FromForm] PhotoForCreationDto photoForCreationDto) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var announceFromRepo = await _announceRepo.GetAnnounce(announceId); var file = photoForCreationDto.File; var uploadResult = new ImageUploadResult(); if (file.Length > 0) { using (var stream = file.OpenReadStream()) { var uploadParams = new ImageUploadParams() { File = new FileDescription(file.Name, stream), //Transformation = new Transformation().Width(500).Height(500) }; uploadResult = _cloudinary.Upload(uploadParams); } } photoForCreationDto.Url = uploadResult.Uri.ToString(); photoForCreationDto.PublicId = uploadResult.PublicId; var photo = _mapper.Map <PhotoForAnnounce>(photoForCreationDto); announceFromRepo.PhotosForAnnounce.Add(photo); if (await _repo.SaveAll()) { var photoToReturn = _mapper.Map <PhotoForReturnDto>(photo); return(CreatedAtRoute("GetAnnouncePhoto", new { userId, id = photo.Id }, photoToReturn)); } return(BadRequest("Eroare la adaugarea pozei.")); }