public async Task <IActionResult> Put(int SetorId, SetorDto model) { try { var setor = await _repo.GetAllSetorAsyncById(SetorId); if (setor == null) { return(NotFound()); } _mapper.Map(model, setor); _repo.Update(setor); if (await _repo.SaveChangesAsync()) { return(Created($"/api/setor/{model.Id}", _mapper.Map <SetorDto>(setor))); } } catch (System.Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de Dados Falhou")); } return(BadRequest()); }
public async Task <IActionResult> Delete(SetorDto dto) { var result = new HttpResult <SetorDto>(this._logger); try { await this._app.Remove(dto); return(result.ReturnCustomResponse(this._app, dto)); } catch (Exception ex) { return(result.ReturnCustomException(ex, "Calemas.Erp - Setor", dto)); } }
public async Task <IActionResult> Post(SetorDto model) { try { var setor = _mapper.Map <Setor>(model); _repo.Add(setor); if (await _repo.SaveChangesAsync()) { return(Created($"/api/setor/{model.Id}", _mapper.Map <SetorDto>(setor))); } } catch (System.Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco de Dados Falhou {ex.Message}")); } return(BadRequest()); }