Beispiel #1
0
        public bool AddFotoCavalo(FotoForCreationDto fotoForCreationDto, Cloudinary cloudinary, int idCavalo)
        {
            var file = fotoForCreationDto.File;

            var uploadResult = new ImageUploadResult();

            if (file.Length > 0)
            {
                using (var stream = file.OpenReadStream())
                {
                    var uploadParams = new ImageUploadParams
                    {
                        File = new FileDescription(file.Name, stream)
                    };

                    uploadResult = cloudinary.Upload(uploadParams);
                }
            }

            fotoForCreationDto.Url      = uploadResult.Uri.ToString();
            fotoForCreationDto.PublicId = uploadResult.PublicId;

            var foto = _mapper.Map <Foto>(fotoForCreationDto);

            foto.IsMain   = true;
            foto.CavaloId = idCavalo;

            _fotoRepository.Add(foto);

            return(true);
        }
Beispiel #2
0
        public bool AddFotoCavalo(FotoForCreationDto fotoForCreationDto, Cloudinary cloudinary, int loteId)
        {
            var fotoAdicionada = _fotoService.AddFotoCavalo(fotoForCreationDto, cloudinary, loteId);

            if (fotoAdicionada)
            {
                if (Commit())
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #3
0
        public IActionResult AddFotoCavalo([FromForm] FotoForCreationDto fotoForCreationDto, int loteId)
        {
            try
            {
                if (_loteService.AddFotoCavalo(fotoForCreationDto, _cloudinary, loteId))
                {
                    return(Created("", new { }));
                }

                throw new Exception("Houve um Erro ao Salvar a Imagem do Leilao");
            }
            catch (Exception exception)
            {
                return(BadRequest(exception));
            }
        }
Beispiel #4
0
        public bool AddFotoLeilao(FotoForCreationDto fotoForCreationDto, Cloudinary cloudinary)
        {
            var fotoId = _fotoService.AddFotoLeilao(fotoForCreationDto, cloudinary);

            var leilao = _leilaoRepository.Find(x => x.Id == fotoForCreationDto.LeilaoId).FirstOrDefault();

            if (leilao != null)
            {
                leilao.FotoId = fotoId;

                _leilaoRepository.Update(leilao);

                if (Commit())
                {
                    return(true);
                }
            }

            return(false);
        }