コード例 #1
0
        public async Task <IActionResult> Delete(int id)
        {
            var paymentChannel = await _ercContext.PaymentChannels.FirstOrDefaultAsync(x => x.Id == id);

            if (paymentChannel is null)
            {
                return(NotFound());
            }

            _ercContext.Remove(paymentChannel);
            await _ercContext.SaveChangesAsync();

            return(Ok());
        }
コード例 #2
0
        protected override async Task Handle(DeletePaymentCommand request, CancellationToken cancellationToken)
        {
            var payment = await _ercContext.Payments.FindAsync(request.Id);

            if (payment is null)
            {
                return;
            }

            if (payment.Status == PaymentStatus.Processed)
            {
                throw new Exception("The payment has been processed and cannot be removed");
            }

            _ercContext.Remove(payment);
        }
コード例 #3
0
        public async Task <IActionResult> Delete(int id)
        {
            var paymentBatch = await _ercContext.PaymentBatches.FirstOrDefaultAsync(x => x.Id == id);

            if (paymentBatch is null)
            {
                return(NotFound());
            }
            else if (paymentBatch.Payments.Any(x => x.Status == PaymentStatus.Processed))
            {
                return(BadRequest("Пачка містить рознесені платежі"));
            }

            _ercContext.Remove(paymentBatch);
            await _ercContext.SaveChangesAsync();

            return(Ok());
        }