예제 #1
0
        public IActionResult Create([FromBody] Foto foto)
        {
            if (foto == null)
            {
                return(BadRequest());
            }

            _fotoRepositorio.AddFoto(foto);
            return(new ObjectResult(_fotoRepositorio.FindByFoto(foto.idFoto)));
        }
예제 #2
0
        public IActionResult Upload(string cpf, Cliente cliente, Foto photo)
        {
            try
            {
                var file       = Request.Form.Files[0];
                var folderName = Path.Combine("RG", "Images");
                var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName);

                if (file.Length > 0)
                {
                    var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                    var fullPath = Path.Combine(pathToSave, fileName);
                    photo.caminhoFoto = Path.Combine(folderName, fileName);

                    using (var stream = new FileStream(fullPath, FileMode.Create))
                    {
                        file.CopyTo(stream);
                    }

                    var clientes = _clienteRepositorio.FindByCpf(cliente.cpf);
                    if (clientes != null)
                    {
                        photo.idCliente = clientes.idCliente;
                        _foto.AddFoto(photo);
                    }
                    return(Ok(new { photo.caminhoFoto }));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, "Internal server error" + ex));
            }
        }