public async Task <IActionResult> UpdatePayment(Guid paymentId, PaymentForCreateDto payment) { if (paymentId == Guid.Empty) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var paymentToUpdate = await _paymentService.GetPaymentById(paymentId); if (paymentToUpdate == null) { return(NotFound()); } Mapper.Map(payment, paymentToUpdate); await _paymentService.UpdatePaymentAsync(paymentId, paymentToUpdate); return(NoContent()); }
public async Task <IActionResult> AddPayment(Guid billId, PaymentForCreateDto payment) { if (billId == Guid.Empty) { return(BadRequest()); } if (!await _billRepository.EntryExists(billId)) { return(NotFound()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var billFromRepo = await _billRepository.GetById(billId, true); var paymentToAdd = Mapper.Map <Payment>(payment); await _paymentService.AddBillPaymentAsync(billFromRepo, paymentToAdd); await _billRepository.Update(billId, billFromRepo); return(CreatedAtAction("GetPayments", new { billId = billFromRepo.Id }, billFromRepo)); }