Search code examples
c#angularhttp-status-code-500

message: "Http failure response for url 500 OK"


I am getting this error for the post request API call from angular service, after hosting the web API in GoDaddy. But it is working perfectly fine in my local machine. Can anyone please tell me what is goin wrong with my code.

Snapshot of the error The error I am getting.

This is the Angular service

saveforpandl(paymenttdata1) {
  return this.http.post(this._urls.weburl + 'api/AallPandR/PostPaymentpandl/',  paymenttdata1);
}

C# code: This is the API backend method that I am calling from Angular

        [HttpPost]

        public async Task<IHttpActionResult> PostPaymentpandl(PaymentCreditDebitListVM paymentdata1)
        {
            try
            {
                if (paymentdata1.PaymentCreditList != null && paymentdata1.PaymentDebitList != null)
                {
                    for (int j = 0; j < paymentdata1.PaymentCreditList.Count; j++)
                    {
                        var acccode1 = (paymentdata1.PaymentCreditList[j].CreditToAccountId);
                        var acname1 = (paymentdata1.PaymentCreditList[j].CreditToAccountId);

                        var acccode = _db.MinorGroupMasters.Where(c => c.ID.ToString() == acccode1).Select(c => c.MinorGroupCode).FirstOrDefault();
                        var accnmae = _db.MinorGroupMasters.Where(c => c.ID.ToString() == acname1).Select(c => c.MinorGroup).FirstOrDefault();


                        tbl_AllReceiptsAndPayments prev2 = new tbl_AllReceiptsAndPayments()
                        {
                            VoucherType = paymentdata1.PaymentCreditList[j].VoucherType,
                            DebitORCredit = "Credit",
                            TransactionNumber = paymentdata1.PaymentCreditList[j].PaymentNumber,
                            AccountId = acccode,
                            AccountName = accnmae,
                            Amount = paymentdata1.PaymentCreditList[j].CreditAmount,
                            TransDate = Convert.ToDateTime(paymentdata1.PaymentCreditList[j].PaymentDate),
                            ChequeNumber = paymentdata1.ChequeNumber,
                            DDNumber = paymentdata1.DDNumber,
                            Narration = paymentdata1.Narration,
                            BranchId = 1,
                            CreatedOn = DateTime.Now,
                        };
                        await Task.Run(() => _db.tbl_AllReceiptsAndPayments.Add(prev2));
                        await _db.SaveChangesAsync();

                    }


                    for (int j = 0; j < paymentdata1.PaymentDebitList.Count; j++)
                    {
                        var acccode1 = (paymentdata1.PaymentDebitList[j].DebitByAccountId);
                        var acname1 = (paymentdata1.PaymentDebitList[j].DebitByAccountId);

                        var acccode = _db.MinorGroupMasters.Where(c => c.ID.ToString() == acccode1).Select(c => c.MinorGroupCode).FirstOrDefault();
                        var accnmae = _db.MinorGroupMasters.Where(c => c.ID.ToString() == acname1).Select(c => c.MinorGroup).FirstOrDefault();

                        tbl_AllReceiptsAndPayments prev1 = new tbl_AllReceiptsAndPayments()
                        {
                            VoucherType = paymentdata1.PaymentDebitList[j].VoucherType,
                            DebitORCredit = "Debit",
                            TransactionNumber = paymentdata1.PaymentDebitList[j].PaymentNumber,
                            AccountId = acccode,
                            AccountName = accnmae,
                            Amount = paymentdata1.PaymentDebitList[j].DebitAmount,
                            TransDate = Convert.ToDateTime(paymentdata1.PaymentDebitList[j].PaymentDate),
                            ChequeNumber = paymentdata1.ChequeNumber,
                            DDNumber = paymentdata1.DDNumber,
                            Narration = paymentdata1.Narration,
                            BranchId = 1,
                            CreatedOn = DateTime.Now,
                        };
                        await Task.Run(() => _db.tbl_AllReceiptsAndPayments.Add(prev1));
                        await _db.SaveChangesAsync();

                    }
                }
                return Ok(1);

            }
            catch (Exception e)
            {

                throw e;
            }

        }


Solution

  • the error is in convertion of date time

    Date = Convert.ToDateTime(receiptdata1.CreditList[j].ReceiptDate)
    

    and it should be

    DateTime Date = DateTime.Parse(receiptdata.CreditList[j].ReceiptDate,
    CultureInfo.CreateSpecificCulture(&quot;en-IN&quot;));
    

    this may work