Ejemplo n.º 1
0
        public async Task <ApiResponseDto <bool> > UpdateTransactionPaymentStatus(long userId, long transactionId, bool isAdmin)
        {
            var transaction = await _transRepo.FindTransactionById(transactionId);

            if (transaction == null)
            {
                return(new ApiResponseDto <bool>(404, "Record not found", "Error updating record", false));
            }

            if (transaction.Buyer.Id != userId || !isAdmin)
            {
                return(new ApiResponseDto <bool>(403, "User not authorized to carry out this operation", "Error updating record", false));
            }

            transaction.HasPaid = true;
            _transRepo.UpdateTransaction(transaction);
            var isUpdated = await _transRepo.SaveChanges();

            if (!isUpdated)
            {
                return(new ApiResponseDto <bool>(500, "An error occured while updating transaction",
                                                 "Error updating transaction", false));
            }

            await _mailingServices.sendNotificationOfPayment(transaction);

            return(new ApiResponseDto <bool>(200, "Transaction successfully updated", null, true));
        }