Esempio n. 1
0
        public Task DeleteVoucher(string code)
        {
            try
            {
                string encryptedCode = CodeGenerator.Encrypt(code);
                var    deleteTask    = _baseRepository.DeleteVoucherByCodeAsync(encryptedCode);
                var    deleteEvent   = new VoucherDeletedEvent()
                {
                    EventId = Guid.NewGuid(), EventTime = DateTime.Now,
                    Message = "Deleted voucher", VoucherCode = code
                };

                _logger.LogInformation("Deleted Voucher: {@DeleteEvent}", deleteEvent);
                return(deleteTask);
            }

            catch (Exception ex)
            {
                var deleteFailedEvent = new VoucherDeletionFailedEvent()
                {
                    EventId       = Guid.NewGuid(), EventTime = DateTime.Now,
                    Message       = "Could not perform delete on voucher", VoucherCode = code,
                    FailureReason = ex.Message
                };

                _logger.LogError("Deletion Failed on voucher: {@DeleteFailedEvent}", deleteFailedEvent);

                _logger.LogError(ex, "Could not perform delete operation on voucher with {Code}", code);
                return(null);
            }
        }