public ActionResult <VoucherDTO> Post([FromBody] VoucherDTO voucherDto) { try { if (!ModelState.IsValid) { _logger.LogError("Invalid model state."); return(BadRequest()); } else { var voucher = _mapper.Map <Voucher>(voucherDto); _voucherRepo.AddVoucher(voucher); _voucherRepo.Save(); return(Created($"/api/Vouchers/{voucher.VoucherId}", voucherDto)); } } catch (Exception e) { _logger.LogError("Exception occurred while attempting to add a Voucher.\nError: " + e.Message); return(BadRequest()); } }