Esempio n. 1
0
        public ActionResult <VoucherDTO> Delete(int id)
        {
            try
            {
                var voucher = _voucherRepo.GetVoucherById(id);

                if (voucher == null)
                {
                    return(NotFound());
                }

                _voucherRepo.DeleteVoucher(id);
                _voucherRepo.Save();

                return(Ok("Voucher deleted."));
            }
            catch (Exception e)
            {
                _logger.LogError("Exception occurred while attempting to delete a Voucher.\nError: " + e.Message);
                return(BadRequest());
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Delete(int AccountId, int Id)
        {
            try
            {
                var Voucher = await _repository.GetVoucherAsync(AccountId, Id);

                if (Voucher == null)
                {
                    return(NotFound());
                }

                if (await _repository.DeleteVoucher(Voucher))
                {
                    return(Ok());
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest("Failed to delete the Voucher"));
        }