I'm not sure what's happening to my code. I'm following the course and the idea is to create in the form a place to upload image using my C# .Net + Angular gallery manager application. The error happens at var galeria = await _galeriaService.GetGaleriaByIdAsync(galeriaId, true);:
Cannot assign void to an implicit type variable CS0815.
The following map is from my controller:
[HttpPost("upload-image/{galeriaId}")]
public async Task<IActionResult> UploadImage(int galeriaId)
{
try {
var galeria = await _galeriaService.GetGaleriaByIdAsync(galeriaId, true);
if(galeria == null) return NoContent();
var file = Request.Form.Files[0];
if (file.Length > 0)
{
// DeleteImage(galeria.ImagemURL);
//galeria.ImagemURL = SaveImage(file);
}
var GaleriaRetorno = await _galeriaService.UpdateGaleria(galeriaId, galeria);
return Ok(GaleriaRetorno);
}
catch (Exception ex)
{
return this.StatusCode(StatusCodes.Status500InternalServerError, $"Erro ao tentar adicionar galeria. Erro {ex.Message}");
}
}
Return type of GetGaleriaByIdAsync
Task<Galeria> IGaleriaService.GetGaleriaByIdAsync(int galeriaId)
{
throw new NotImplementedException();
}
IGaleriaService
namespace GestorGaleria.Application.Contratos
{
public interface IGaleriaService
{
Task<GaleriaDto> AddGaleria(GaleriaDto model);
Task<GaleriaDto> UpdateGaleria(int id, GaleriaDto model);
Task<bool> DeleteGaleria(int id);
Task<GaleriaDto[]> GetAllGaleriasAsync();
Task UpdateGaleria(int galeriaId, Galeria galeria);
Task<Galeria> GetGaleriaByIdAsync(int galeriaId);
}
}