public async Task Create(CreateDebtRequest request) { Debtor debtor = await _debtorRepository.GetByIdWithIncludes(request.DebtorId); if (debtor is null) { throw new AppCustomException(StatusCodes.Status400BadRequest, "Debtor does not exist"); } Debt debt = _mapper.Map <CreateDebtRequest, Debt>(request); debtor.Debts.Add(debt); await _debtorRepository.Update(debtor); }
public async Task <IActionResult> Update([FromBody] DebtorViewModel model) { if (model == null) { return(StatusCode(400, "Invalid parameter(s).")); } Debtor debtor = new Debtor { Id = model.Id, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, BankAccount = model.BankAccount, Phone = model.Phone, CompanyName = model.CompanyName }; //Update debtor var data = await _repo.Update(debtor); if (data == null) { return(StatusCode(500, "A problem occured while updating the record. Please try again!")); } var result = new DebtorViewModel(); result.SetProperties(data, false, false); return(Ok(result)); }