What am I doing wrong with my C# CASE SWITCH Code Logic

abiodunajai 396 Reputation points
2023-04-20T15:48:36.6333333+00:00

Please what am I doing wrong with my C# Code below: I'm working on a multi-currency App that need to make decision to Identify the Currency that the client selected and based on that process the invoice by checking if the client Receipt Value is greater than the Invoice amount. If yes, the App should check the Account Balance for the client and add the ShortFallBalance to the AmountPaid to settle the Invoice. If the Clients overpaid, the App should credit the client's account with the ExcessBalance for future use. I don't know What is happening. When I run the code on the development Machine, it works very well on the local Server, but when I uploaded into Production, for Users to use, most of the data submitted as shown below are NULLS. However, when I run it on my Machine, it does exactly what is expected. At first I thought because I used Convert.ToInt64() to test for the GrossAmount, I changed it to Decimal.ToInt64(), yet the same problem persist. I have tried all I could but to no avail. Is it a hardware Issue ? All the User systems Runs Window 10/11 64 bit, Except view ones that are 32 bit. Does that have any effect on this issue? My Model is stated below:

    public class Account_ClientReceipt
    {
        public decimal? GrossAmount { get; set; }
        public string DigitalCode { get; set; }
        public decimal? ShortfallBalance { get; set; }
        public decimal? ExcessBalance { get; set; }
        public decimal? TotalAmountPaid { get; set; }
        public decimal? StaffDiscount { get; set; }
        public string TransTypeCode { get; set; }
        public string ReceivableCode { get; set; }
    }

    public class ReceiptNoteDTO
    {
        public Account_ClientReceipt Account_ClientReceipt { get; set; }
        public decimal TotalPremium { get; set; }
        public decimal? TotalDebitPremium { get; set; }
        public decimal? AmountNowPaid { get; set; }
        public decimal? AccountBalanceBroughtForward { get; set; }
        public decimal? PolicyBalance { get; set; }
     }


    public class AccountBalanceDTO
    {
        public string DigitalCode { get; set; }
        public string ClientCode { get; set; }
        public decimal? AccountBalance { get; set; }
    }

    public class Client
    {
        public decimal? AccountBalance { get; set; }
        public decimal? StaffDiscount { get; set; }
    }

Codes

var currency="566"
      
      var receiptResult = SetupReceipt(receiptNote, clientBalance, client, currency);


       internal static Account_ClientReceipt SetupReceipt(ReceiptNoteDTO receiptNote, AccountBalanceDTO clientBalance, Client client, string currency)
       {

	   switch (currency)
            {
                case Constants.CurrencyCodes.Naira:
                    if (clientBalance == null)
                    {
                        client.AccountBalance = 0m;
                    }
                    else
                    {
                        client.AccountBalance = clientBalance.AccountBalance;
                    }

                    if (receiptNote.Account_ClientReceipt.GrossAmount.HasValue && Decimal.ToInt64(receiptNote.Account_ClientReceipt.GrossAmount.Value) <= Decimal.ToInt64(receiptNote.TotalDebitPremium.Value))
                    {
                        receiptNote.Account_ClientReceipt.ShortfallBalance = receiptNote.TotalDebitPremium.Value - receiptNote.Account_ClientReceipt.GrossAmount.Value;

                        if (Decimal.ToInt64(receiptNote.Account_ClientReceipt.ShortfallBalance.Value) <= Decimal.ToInt64(client.AccountBalance.Value))
                        {
                            receiptNote.AccountBalanceBroughtForward = client.AccountBalance;
                            receiptNote.Account_ClientReceipt.TotalAmountPaid = receiptNote.Account_ClientReceipt.ShortfallBalance.Value + receiptNote.Account_ClientReceipt.GrossAmount.Value;
                            receiptNote.Account_ClientReceipt.ExcessBalance = 0.00m;
                            receiptNote.Account_ClientReceipt.StaffDiscount = 0.00m;
                        }
                        else
                        {
                            receiptNote.AccountBalanceBroughtForward = client.AccountBalance;
                            receiptNote.Account_ClientReceipt.ExcessBalance = 0.00m;
                            receiptNote.Account_ClientReceipt.TotalAmountPaid = receiptNote.Account_ClientReceipt.GrossAmount.Value;
                            receiptNote.Account_ClientReceipt.StaffDiscount = 0.00m;
                        }
                    }

                    else  
                    {
                        receiptNote.Account_ClientReceipt.ExcessBalance = receiptNote.Account_ClientReceipt.GrossAmount.Value - receiptNote.TotalDebitPremium.Value;
                        receiptNote.Account_ClientReceipt.TotalAmountPaid = receiptNote.Account_ClientReceipt.GrossAmount;
                        receiptNote.Account_ClientReceipt.ShortfallBalance = 0.00m;
                        receiptNote.Account_ClientReceipt.StaffDiscount = 0.00m;
                    }
                    break;


		//Other currencies code Section.

            
            }
                
            return receipt;
    }

OutPut receiptNullFields

Developer technologies | ASP.NET | ASP.NET API
Developer technologies | ASP.NET | Other
Developer technologies | C#
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2023-04-24T15:10:17.7933333+00:00

    That sure why the convert to int64, but it’s not the issues. I would guess, that in production, this code path is hit for the null values.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.