public async Task <IActionResult> Edit(int id, [FromBody] ContaAPagarResource contasAPagarResource) { try { var contasAPagar = await _unitOfWork.ContasAPagar.GetByIdAsync(id); if (ModelState.IsValid) { contasAPagar = ContaAPagarMapper.ResourceToModel(contasAPagarResource, contasAPagar); await _unitOfWork.CompleteAsync(); contasAPagar.TipoConta = await _unitOfWork.TipoContas.GetByIdAsync(contasAPagar.TipoContaId); ContaAPagarMapper.ModelToResource(contasAPagar); } return(Ok(contasAPagar)); } catch (Exception e) { LogError.LogErrorWithSentry(e); return(BadRequest(ModelState)); } }
public async Task <IActionResult> Create([FromBody] ContaAPagarResource contasAPagarResource) { if (contasAPagarResource == null) { return(NotFound()); } try { var contasAPagar = new ContaAPagar(); if (ModelState.IsValid) { contasAPagar = ContaAPagarMapper.ResourceToModel(contasAPagarResource, contasAPagar); } _unitOfWork.ContasAPagar.Add(contasAPagar); await _unitOfWork.CompleteAsync(); return(Ok(contasAPagar)); } catch (Exception exception) { LogError.LogErrorWithSentry(exception); return(BadRequest()); } }