public async Task <IActionResult> Delete(long VendedorId, string Token) { var TokenApi = new Token { TokenDef = _config.GetValue <string>("Token:TokenDef") }; if (TokenApi.TokenDef != Token) { return(this.StatusCode(StatusCodes.Status401Unauthorized, $"O Token informado não é autorizado.")); } try { var evento = await _repo.GetVendedorByIdAsync(VendedorId); if (evento == null) { return(NotFound()); } _repo.Delete(evento); if (await _repo.SaveChangesAsync()) { return(Ok()); } } catch (System.Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco de Dados Falhou. {ex.Message}")); } return(BadRequest()); }
public async Task <IActionResult> Delete(FotoImovelDelete model, string Token) { var TokenApi = new Token { TokenDef = _config.GetValue <string>("Token:TokenDef") }; if (TokenApi.TokenDef != Token) { return(this.StatusCode(StatusCodes.Status401Unauthorized, $"O Token informado não é autorizado.")); } try { if (model.TipoFoto == 2) //Imovel { var fotos = await _repo.GetFotosImovelByIdAsync(model.ImovelId); if (fotos.Count() <= 0) { return(NoContent()); } var foto = fotos.Where(x => x.Id == model.FotoId).FirstOrDefault(); _repo.Delete(foto); } else if (model.TipoFoto == 6) //Area { var fotos = await _repo.GetFotosAreaImovelByIdAsync(model.ImovelId); if (fotos.Count() <= 0) { return(NoContent()); } var foto = fotos.Where(x => x.Id == model.FotoId).FirstOrDefault(); _repo.Delete(foto); } else if (model.TipoFoto == 7) //Planta { var fotos = await _repo.GetFotosPlantaImovelByIdAsync(model.ImovelId); if (fotos.Count() <= 0) { return(NoContent()); } var foto = fotos.Where(x => x.Id == model.FotoId).FirstOrDefault(); _repo.Delete(foto); } else { return(NotFound()); } if (await _repo.SaveChangesAsync()) { return(this.StatusCode(StatusCodes.Status200OK)); } } catch (System.Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco de Dados Falhou. {ex.Message}")); } return(BadRequest()); }